Skip to content

armgit / forma

Public Imported from GitHub
0

A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server

3.3 KB
Raw Blame

How to work with units and process existing meshes

Use this guide to author dimensionally accurate parts in millimeters or imperial units and to import, normalize, bisect, heal, or decimate existing 3D meshes.

Declare model units inside your script (portable across all surfaces)

Forma geometry is unitless internally (1.0 equals one model unit, defaulting to meters). Add units("mm") (or m, cm, um, in, ft) at the top of your Forma-Pipe script so the exact same script behaves identically across the native CLI, forma-3d WASM CLI, MCP server, JS/TS/Edge API, and forma-server:

units("mm")
enclosure = box(100, 60, 25, z0=0)
  | bevel(vertical, 4)
  | shell(2.4, open_top=true)

You can also set the starting unit from outside the script via --unit on both CLIs (forma and forma-3d), { unit: "mm" } in the JS/TS API, or "unit": "mm" in forma-server (POST /v1/eval):

forma eval --unit mm --out enclosure.3mf enclosure.forma
npx forma-3d eval --unit mm --out enclosure.3mf enclosure.forma

Verify how each exporter handles your declared unit

  • .3mf: embeds model/@unit (millimeter, meter, centimeter, micron, inch, or foot) so slicers open the part at true physical scale.
  • .step: declares the model length unit inside the STEP AP214 header.
  • .glb: automatically scales vertex positions by unit.meters_per_unit() because the glTF 2.0 specification requires meters (and converts Z-up to glTF Y-up).
  • .svg: labels orthographic dimension callouts, size, and volume with your declared unit symbol (mm, in, m, etc.).
  • .stl and .obj: have no standard unit metadata field and are written in raw model units.

Import, normalize, and decimate an existing mesh

Load an existing .glb, .obj, or .stl mesh with load(...), inspect its invariants, and chain standard modeling or mesh-processing operators:

part = load("scan.obj")
  | remesh(voxel_size=0.05)
  | decimate(ratio=0.5)
  | smooth(angle=35, weighted=true)
  | align_z0(0)

Evaluate and export with the CLI:

forma eval --strict --out clean.glb --render preview.png cleanup.forma

Operator checklist for dirty or high-poly meshes

  • Heal open holes or multi-shell scans: run remesh(voxel_size=0.08) (pure-Rust Surface Nets voxel remesh) to produce a watertight solid before downstream booleans.
  • Cut a flat base or split a model in half: run bisect(normal=(0, 0, 1), offset=0.0, clear_inner=false) to slice cleanly with a watertight planar cap.
  • Reduce triangle count for real-time engines: run decimate(ratio=0.5) or decimate(faces=2000) (Link-Condition QEM reduction that preserves WT=ok NM=0).
  • Generate clean UVs and shading normals: run unwrap(angle=45, margin=0.01) followed by smooth(angle=35, weighted=true).

Normalize assets over HTTP without writing a script

If you run forma-server, use POST /v1/process to perform Y-up to Z-up conversion ("yup": true), uniform or per-axis scaling ("scale": 0.001 or "scale": [sx, sy, sz]), resting on z = 0 ("center_z0": true), and QEM decimation ("decimate" and/or "target_faces") in a single request. See How to deploy Forma.

Related references