- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .claude | ||
| .vscode | ||
| docs/examples/two-color-bolt | ||
| examples/two-color-bolt | ||
| .gitignore | ||
| CHANGELOG.md | ||
| go.mod | ||
| go.sum | ||
| index.md | ||
| LICENSE | ||
| README.md | ||
| ROADMAP.md | ||
| task-plus.yml | ||
| Taskfile.yml | ||
| threemf.go | ||
| threemf_test.go | ||
gsdf-3mf
Write 3MF (3D Manufacturing Format) files from triangle meshes produced by gsdf. Supports multiple parts in a single file with per-part display colour, so a composite assembly prints with the intended colours on a multi-material printer.
Install
go get codeberg.org/hum3/gsdf-3mf
Quick start
import (
threemf "codeberg.org/hum3/gsdf-3mf"
"github.com/soypat/geometry/ms3"
)
parts := []threemf.Part{
{Name: "bolt", Color: threemf.Color{R: 0xC8, A: 0xFF}, Triangles: boltTris},
{Name: "nut", Color: threemf.Color{B: 0xC8, A: 0xFF}, Triangles: nutTris},
}
f, _ := os.Create("assembly.3mf")
defer f.Close()
threemf.Write(f, parts, threemf.UnitMillimeter)
boltTris / nutTris are []ms3.Triangle slices, exactly the type
gsdf/glrender.RenderAll returns.
Demo
The examples/two-color-bolt demo builds an M3
bolt and matching hex nut with gsdf, renders each separately on the CPU,
then writes both as a single 3MF with red bolt and blue nut:
go run ./examples/two-color-bolt -o bolt-nut.3mf
The scene is modelled on gsdf's examples/ui-bolt
but split into two SDF shapes that get rendered as independent meshes. See
the example's README for a full walk-through.
How it works
Each part becomes its own <object> in the 3MF model, with a pid/pindex
pointing at a slot in a shared <basematerials> group. All part objects are
bundled as <components> of a single composite object, and that composite is
the sole <build><item/>. Vertices inside each mesh are deduplicated.
Only the 3MF core spec is used — no extensions, so the output loads in any 3MF reader (Cura, PrusaSlicer, Bambu Studio, Microsoft 3D Builder, etc.).
Links
- Source: https://codeberg.org/hum3/gsdf-3mf
- gsdf: https://github.com/soypat/gsdf
- 3MF spec: https://3mf.io/specification/