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.
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 agentWrite sketches and features
→
sketch + decadBuild a 3D body
↓
Check the resultDo 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 stepsCAD 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.
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
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
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
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.
Extrude sweeps a solved profile straight into a solid.Revolve spins a profile about an axis.Sweep carries a profile along a tangent 3D path.Loft joins profiles on different planes.Free-form profiles preserve and measure exact spline walls.Fillet rounds selected edges into tangent arcs.Chamfer cuts selected edges back to a straight bevel.Cap-loop chamfer bevels a whole rim in one operation.Shell hollows a solid to one wall thickness.Union, Cut and Intersect combine bodies explicitly.Verify checks fits and proves clearance between bodies.Surface results leave a feature's swept walls as a sheet body.
Folding arm moves to the last pose the linkage check proves clear,
just short of the stop block.Crank-rocker shows the same check on a closed four-bar loop.Tumble drops spinning solids into a tray, where each one comes to
rest on a face.Parts bin drops five modeled parts to rest while a cylinder rolls
across the floor.
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.
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
Parametric 3D shapes, patterns, and assemblies built with decad.
Each model is a solid body whose dimensions come from inputs such as tooth count,
thickness, and bore: spur, helical and herringbone gears, a cycloidal drive, and bevel
gear pairs. Every model ships a written specification and a step-by-step map from each
construction requirement to a sketch or decad
operation, with a geometry check at each boundary.
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.