Skip to content

A BIM engine in Rust, and where I stopped

Five months writing a native wall-and-slab modeller, and the day I deleted three thousand lines of IFC parser and handed the geometry to IfcOpenShell.

geometry · IfcOpenShellborrowed: the part with the long tailmodelhecs entities · indexed, shared verticestools · undoone lifecycle for the wall and door toolsrenderer · wgpuone mesh, a thousand instance transforms−2,963 lines · +361IfcConvert → glTF, instancing keptwritten in Rust: model, tools, renderer · v0.3.0FIG. 1 · WRITE THE MODEL, BORROW THE PARSERdrawn for this post
the engine, exploded · drawn for this postfig. 1

Last December I started writing a BIM authoring tool from scratch. Rust, a GPU renderer, an entity-component model, walls and doors and slabs you could draw. The pitch to myself was simple: Revit does most of its work on one thread and browser-based viewers run out of memory, so a native engine on modern hardware should feel different.

It did feel different. It also taught me, expensively, where the line sits between the part of a BIM engine worth writing yourself and the part you should borrow. This is the story of finding that line.

What it was

A single binary. wgpu for rendering, winit for the window, egui for panels, hecs as the entity store. A command pattern with undo and redo. A tool trait, so a wall tool and a door tool share one lifecycle. A small CSG kernel for cutting openings. IFC import and export, because without IFC it is a toy.

The first day set the tone. I had started with a web prototype as well, using web-ifc in WebAssembly inside a Tauri shell. By the evening I had deleted it, 7,295 lines, and kept only the native core. Two codebases for one idea was one too many.

Two frames from a screen recording of a dark 3D viewport: a single wall segment on the left, three walls joined at corners with the Wall tool active on the right.
The wall tool on day one, from the first screen recording. Snapping worked before anything else did.

The geometry bug that wrote an architecture decision

Early on, a plain cube clipped against itself. Some faces vanished from some angles. The cube had eight shared vertices, each with a placeholder normal, and the faces did not agree on winding order. Back-face culling did the rest.

The fix was not a patch. It was a decision I wrote down as the project’s first architecture record: the core keeps indexed geometry, with shared vertices, because that is what IFC and STEP topology look like and what the CSG kernel needs. The renderer gets a converted copy, flat-shaded, with vertices duplicated per face, because that is what looks right on screen. Two representations, one conversion step, no arguing.

Up is a matter of opinion

IFC is Z-up. The renderer was Y-up. I got the transform wrong twice on the same day, in two different places, and each time the model looked plausible enough to not notice immediately. The second time, selection broke rather than rendering: the spatial index was storing bounding boxes in local space while the picking ray was in world space, and nothing matched until the box corners were transformed before insertion.

The sphere test was the opposite kind of bug. A unit-test failure said the sphere mesh had 672 indices instead of the expected 768. I spent a while looking for the missing triangles before counting the middle stacks by hand. There were six. The test had assumed seven. The sphere was fine; the arithmetic in the test was not.

Then I tried to parse IFC myself

In February I wrote an IFC parser in Rust. STEP syntax is not hard. The entities are not hard. The geometry is hard. IFC describes solids parametrically: extrusions along a direction, sweeps along a path, booleans of the results, mapped items that instance one representation many times. Every one of those needs a correct, robust implementation before you see a single building, and the long tail of edge cases in real exported files is very long.

A month later I had about three thousand lines that handled the common cases and fell over on anything interesting. Real models from real exporters are nothing but interesting.

Two rows: in February, IFC went through a hand-written Rust parser into the engine; in March, geometry comes from IfcOpenShell and semantics from Python, and the Rust engine keeps only the model, tools and renderer.
One commit removed 2,963 lines from the IFC module and added 361.

The reversal

In March I stopped. IfcOpenShell already does the geometry, in C++, maintained by people who have spent years on exactly the edge cases I was rediscovering. Its IfcConvert tool emits glTF with instancing preserved, so an IfcMappedItem used a thousand times arrives as one mesh and a thousand transforms, which maps straight onto GPU instance buffers.

So the engine now asks IfcOpenShell for geometry and a small Python script for semantics: the types, the property sets, the spatial tree. Rust keeps the parts I actually wanted to write: the model, the tools, the undo stack, the renderer. The roadmap’s note on the change is one sentence long and I still agree with it: hand-decoding parametrised STEP geometry is deprecated.

A review I did not do myself

Around the same time I ran an AI code audit across the codebase, roughly eight and a half thousand lines over fifty files. It produced a report, which I turned into three short sprints: wire up the commands that were half-connected, remove the unwrap() calls that would panic on bad input, propagate errors properly, and refactor the view manager. Soon after, the one large BimStore was split into scene, selection and view managers. None of it was glamorous. All of it made the next month easier.

Smaller things from the same period: the quaternion identity check on import was simply wrong, and spatial element GUIDs needed to be deterministic on export, or a round trip through IFC changed every identifier.

Where it is

Version 0.3.0 shipped at the end of March. In May I built a demo model with coordination issues to show the viewer side. Then work and other things took over, and the repository has been quiet since.

I do not regret it. I know what an entity-component BIM model feels like to work in. I know why wgpu instancing matters for buildings in a way it does not for most games. And I know, in my hands rather than from a blog post, that the geometry kernel is the last thing to write and the first thing to borrow.