threemf

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 7 Imported by: 2

README

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

Documentation

Overview

Package threemf writes 3MF (3D Manufacturing Format) files from triangle meshes produced by github.com/soypat/gsdf. Multiple coloured parts are emitted as separate build items so that slicers (Cura, 3D Builder, etc.) see them as distinct objects. Two PrusaSlicer-specific sidecars are also emitted: Metadata/Slic3r_PE_model.config assigns each part to its own extruder, and Metadata/Slic3r_PE.config sets a filament_colour list so PrusaSlicer renders the parts in their native colours regardless of the loaded printer profile.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, parts []Part, unit Unit) error

Write encodes parts into a single 3MF file written to w. Each part becomes its own mesh object referencing a slot in a shared <basematerials> group, and is emitted as a separate <item> in the build. A PrusaSlicer-specific sidecar assigns one extruder per part.

Types

type Color

type Color struct {
	R, G, B, A uint8
}

Color is an sRGB color with alpha.

type Part

type Part struct {
	Name      string
	Color     Color
	Triangles []ms3.Triangle
}

Part is one colored mesh inside a 3MF file.

type Unit

type Unit string

Unit is the model length unit declared in the 3MF.

const (
	UnitMillimeter Unit = "millimeter"
	UnitMeter      Unit = "meter"
	UnitInch       Unit = "inch"
	UnitFoot       Unit = "foot"
	UnitMicron     Unit = "micron"
	UnitCentimeter Unit = "centimeter"
)

Directories

Path Synopsis
examples
two-color-bolt command
two-color-bolt builds an M3 bolt and matching nut with the gsdf SDF builder, renders each to a triangle mesh, then writes both as a single 3MF file with the bolt and nut painted different colors.
two-color-bolt builds an M3 bolt and matching nut with the gsdf SDF builder, renders each to a triangle mesh, then writes both as a single 3MF file with the bolt and nut painted different colors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL