github.com/lestrrat-3d

A Go toolchain for CAD,
from typed units up to rendered pixels.

Six libraries that stack into a headless CAD pipeline, plus the tools built on top of it. Models start in code, with no required CAD GUI or project file and no hidden ambient units.

All repositories The stack

How the hero was made

A WebGL2 shader uses distance formulas to draw a cube, chamfer and round its edges, turn it into a sphere, open a hole, and finish as a torus. Twelve copies start at different points in the sequence, turn in alternating directions, and drift across three rows.

Playwright captures each frame; ffmpeg makes the WebM and MP4 videos and a still poster for visitors who request reduced motion. The animation illustrates shape changes; the library images below show actual tool output. View the shader and build steps.

Why build CAD from code?

Before coding agents, a designer made a parametric part in a CAD app by drawing dimensioned sketches and adding extrusions and cuts. The app rebuilt the part when a dimension changed. That workflow still works.

Agents can make convincing 3D shapes for a one-off render or print. A bevel gear can look right yet fail to mesh at the requested dimensions, and another prompt may produce different geometry. An agent can also write an add-in that reruns fixed modeling steps. It still has to run the add-in in the CAD app to inspect the resulting body.

With sketch and decad, the agent writes dimensioned sketches and ordered features in Go, builds 3D bodies, and checks their measurements and fit as it revises the code. The same code and inputs rebuild the same model. The agent uses those steps in a CAD app to build an editable, parametric part, then checks the app's result.

decad writes a body as STL or OBJ when a mesh file is needed. solidlens renders its mesh directly to a PNG for visual inspection. To show an assembly moving or a part changing shape, kinetograph animates decad bodies and uses solidlens to render numbered PNG frames.

Agentic CAD: build a model you can rerun
CAD goal

Agent development loop

AI agent Write sketches and features
sketch + decad Build a 3D body
Check the result Do the steps meet the CAD goal?
✓ Sketch solved ✓ 3D body verified ? solidlens render matches the goal?
Change a dimension or feature. Rerun.
Passes
Keep the code; use the model and its steps CAD appSTL / OBJsolidlens PNGkinetograph frames

The stack

Each layer depends only on the ones beneath it, and never the other way around. Any layer is usable on its own.

  1. kinetograph Animates bodies, cameras, and lights
  2. solidlens Renders a mesh to pixels
  3. decad 3D bodies, features, verification
  4. sketch Parametric 2D constraint solving
  5. r3 Vectors, frames, rigid transforms
  6. units Typed quantities and their kinds

Libraries

units

Units of measure for Go.

A Value is a magnitude paired with the unit it is expressed in. A Kind is a vector of exponents over length, mass, angle, time and temperature, so kinds compose: multiply two lengths and you get an area, divide mass by volume and you get a density. Asking for a length in degrees returns an error rather than a silent reinterpretation, which is how the classic CAD-API trap — 2 quietly meaning 2 radians — stops happening.

w := units.Millimeters(100)
in, err := w.In(units.Inch)       // 3.937...
_, err = w.Convert(units.Degree)  // error: a length is not an angle

Gostandard library only

r3

Coordinate math for Euclidean 3-space.

A Vec vector type, an orthonormal right-handed Frame that carries the transform between a plane's local (u, v, w) coordinates and world (x, y, z), and a Transform for rigid motion of the space itself. Angles are typed, so no bare radians cross an API boundary. Points translate and directions do not.

spin, err := r3.RotationAround(
    r3.NewVec(10, 0, 0), r3.NewVec(0, 0, 1), units.Degrees(30),
)
p := spin.Apply(pt)      // a POINT: rotated, then moved
n := spin.ApplyDir(nrm)  // a DIRECTION: rotated only

Godepends on units

The word 'sketch' in outlined letters over a CAD grid and frame, above the tagline 'A headless parametric 2D sketch engine'

sketch

A headless parametric 2D sketch engine, in the spirit of Fusion's sketch environment.

You build points, lines, circles, arcs, ellipses and splines in code, tie them together with geometric and dimensional constraints, and a Levenberg–Marquardt solver moves the geometry until every constraint holds at once. Dimensions are ordinary editable values, so changing one and re-solving updates the sketch.

  • A Fusion-like constraint set: coincidence, tangency, parallel, perpendicular, symmetry, equality and more.
  • Degrees-of-freedom and redundancy analysis, conflict detection, and a multi-solution ambiguity probe.
  • Trim, extend, break, fillet, chamfer, mirror, pattern and offset on committed geometry, including arcs and circles and offset chains of lines and arcs.
  • Closed-region profile detection with exact areas and hole nesting.
  • Export to SVG and PNG — optionally annotated with dimensions and constraint glyphs — plus DXF R12 and lossless JSON.
w := sketch.NewWorld()
s, err := w.CreateSketch(w.XY())

a, b, d := s.CreatePoint(0, 0), s.CreatePoint(18, 2), s.CreatePoint(1, 13)
ab, ad := s.CreateLine(a, b), s.CreateLine(a, d)
s.Fix(a)                                    // ground one corner
s.AddConstraint(sketch.NewHorizontal(ab), sketch.NewVertical(ad))

width := sketch.NewDistance(a, b, 20)       // a driving dimension
s.AddConstraint(width)

res, err := s.Solve(ctx)                    // res.DOF == 0: fully constrained
width.Set(35)                               // re-solve and the geometry follows

Godepends on r3, units

DECAD letters assemble on a navy plate, a light sweeps across them, and the letters lift away

decad work in progress

Deconstructed CAD: a headless CAD engine for Go.

decad builds 3D bodies in Go from dimensioned profiles solved by sketch and ordered modeling features. An agent can measure volume and centroid, tessellate the bodies, change a dimension or feature, and run the construction again. The same code and inputs rebuild the same model.

Its verification report can check body validity, interference, and requested clearance or wall-thickness limits. After the model passes the requested checks, the agent can translate those operations into a CAD add-in that builds an editable, parametric part. The agent checks the CAD app's result too.

The public API is landing incrementally against an approved design, so what the package exports today is the leading edge of a larger contract.

  • Build solids: extrude, revolve, sweep and loft solved profiles, including profiles with exact spline walls.
  • Refine bodies: round selected edges with fillets, cut chamfers into edges or whole cap loops, and shell solids to a uniform wall thickness.
  • Combine geometry: union, cut and intersect bodies with explicit Boolean operations.
  • Work with surfaces: keep a feature's swept walls without its closing faces to produce an open sheet body.
  • Prove the result: inspect topology and physical quantities, then check interference and clearance between bodies.
  • Check moving parts: drive bodies along a revolute, prismatic or linked joint path, including closed loops such as a four-bar, and get each interval of the motion reported as clear, colliding or undecided. The dynamics package simulates rigid bodies under gravity, impact and friction.
  • Export meshes: tessellate a body at a chosen tolerance and write STL or OBJ through decad/export.
doc := decad.New()
body, err := doc.Extrude(s, s.Profiles()[0],
    decad.Distance{D: units.Millimeters(10), Dir: decad.Along})

vol, err := body.Volume()
fmt.Println(vol.Value, vol.Exactness)       // 60000 mm^3 Exact

report, err := doc.Verify(ctx)              // solidity, quantities, interference
fmt.Println(report.Status, report.Trustworthy())
// Sound true

Gowrites STL, OBJdepends on sketch, r3, units

The word solidlens in white voxel letters above a floating voxel island with a house, a stone tower, pine trees, a footbridge and a waterfall, on a deep navy background

solidlens

A pure-Go headless raster renderer for triangle meshes.

It loads STL, 3MF and OBJ files, or takes a *decad.Mesh directly, and renders a configured scene to an image.RGBA or a PNG stream. The scene owns the camera, materials, directional and point lights and background; the renderer owns only the output size, so independent scenes render concurrently.

Edge drawing follows the geometry rather than the tessellation: a line appears on a border, on a silhouette, or where two faces meet above the crease angle, so a curved surface keeps its outline instead of turning into a grid of facets.

Goreads STL, 3MF, OBJ

kinetograph work in progress

Animate CAD bodies, cameras, and lights from Go.

Kinetograph places decad bodies on a joint rig and changes their positions over time. Keyframed channels control rotations, slides, camera motion, lighting, opacity, and parametric changes to a body's shape. solidlens renders each frame to a numbered PNG; ffmpeg can turn the frames into a video.

cd _clips/demo && go run . -out out
ffmpeg -framerate 24 -i out/frame_%06d.png -c:v libx264 -pix_fmt yuv420p demo.mp4

Gorenders PNG sequences

step

Write ISO 10303-21 STEP files from Go.

The root package writes Part 21 headers, entity records and values. The ap214 package provides constructors for selected AUTOMOTIVE_DESIGN records.

GoSTEP Part 21 and AP214

Built on the stack

A blue spur gear with a central bore, teeth running straight across the rim A blue helical gear, its teeth slanting evenly around the rim A blue herringbone gear, its teeth meeting in a chevron at mid-height Two bevel gear pairs: a blue spiral-tooth pair and an orange straight-tooth pair, each meshing at a right angle A cycloidal drive laid out in parts: a gray ring housing, two blue lobed discs, an orange eccentric cam, and a green output plate on six pins

fusion360-gear-generator work in progress

Yet another gear generator for Fusion 360 — this one leaves fully constrained sketches behind.

Spur, helical, herringbone and bevel gears, plus a cycloidal drive that builds its lobed discs, eccentric cam, ring housing and output plate as separate sub-components. Gears can be placed on any plane, surface or point pair, and the sketches come out fully constrained, so moving or editing a generated gear behaves.

The add-in translates the models in decad gallery, and those images are renders of the same models.

PythonFusion 360 add-in