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.
| Function | Signature | Description |
|---|---|---|
srgb_to_linear | (c: float) -> float | Convert a single sRGB gamma component to linear. |
linear_to_srgb | (c: float) -> float | Convert 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) -> str | Convert 0-1 float RGB values to a #RRGGBB hex string. |
linear_rgb_to_hex | (r: float, g: float, b: float) -> str | Convert linear RGB (0-1) to a #RRGGBB sRGB hex string. |
Units
io_mesh_3mf.common.units — unit conversion between 3MF and Blender.
| Variable | Description |
|---|---|
threemf_to_metre | Dict mapping 3MF unit strings to metre scale factors |
blender_to_metre | Dict mapping Blender unit strings to metre scale factors |
| Function | Signature | Description |
|---|---|---|
import_unit_scale | (context: bpy.types.Context, root, global_scale: float) -> float | Compute the import scale factor from 3MF document units to Blender scene units. |
export_unit_scale | (context: bpy.types.Context, global_scale: float) -> float | Compute 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.
| Class | Description |
|---|---|
SegmentationNode | A node in the triangle subdivision tree. |
SegmentationDecoder | Decodes PrusaSlicer segmentation strings into subdivision trees. |
TriangleSubdivider | Subdivides triangles based on segmentation trees. |
SegmentationEncoder | Encodes 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.
| Class | Description |
|---|---|
Extension | Represents a 3MF extension with its metadata and capabilities. |
ExtensionManager | Manages active extensions for import/export operations. |
Metadata
io_mesh_3mf.common.metadata — metadata storage and merging.