Build pipeline
How a Go source file in cmd/ becomes a printable STL, a coloured 3MF, and a set of dimensioned SVG cutaways.
Stages
- Source — each part lives in its own
cmd/<part>/directory as a smallmainpackage. Geometry is defined in plain Go usinggsdfprimitives plus the sharedpkg/fastenerscatalogue (WoodScrewschematic / threaded / wall-cutout variants).main.goparses flags (-size,-part,-out,-mesh) and dispatches to the build pipeline below. - SDF tree —
gsdfcomposes primitives (boxes, cylinders, octagonal prisms, screws, etc.) with boolean operations into a single signed-distance-function tree. No mesh yet — just a function that, given a 3D point, returns the signed distance to the surface. - CPU evaluation —
gleval.NewCPUSDF3compiles the tree for fast batched evaluation on the CPU. The same evaluator drives both the mesh renderers (3D grid sampling) and the SVG slicer (2D plane sampling). - Mesh rendering — two algorithms, picked by the
-meshflag:OctreeRenderer(marching cubes) — original pipeline, larger triangle counts, tolerant of slicer quirks.DualContourRenderer(dual contouring) — sharper edges on flat faces, fewer triangles before merging.
- Optional planar merge —
pkg/meshopt.PlanarMergecollapses fans of coplanar triangles back to single polygons (re-triangulated as fans). Default for 3MF; cuts adaptor file size by ~95%, and blocks/covers by 15-35%. Skipped for-mesh=octreeand-mesh=dc. - Cross-section slicing —
pkg/svgsliceevaluates the SDF on a user-supplied plane (origin + U/V basis vectors), runs marching squares to extract contour line segments, and writes them as an SVG<path>with optional dimension annotations and labels. - Writers:
- STL —
gsdfaux.RenderShader3D→ binary STL viaglrender.NewOctreeRenderer. - 3MF —
gsdf-3mfzips a 3D Manufacturing Format file with one part per colour. Used for browser previews and for slicers that respect material assignments. - SVG —
svgslice.WriteSliceLabelledwrites a millimetre-scale SVG, suitable both for documentation and for round-tripping into 2D CAD.
- STL —
Mesher choice
The -mesh flag for 3MF output trades file size against pipeline complexity. The task v0:3mf shortcut uses the default (merge).
-mesh |
Triangles | When to use |
|---|---|---|
merge |
Smallest | Default. Coplanar fans collapsed. Adaptors shrink ~95%. |
dc |
Medium | Same triangle count as merge before the merge step — useful to bisect a slicer issue blamed on the merge pass. |
octree |
Largest | Original pipeline. Use if a slicer rejects the merged output (potential T-junctions across faces). |
Where each artefact comes from
| Artefact | Pipeline |
|---|---|
*.stl |
gsdf → gleval → octree → WriteBinarySTL |
*.3mf (default) |
gsdf → gleval → dual contouring → planar merge → gsdf-3mf |
*.3mf (-mesh=dc) |
gsdf → gleval → dual contouring → gsdf-3mf |
*.3mf (-mesh=octree) |
gsdf → gleval → octree → gsdf-3mf |
*_cutaway_*.svg |
gsdf → gleval → svgslice (marching squares + labels) |
Source
- Diagram source: process-flow.d2 — rendered with d2.