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.
Swipe sideways to see the whole figure.
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:
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.
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.
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.
Rebuild OK: all 5 features built
Feature tree
- ✓1. Sketch: L-profile 70 × 44 mm, t = 6 mm
- ✓2. Extrude: 40 mm wide
- ✓3. Fillet: R6 inside bend
- ✓4. Hole: Ø8.5 through the base
- ✓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.
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.
- Write the build123d script, with the dimensions as named values or clear numbers.
- Before you run it, predict the number of faces, edges and vertices and the volume in mm³.
- Export STEP, import it again and confirm the volume survives the round trip.
- 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
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 volumeCounts. 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?
screenName three CAD kernels and a product built on each.
screenWhat is a feature tree, and why does the order of features matter?
screenWhat do STEP, STL and 3MF each carry, and when do you use each?
deepExplain the topological naming problem and how you would design around it.
deepWhy is code-CAD a good target for an LLM, and what are its limits?
Quiz
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.
- 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.
- Book
Martti Mäntylä (1988). An Introduction to Solid Modeling. Computer Science Press.
Read: B-rep and the Euler operators.
- 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.
- 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.
- Documentationfree online
Open Cascade SAS (2025). Open CASCADE Technology Documentation. dev.opencascade.org.
Read: The modelling-data and algorithms overview.
- Documentationfree online
build123d contributors (2025). build123d Documentation. build123d.readthedocs.io.
Read: The tutorial, then the API reference.