FeatureBoardby Lewis Valentine

What a CAD Kernel Is Actually Made Of

Most engineers have used CAD. Far fewer have looked inside one. A solid modeling kernel is a handful of layers in a specific order, and almost every hard problem in CAD comes from one rule about which layer is allowed to be the truth.

Most engineers have used CAD. Far fewer have looked inside one, and the inside is less mysterious than its reputation suggests. A solid modeling kernel is a handful of layers stacked in a specific order, and almost every hard problem in CAD comes from one rule about which layer is allowed to be the truth.

NativeCAD is a kernel written from scratch in JavaScript. No wrapping of an existing engine, which means every layer below had to be built rather than configured. This is a tour of those layers, in the order the data moves through them.

The one idea everything else follows from

A mesh tells you where a surface is. A boundary representation tells you what the surface is.

Take a cylinder. In a mesh it's 64 quads approximating a tube, and if you want to know its radius you have to infer it back out of the vertex positions. In a B-rep it's a cylindrical surface with an axis, a radius and a placement, trimmed by two circular edges. The radius isn't inferred. It's stored, exactly, as the number someone typed.

That difference decides what the software can do. You can fillet a B-rep edge because there is an edge, with two faces meeting along it at a knowable angle. You can measure a hole because the hole is a cylindrical face and its diameter is a property rather than a statistic. You can export to a machine tool because the tool wants surfaces, not triangles.

The rule the rest of the article is about

The B-rep is the model. Everything else, including every triangle you have ever seen on screen, is a view derived from it. The moment triangles become the source of truth, you have built a mesh editor with a CAD-shaped interface.

Layer 1: the entity graph

The bottom layer is storage, and here NativeCAD makes a choice worth explaining. STEP (ISO 10303) is usually treated as an interchange format: you import it, convert it into your own internal structures, and convert back on the way out. NativeCAD treats it as the native representation. The parser reads the file into a map of entities and keeps them.

A STEP file is a flat list of numbered records that reference each other by id:

#42 = CARTESIAN_POINT('',(0.,0.,0.));
#43 = DIRECTION('',(0.,0.,1.));
#44 = DIRECTION('',(1.,0.,0.));
#45 = AXIS2_PLACEMENT_3D('',#42,#43,#44);
#46 = CYLINDRICAL_SURFACE('',#45,25.0);

That is a graph. Cylindrical surface 46 is placed by 45, which is anchored at point 42 and oriented by directions 43 and 44. The parser holds the references unresolved, as the literal strings, and walks them on demand. Adjacency queries stay cheap, and every entity keeps the id it had in the file.

Keeping ids is what makes round-tripping honest. Import a file, change one face, write it back, and every entity you didn't touch is re-emitted as it arrived rather than regenerated from a lossy internal copy.

Layer 2: topology, and what "watertight" means

Raw entities are a soup. The topology layer puts typed wrappers over them so the code can talk about solids and faces instead of record numbers. The B-rep chain runs top down like this:

MANIFOLD_SOLID_BREP  → a solid
  CLOSED_SHELL       → its surface, as a set of faces
    ADVANCED_FACE    → one face: a surface plus the loops that trim it
      FACE_OUTER_BOUND / FACE_BOUND
        EDGE_LOOP    → an ordered ring of oriented edges
          ORIENTED_EDGE
            EDGE_CURVE   → two vertices and the curve between them
              VERTEX_POINT

A face is a surface and its trimming loops, which is why a face can be a rectangle cut out of an infinite plane, with a circular hole in it, described by an outer bound and an inner one.

The relationships that matter most run sideways rather than down: edge to faces, vertex to edges, face to neighbouring faces. Those are what an operation needs. A fillet has to know which two faces share the edge you clicked.

They are also where watertightness is defined. A closed manifold shell has every edge shared by exactly two faces. One face means a hole in the surface. Three means a non-manifold junction where the solid pinches into something that could not exist as a physical object.

Where the textbook stops being useful

The classic validity check is Euler's formula: for a simple closed polyhedron, V − E + F = 2. It's elegant and it is not usable on real files.

Conformance parts from NIST give geometrically coincident corners distinct vertex ids. Two faces meeting at what a human sees as one corner can reference two different VERTEX_POINT records holding identical coordinates. That inflates V, and the Euler number comes out meaningless while the solid is perfectly valid.

So the invariant that actually gets enforced is the edge-sharing one, which survives contact with real data. This is a recurring shape in kernel work: the textbook result is true, and true about a cleaner object than the one in your hands.

Layer 3: operations

Above topology sit the modeling operations, which in NativeCAD is 36 modules covering extrude, revolve, loft, sweep, booleans, shell, holes, patterns, chamfers, blends, ribs, sheet metal and the rest.

The thing to understand about all of them is what they edit. An extrude does not produce triangles. It creates new faces, edges and vertices as entities in the graph, wires up their loops, and hands back a solid whose surfaces are exact. A boolean re-trims existing faces and stitches the survivors into a new closed shell. A fillet inserts a rolling-ball surface and makes each junction curve a single shared edge entity between the new surface and the old face.

That last detail is small and load-bearing. If the blend created its own boundary curve and the neighbouring face kept a separate copy at the same coordinates, the two would agree to within floating-point noise and the shell would have a seam. Sharing one edge entity means there is nothing to disagree about, and the result is watertight by construction rather than by a repair pass afterwards.

Layer 4: tessellation, which is a view

Screens draw triangles, so at some point the exact surfaces have to become approximate ones. The tessellator walks each face, samples its surface across the region its loops enclose, triangulates that region, and welds the results into one mesh.

Two properties are worth naming. It is derived, so it can be thrown away and rebuilt from the B-rep at any time, at any resolution. And it is lossy on purpose: a cylinder becomes flat strips, and how many is a quality setting rather than a fact about the model.

Everything downstream of tessellation inherits that. Mass properties are computed from the mesh, so a tessellation too coarse to close gives you a volume that is wrong in a way the B-rep is not. Keeping this layer honest is most of what makes the difference between a viewer and a kernel.

Layer 5: history, which is what "parametric" means

A kernel that only edits geometry in place gives you a solid and no way to revise it. The feature history is a log of the operations that built the model, stored as data: extrude this profile 20mm, fillet these edges at 3mm, drill this hole.

Change the 20 to 25 and the model rebuilds by replaying the log. That replay is the entire content of the word "parametric", and it's why operations have to reference things by stable identity rather than by position. If your fillet says "the edge at these coordinates", it breaks the moment an earlier feature moves it.

The layer nobody warns you about

Between exact mathematics and real files sits tolerance, and it is where kernel engineering stops resembling ordinary programming.

Two faces are coincident when they are within some distance of each other. Pick that distance too small and imported files fall apart at every seam. Too large and genuinely distinct features get welded into each other. There is no value that is correct everywhere, because the right answer depends on the size of the feature being tested.

The approach NativeCAD follows, taken from how the established commercial kernels handle it, is to attach precision to individual edges and vertices rather than running one global epsilon for the whole model. An entity with no precision set is exact. An entity that needs slack carries its own, locally, and every algorithm consults it rather than assuming exactness.

The alternative, retrofitting tolerance later as a special case, produces a long tail of bugs where some code path forgot to branch on it. That history is visible in the public documentation of more than one shipping kernel.

What it costs

Concretely, for the kernel and its ops, commands and sketch layers:

51,887
Lines of kernel
69,880
Lines of tests
36
Operation modules

The ratio is the honest headline. There is more test code than kernel code, for a specific reason: geometry fails quietly. A boolean that is wrong by 0.4% produces a solid that looks completely normal on screen, exports without complaint, and is wrong. There is no stack trace and nothing red. The only thing standing between that and a shipped defect is a test that knew the right volume beforehand.

In most software the bug announces itself. In geometry it renders beautifully and waits.

That is also the argument for writing the core rather than wrapping one. When the boolean is someone else's binary, a 0.4% volume error is a support ticket into a black box. When it's yours, it's a Tuesday.


NativeCAD runs entirely in the browser: STEP AP242 in and out, exact B-rep modeling, no server round-trip. You can open it and build something, or book a call if you have a geometry problem worth talking through.

← Previous Post
Watertight Is a Claim You Have to Keep