Skip to main content

Building Blocks

The API re-exports common modules for custom workflows. These are the same modules used internally by the import/export pipeline.

from io_mesh_3mf.api import colors, types, segmentation, units

Colors

io_mesh_3mf.common.colors — hex/RGB conversion and sRGB/linear transforms.

FunctionSignatureDescription
srgb_to_linear(c: float) -> floatConvert a single sRGB gamma component to linear.
linear_to_srgb(c: float) -> floatConvert a single linear component to sRGB gamma.
hex_to_rgb(hex_str: str) -> Tuple[float, float, float]Convert #RRGGBB hex string to an (r, g, b) tuple of 0-1 floats.
hex_to_linear_rgb(hex_str: str) -> Tuple[float, float, float]Convert #RRGGBB hex string to an (r, g, b) tuple in linear space.
rgb_to_hex(r: float, g: float, b: float) -> strConvert 0-1 float RGB values to a #RRGGBB hex string.
linear_rgb_to_hex(r: float, g: float, b: float) -> strConvert linear RGB (0-1) to a #RRGGBB sRGB hex string.

Units

io_mesh_3mf.common.units — unit conversion between 3MF and Blender.

VariableDescription
threemf_to_metreDict mapping 3MF unit strings to metre scale factors
blender_to_metreDict mapping Blender unit strings to metre scale factors
FunctionSignatureDescription
import_unit_scale(context: bpy.types.Context, root, global_scale: float) -> floatCompute the import scale factor from 3MF document units to Blender scene units.
export_unit_scale(context: bpy.types.Context, global_scale: float) -> floatCompute the export scale factor from Blender scene units to 3MF millimeters.

Types (Dataclasses)

io_mesh_3mf.common.types — internal data structures used throughout the pipeline.

Key dataclasses:

  • ResourceObject — A parsed <object> element from a 3MF model file.
  • Component — A <component> reference inside an <object>.
  • ResourceMaterial — Material properties parsed from 3MF basematerials, colorgroups, or PBR extensions.
  • ResourceTexture — A <texture2d> element — texture image metadata.
  • ResourceTextureGroup — A <texture2dgroup> container for texture coordinates.
  • ResourceComposite — Composite materials (Materials Extension) for round-trip support.
  • ResourceMultiproperties — Multiproperties (Materials Extension) for round-trip support.
  • ResourcePBRTextureDisplay — Textured PBR display properties (metallic/specular texture maps).
  • ResourceColorgroup — Passthrough storage for <colorgroup> elements.
  • ResourcePBRDisplayProps — Passthrough storage for non-textured PBR display properties.

Segmentation Codec

io_mesh_3mf.common.segmentation — encode/decode hex segmentation strings used for multi-material paint data.

ClassDescription
SegmentationNodeA node in the triangle subdivision tree.
SegmentationDecoderDecodes PrusaSlicer segmentation strings into subdivision trees.
TriangleSubdividerSubdivides triangles based on segmentation trees.
SegmentationEncoderEncodes subdivision trees back to PrusaSlicer hex strings.

The codec implements the recursive 4-bit nibble encoding used by Orca Slicer and PrusaSlicer, where each nibble xxyy encodes the state (2 bits) and split direction (2 bits) of a triangle subdivision.

Extensions

io_mesh_3mf.common.extensions — extension registry and validation.

ClassDescription
ExtensionRepresents a 3MF extension with its metadata and capabilities.
ExtensionManagerManages active extensions for import/export operations.

Metadata

io_mesh_3mf.common.metadata — metadata storage and merging.