Hardware Academy
AI-Assisted Design

CAD kernels and parametric design

B-rep vs mesh, the kernels behind the tools, and why code-CAD suits AI.

Day 13 · 50 min

After this lesson

  • You can compare mesh, B-rep and CSG representations.
  • You can name the major CAD kernels and the tools built on them.
  • You can write a small parametric part in code and export STEP.

Four ways to describe a solid

A CAD file is not a picture of a part. It is a description that a machine shop can cut metal from, and the kind of description decides which questions you can ask later: how wide is this hole, is this surface flat, which faces meet at this edge? Four representations dominate engineering, and each answers a different set of questions.

Mesh, B-rep, CSG and implicit models

  • Mesh (STL). A bag of triangles. A binary STL is an 80-byte header, a 4-byte triangle count and 50 bytes per triangle, with no units, no colour and no concept of a hole. A 20 mm sphere held within 0.01 mm of true needs about 5,000 triangles, roughly 250 KB. Meshes are right for rendering, 3D printing and machine-learning data, and wrong when you need exact dimensions.
  • B-rep (boundary representation). The solid is described by its skin: faces (patches of planes, cylinders, cones, spheres, tori or NURBS surfaces), edges (lines, circles, B-splines) and vertices (points), plus the topology saying which edge bounds which face. The same sphere is one face with a radius of 10 mm. Mainstream mechanical CAD, and the hand-off to a machine shop, is built on B-rep.
  • CSG (constructive solid geometry). A tree of primitives (box, cylinder, sphere) combined by union, difference and intersection. It is compact and naturally parametric, and OpenSCAD is CSG-first. The tree must still be evaluated into a B-rep or a mesh before anyone can machine or print it.
  • Implicit or SDF models. The solid is where a function f(x, y, z) is negative; union and intersection become max and min, and smooth blends and lattices come almost free. nTop builds lattice and heat-exchanger design on this idea. Implicit models have no named faces, so there is nothing to dimension or tap a thread into, and they leave the system as meshes.

B-rep obeys a counting rule. For a simple closed solid, vertices − edges + faces = 2. Each through-hole cuts extra loops into the faces it pierces, and the general form is V − E + F − R = 2 − 2g, where R counts those extra loops and g is the number of through-holes. The bracket below has 11 faces, 27 edges and 18 vertices in OpenCascade's convention, where a cylinder carries a seam edge: 18 − 27 + 11 − 4 = −2, which is 2 − 2 × 2 holes.

B-rep topology of a bracket: one solid, one shell, 11 faces, 15 wires, 27 edges and 18 vertices, each bound to exact geometryF2 base endF3 base topF4 inside filletF5 flange innerF6 flange topF8 front capF10 base hole wallF11 flange hole wallV2 at (70.0, 0.0, 0.0) mmV3 at (70.0, 0.0, 6.0) mmV4 at (12.0, 0.0, 6.0) mmV5 at (6.0, 0.0, 12.0) mmV6 at (6.0, 0.0, 44.0) mmV7 at (0.0, 0.0, 44.0) mmV8 at (0.0, 40.0, 0.0) mmV9 at (70.0, 40.0, 0.0) mmV10 at (70.0, 40.0, 6.0) mmV11 at (12.0, 40.0, 6.0) mmV12 at (6.0, 40.0, 12.0) mmV13 at (6.0, 40.0, 44.0) mmV14 at (0.0, 40.0, 44.0) mmV15 at (56.0, 23.0, 6.0) mmV17 at (6.0, 23.0, 27.0) mmFace F5a bounded patch of one planeEdge E19a line shared by F4 and F5Vertex V12where E11, E12 and E19 meetTOPOLOGYBOUND GEOMETRYSolid1one closed volumeShell1a closed skin, no gapsFaces11Surface: 8 planes, 3 cylindersWires1511 outlines + 4 hole rimsEdges27Curve: 21 lines, 2 arcs, 4 circlesVertices18Point: x, y, z in mm

Swipe sideways to see the whole figure.

B-rep topology of a bracket: a solid is a shell of faces, each face is bounded by wires of edges, each edge ends at vertices, and every face, edge and vertex is bound to exact geometry.

Kernels: who does the geometry

A kernel is the library that does the hard geometry: boolean cuts, fillets, offsets and surface intersections. Parasolid (Siemens) sits under SolidWorks, NX, Solid Edge and Onshape. ACIS (Spatial, a Dassault company) is the other long-lived commercial kernel, and Autodesk's ShapeManager in Inventor and Fusion began as a fork of it. CATIA uses CGM and Creo uses Granite. OpenCascade (OCCT) is the open-source kernel behind FreeCAD, CadQuery and build123d, and KiCad uses it to import and export STEP. Kernels agree on the ideas and differ in the details: Parasolid resolves 10⁻⁸ m inside a 1 km modelling box, OpenCascade merges points closer than 10⁻⁷ model units, and a boolean that succeeds in one can fail in another.

Feature trees and constraint solvers

Mechanical CAD is history-based. You draw a sketch, and a 2-D constraint solver (D-Cubed in many commercial tools, planegcs in FreeCAD) moves the geometry until every dimension and relation holds. A sketch is fully constrained when it has zero degrees of freedom: a rectangle with horizontal and vertical sides is four numbers (corner x and y, width, height), so pinning the corner and dimensioning both sides leaves nothing free. Features then apply in order: extrude, hole, fillet, pattern. That ordered list is the feature tree, and every edit makes the kernel replay it from the top. Change a dimension and the part regenerates; change the order and you may get a different part, or none.

Exchange formats

STEP (ISO 10303, usually application protocol AP203, AP214 or AP242) carries exact B-rep, assembly structure, colours and units, and is what a shop wants. IGES froze at version 5.3 in 1996 and survives for surfaces and curves. STL dates from 1987 and holds triangles only. 3MF (3MF Consortium, 2015) is zipped XML with units, colours and multiple objects, and is the modern format for printing. Send a shop an STL and every hole becomes a ring of flat facets that nobody can dimension.

Why code-CAD suits AI

Code-CAD writes the feature tree as a program. build123d (Python, on OpenCascade) and CadQuery are the common choices. An 80 × 40 × 6 mm plate with rounded corners and four holes is a dozen lines, and every dimension is a named variable:

plate.pypython
from build123d import *

length, width, thickness = 80, 40, 6      # mm
hole_d, inset, corner_r = 6.5, 10, 4

plate = Box(length, width, thickness)
plate = fillet(plate.edges().filter_by(Axis.Z), radius=corner_r)   # round the 4 corners
for sx in (-1, 1):
    for sy in (-1, 1):                                              # four clearance holes
        x, y = sx * (length / 2 - inset), sy * (width / 2 - inset)
        plate -= Pos(x, y, 0) * Cylinder(hole_d / 2, thickness * 2)

print(round(plate.volume, 1), len(plate.faces()))   # 18321.2 mm3, 14 faces
export_step(plate, "plate.step")

Four properties make this a good target for a language model. Text goes in and geometry comes out, so the model works in its native medium. A diff shows exactly what changed, where a binary CAD file shows nothing. The script runs headless in a sandbox, so a failure returns a traceback the model can read and fix. And the parameters are explicit, so a checker can inspect them. The cost is blindness: the model cannot see the part unless you return measurements, renders or DFM reports, which is what the next two lessons build.

Topological naming

The classic failure of feature trees is the topological naming problem. A fillet stores its target as something like “Edge17”, but edge numbers are not stable: change a hole upstream and the kernel may split, merge or renumber edges, so the fillet attaches to a different edge or fails. FreeCAD showed this to every user until version 1.0 (November 2024) added element tracking to mitigate it, and commercial kernels keep persistent IDs with heuristics. Code-CAD sidesteps most of it by selecting geometry with queries, such as “the vertical edges at the corners”, instead of numbers.

Interactive: explore a B-rep, then break a parametric part

Start with the explorer. Switch faces, edges and vertices on and click them, then remove the holes and the fillet one at a time and watch the counts and the Euler-Poincaré line follow. Then use the parametric bracket: drag a slider and the kernel replays the feature tree. Push the hole and the fillet until something fails, then flip the feature order and see where the error lands.

B-rep explorer: one bracket, three kinds of entity

Switch faces, edges and vertices on and click any of them. With X-ray on, hidden ones are drawn dashed; pick those from the lists. Then remove a feature and watch the counts and the Euler check change.

Isometric L-bracket with 11 faces, 27 edges and 18 verticesF2 base endF3 base topF4 inside filletF5 flange innerF6 flange topF8 front capF10 base hole wallF11 flange hole wallF2F3F4F5F6F8F10F11

From this angle you can see 8 of 11 faces, 20 of 27 edges and 15 of 18 vertices. The kernel stores all of them.

Click a highlighted face, edge or vertex, or pick one from the lists below, to see its exact geometry and what it touches.

Faces
Euler-Poincaré check: V − E + F − R = 18 − 27 + 11 − 4 = -2, and 2 − 2g with g = 2 through-holes is -2. Each hole you remove adds 2 back.

Parametric bracket: change a number, regenerate the part

Drag the sliders and the kernel replays the feature tree. Switch the feature order and enlarge the hole to see why order is part of the design.

Isometric bracket, base length 70 mm, hole diameter 8.5 mm, fillet radius 6 mmF2 base endF3 base topF4 inside filletF5 flange innerF6 flange topF8 front capF10 base hole wallF11 flange hole wallL = 70 mmØ8.5Ø8.5R6

Rebuild OK: all 5 features built

Feature tree

  1. ✓1. Sketch: L-profile 70 × 44 mm, t = 6 mm
  2. ✓2. Extrude: 40 mm wide
  3. ✓3. Fillet: R6 inside bend
  4. ✓4. Hole: Ø8.5 through the base
  5. ✓5. Hole: Ø8.5 through the flange

DFM checks

  • ✓Minimum wall: 6 mmrule: at least 1.5 mm
  • ✓Hole to edge: 12.8 mmrule: at least 1 × hole diameter (8.5 mm)
  • ✓Fillet feasibility: R6rule: inside radius of at least 0.5 mm

Volume 25,548 mm³, about 69.0 g in 6061 aluminium.

Feature order
Reproduce sets holes first, a Ø12 hole and an R12 fillet. Then flip the order to Fillet first and compare where the error lands.

In practice: a motor mount in code

Practice

Write, predict and check a NEMA 17 mount in build123d

Build a mounting plate for a NEMA 17 stepper motor: 50 × 50 mm and 6 mm thick, a 22.5 mm centre bore for the motor's pilot boss, four Ø3.4 mm clearance holes for M3 screws on a 31 mm square pattern, and R4 on the four corners.

  1. Write the build123d script, with the dimensions as named values or clear numbers.
  2. Before you run it, predict the number of faces, edges and vertices and the volume in mm³.
  3. Export STEP, import it again and confirm the volume survives the round trip.
  4. Check the design against two rules we use later: hole rim at least one diameter from the edge for fastener holes, and every wall at least 1.5 mm.
Answer
nema17_mount.pypython
from build123d import *

plate = Box(50, 50, 6)
plate = fillet(plate.edges().filter_by(Axis.Z), radius=4)    # R4 corners first
plate -= Cylinder(22.5 / 2, 12)                              # pilot bore
for x in (-15.5, 15.5):
    for y in (-15.5, 15.5):
        plate -= Pos(x, y, 0) * Cylinder(3.4 / 2, 12)        # M3 clearance holes

print(len(plate.faces()), len(plate.edges()), len(plate.vertices()), round(plate.volume))
export_step(plate, "nema17_mount.step")
print(round(import_step("nema17_mount.step").volume))      # round trip: same volume

Counts. The box has 6 faces. Filleting the four vertical edges adds 4 cylindrical faces, and five holes (four screws plus the bore) add 5 more: 15 faces. The filleted outline has 8 edges on top, 8 on the bottom and 8 vertical tangent lines, 24 in all, and each hole adds a top circle, a bottom circle and a seam: 24 + 15 = 39 edges. Vertices: 16 on the outline plus 2 per hole for the seam ends, 16 + 10 = 26. Euler-Poincaré agrees: 26 − 39 + 15 − 10 hole rings = −8, which is 2 − 2 × 5.

Volume. 15,000 − 82.4 (four R4 corners) − 2,385.7 (bore) − 217.9 (four holes) = 12,314.0 mm³. The re-imported STEP should print the same rounded value, because STEP stores the exact surfaces.

Rules. The M3 holes sit 9.5 mm from the plate edge, so the rim is 7.8 mm away against 3.4 mm required. The bore is a cut-out, not a fastener hole, so only the 1.5 mm wall applies: it leaves 13.75 mm to the plate edge and 8.97 mm to the nearest M3 hole. Fillet first and drill last is the habit to keep: if a hole later grows too big, the error lands on the hole you just edited and says why, instead of on an unrelated fillet.

Real-world scenario

Real-world scenario

The fillet fails after someone enlarges a hole

A team keeps a parametric aluminium L-bracket in a feature-tree CAD system. The tree reads: Sketch (70 × 44 mm L-profile, 6 mm thick), Extrude 40 mm, Hole 8.5 mm through the base, Hole 8.5 mm through the flange, then Fillet R12 on the inside bend, whose edge was picked by clicking it in the viewport. Procurement swaps the M8 anchor for an M10, so a junior engineer changes one number on the flange hole: 8.5 mm becomes 12 mm. The model turns red and the drawing package for the supplier cannot be released.

Symptoms

  • Rebuild stops at the Fillet feature with BRep_API: command not done, and everything after it is suppressed
  • Setting the hole back to 8.5 mm makes the error disappear, so the hole edit looks innocent
  • Opening the same file in an older release attaches the fillet to a different edge, and a rounded edge appears that nobody designed

Interview questions

screenWhat is the difference between a mesh and a B-rep?
A mesh approximates a surface with triangles, so a cylinder is a ring of flat facets and nothing in the file says it was ever a cylinder. A B-rep stores faces, edges and vertices with exact surfaces and curves, plus the topology of which entities touch, so the same cylinder is one face with a radius. That is why a machine shop wants STEP, which carries a B-rep, rather than STL, which carries a mesh. Meshes are still the right choice for rendering, 3D printing and machine-learning datasets because they are simple and robust.
screenName three CAD kernels and a product built on each.
Parasolid from Siemens sits under SolidWorks, NX, Solid Edge and Onshape. ACIS from Spatial is licensed to many vendors, and Autodesk's ShapeManager in Inventor and Fusion started as a fork of it. OpenCascade is the open-source kernel behind FreeCAD, CadQuery and build123d, and KiCad uses it for STEP import and export. CATIA has its own CGM kernel and Creo has Granite. The kernel matters because boolean and fillet robustness differ between them, so a model can rebuild in one tool and fail in another.
screenWhat is a feature tree, and why does the order of features matter?
A feature tree is the ordered recipe of a history-based CAD model: sketch, extrude, hole, fillet, pattern. On every edit the kernel replays the recipe from the top, and each feature takes the previous result as its input. Order matters because later features reference geometry that earlier ones create. A fillet placed after a hole has to roll around that hole, so enlarging the hole can break it, while the same fillet built first never sees the hole. As a rule I build large global features first, add holes and small details last, and select geometry by rule instead of by name.
screenWhat do STEP, STL and 3MF each carry, and when do you use each?
STEP carries exact B-rep geometry with units, assembly structure and optionally colours or GD&T, so it is the hand-off to a machine shop or another CAD tool. STL carries only triangles with no units or colour, which is fine for a slicer but loses every dimension. 3MF is a zipped XML package that holds a mesh with units, colours, materials and multiple objects, so it is the modern choice for 3D printing. I choose by who consumes the file: a machinist gets STEP, a printer gets 3MF or STL, and a renderer gets glTF or OBJ.
deepExplain the topological naming problem and how you would design around it.
Features in a history-based model refer to faces and edges by identifiers the kernel generates, such as Edge17. After an upstream edit the kernel may split, merge or renumber entities, so a downstream fillet can attach to a different edge or fail outright. Commercial systems keep persistent IDs with heuristics, and FreeCAD added element tracking in version 1.0 to mitigate it. In design terms I reduce exposure by referencing sketch geometry or datum planes instead of picked faces, by ordering features so fragile references come late, and in code-CAD by selecting with queries such as edges parallel to Z at the corners. I also add a check that fails loudly when a selection returns zero or an unexpected number of entities.
deepWhy is code-CAD a good target for an LLM, and what are its limits?
Code-CAD turns geometry into text, which is the medium a language model is best at: the model writes build123d or CadQuery, the script runs headless, and any error comes back as a traceback it can read and fix. The result is diffable, so a review shows that a hole changed from 6.5 to 8.5 mm instead of showing a binary file that changed. Parameters are explicit, so a checker can inspect them and a tool can reject values outside the shop's limits. The limits are spatial and physical: the model cannot see the part unless you give it renders or measurements, it mixes up axes and mirrored features, and it knows nothing about tolerances or the shop's tooling unless a check encodes them. So I pair code-CAD with measurement tools and DFM checks rather than trusting the script.

Quiz

1. A binary STL file describes a 20 mm sphere. What does the file actually contain?
2. You drill one through-hole in a box (8 vertices, 12 edges, 6 faces). With OpenCascade conventions, the new counts are:
3. Which kernel is open source and sits under FreeCAD, CadQuery and build123d?
4. A parametric model fails at its fillet right after you enlarge a hole. What is the most likely cause?
5. What is the topological naming problem?
6. Which property makes code-CAD attractive for AI-assisted design?
7. Your STEP file has no tolerance note and the shop works to ISO 2768-m. Roughly what will they hold on a 40 mm dimension?

References and further reading

Where the ideas in this lesson come from, and what to read next. Books are the standard texts; papers are the original sources; standards are what employers work to.

  1. Paper

    Aristides A. G. Requicha (1980). Representations for Rigid Solids: Theory, Methods, and Systems. ACM Computing Surveys 12(4), 437-464.doi:10.1145/356827.356833

    Read: The survey of solid representations.

  2. Book

    Martti Mäntylä (1988). An Introduction to Solid Modeling. Computer Science Press.

    Read: B-rep and the Euler operators.

  3. Book

    Jami J. Shah and Martti Mäntylä (1995). Parametric and Feature-Based CAD/CAM: Concepts, Techniques, and Applications. Wiley.

    Read: Feature trees and parametric history.

  4. Paper

    Jiri Kripac (1997). A Mechanism for Persistently Naming Topological Entities in History-Based Parametric Solid Models. Computer-Aided Design 29(2), 113-122.doi:10.1016/S0010-4485(96)00040-1

    Read: The topological naming problem.

  5. Documentationfree online

    Open Cascade SAS (2025). Open CASCADE Technology Documentation. dev.opencascade.org.

    Read: The modelling-data and algorithms overview.

  6. Documentationfree online

    build123d contributors (2025). build123d Documentation. build123d.readthedocs.io.

    Read: The tutorial, then the API reference.