Write 3mf files from GSDF sources
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-05-02 10:36:57 +01:00
.claude Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
.vscode Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
docs/examples/two-color-bolt Adding example 2026-04-27 20:14:45 +01:00
examples/two-color-bolt Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
.gitignore removing vscode from dir 2026-05-02 10:36:14 +01:00
CHANGELOG.md Update CHANGELOG for v0.1.1 2026-05-02 10:36:57 +01:00
go.mod Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
go.sum Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
index.md Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
LICENSE Initial commit 2026-04-26 15:56:28 +02:00
README.md Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
ROADMAP.md Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
task-plus.yml Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
Taskfile.yml Add 3MF writer, demo example, and project scaffolding 2026-04-27 20:13:13 +01:00
threemf.go Filter degenerate triangles and add PrusaSlicer project sidecar 2026-05-02 10:22:25 +01:00
threemf_test.go Filter degenerate triangles and add PrusaSlicer project sidecar 2026-05-02 10:22:25 +01:00

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.).