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

9.7 KB
Raw Blame

Language, units, and formats reference

Authoritative specification for Forma's two modeling dialects, semantic selectors, progressive topic extensions, unit system, and import/export formats (v0.4.5). For the exact live compiled prompt text, run forma spec or npx forma-3d spec.

Coordinate system and evaluation rules

  • Axes: Right-handed Z-up internally. glTF (.glb) export automatically converts to Y-up ([x, z, -y]).
  • Default unit: 1.0 equals one meter (Unit::Meter) unless overridden by units("..."), --unit, JS { unit }, or HTTP unit.
  • Export target: The last assigned or modified part exports by default unless a specific part or multi-part scene export/render (scene: true / --scene for .glb, .blend, .obj, .3mf, .stl, .step, .png, or .svg) is requested.
  • Variables & scope: Scalar variables persist across stateful eval calls (such as MCP sessions) and roll back with tx. Mesh variables prefixed with _ (for example _tmp = ...) stay local to the script and do not pollute scene.parts or scene: true exports. Use del("name") to delete a named part from scene.parts.
  • Transactional rollback: Every eval_script call pushes an undo snapshot before execution and restores geometry, scalar variables, and Scene.unit if any statement fails or violates strict invariants.

Dialects

Dialect CLI --dialect values Structure Formal grammar
Forma-Pipe (default) pipe, forma-pipe, a, default Expression pipeline: name = prim | op | op with multi-line |, macros (def name(p1, p2=default) = expr), list comprehensions ([expr for i in range(n)], 1/2/3-arg range), arithmetic (+ - * / sqrt sin cos tan asin acos atan atan2 abs deg rad pi), keyword arguments, and coordinate lists at=[(x,y,z), ...]. grammar/forma_pipe.gbnf (spec --gbnf)
Forma-DSL (compact) compact, dsl, forma-dsl, b Line-oriented imperative statements (new, add, sub, int, bev, shl, ext, ins, subdiv, mov, rot, scl, z0, mir, del, ckpt, rb, undo, units). Built-in EBNF (spec --dialect compact)

Core Forma-Pipe primitives

Primitive Signature Notes
box box(sx, sy, sz, at=, z0=) Centered at origin unless at or z0 is given.
cyl cyl(r, h, segs=32, axis=z, at=, z0=) segs=6 places vertices at k * 60 degrees.
cone cone(r0, r1, h) Tapered frustum or cone when r1=0.
sphere sphere(r) Closed watertight UV/polyhedral sphere.
torus torus(R, r) Major radius R, minor tube radius r.
revolve revolve([(r, z), ...], segs=32) Lathe profile around Z; auto-closes to r = 0.
arc_tube arc_tube(center=(x, y, z), rx=, rz=, start=-90, end=90, r=0.08) Swept tube along an XZ elliptical arc (degrees).
tube tube([(x, y, z), ...], r=0.08) Circular tube along a 3D polyline or bezier()/nurbs() path.
extrude2d extrude2d([(x, y), ...], z0, z1, holes=) Watertight 2D polygon extrusion with optional inner hole loops.
pipe pipe(ro, ri, h) Hollow cylinder (outer radius ro, inner radius ri).
gear gear(teeth, module=1.0, h=1.0, pressure_angle=20, bore=0) Involute spur gear (tooth 0 on +X; meshing pair at center distance m*(z1+z2)/2 with gear 2 rotated 180/z2 degrees when z2 is even, 0 degrees when z2 is odd).
loft loft([(z, [(x, y), ...]), ...]) Lofted solid between planar cross-sections at heights z.
thread thread(r0, r1, pitch, turns) Helical screw thread solid (r0/r_minor, r1/r_major).
sweep sweep(profile2d, path3d, scale_end=1.0, twist=0.0, closed=false) Parallel-transport 3D rail sweep with optional taper and twist.
text3d text3d("TEXT", height=0.5, depth=0.1) Watertight 3D extruded vector text (size= alias supported).

Core Forma-Pipe operators and queries

Category Operators
Booleans add(b, at=), cut(b, at=), intersect(b) (at accepts (x,y,z) or [(x,y,z), ...])
Patterns and symmetry mirror(x|y|z), array(n, step) / pattern_linear(n, step), radial(n, r=, axis=z) / pattern_radial(n, r=, axis=z)
Topology modifiers shell(t, open_top=true), subsurf(levels=1, crease=false), bevel(edges, w, segs=1), extrude(faces, d), inset(faces, amt, depth=0)
Transforms and placement move(x, y, z), rot(rx, ry, rz), scale(sx, sy, sz), align(x|y|z, min|center|max, val), on(base, gap=0), align_z0(z)
Materials mat(name, color=(r, g, b[, a]), metallic=0.0, roughness=0.5, alpha=1.0, emissive=(r, g, b), emissive_strength=1.0, transmission=0.0, ior=1.5, double_sided=false, faces=), color(r, g, b[, a], alpha=) (display sRGB converted to linear RGB in glTF .glb export)
Queries, state, and units clearance(a, b), section(part, z), units("m|cm|mm|um|in|ft"), checkpoint(tag), rollback(tag), undo(), del(name)

Semantic selectors

Selector kind Built-in selectors
Edge selectors (bevel) vertical, horizontal, top_rim, bottom_rim, outer_rim, sharp, sharp:<deg>, boundary, all
Face selectors (extrude, inset, mat) top, bottom, front, back, left, right, sides, all

Progressive spec_topic domains

Query via forma spec --topic <name>, npx forma-3d spec --topic <name>, GET /spec?topic=<name>, getSpecTopic(name), or MCP inspect({ topic }).

Topic Aliases Exposed operators / behavior
deform deform solidify(t, offset=-1.0, open_top=false), deform("bend"|"twist"|"taper", axis=, angle=, factor=, subdivs=), deform("curve", path=, axis=), deform("lattice", corners=[8 Vec3 points in (x,y,z) bit order])
curves curves bezier([(x,y,z), ...], segs=24), nurbs([(x,y,z), ...], degree=3, segs=32, weights=), extrude2d(outer, z0, z1, holes=...), sweep(profile2d, path3d, scale_end=1.0, twist=0.0, closed=false)
uv uv, normals smooth(angle=35, weighted=true), flat(), unwrap(angle=45, margin=0.01), decimate(ratio=0.5, faces=)
remesh remesh remesh(voxel_size=0.0) (0 = auto diag/28), bisect(normal=(0,0,1), offset=0.0, clear_inner=false), load("path.glb|obj|stl", yup=)
scene scene Multi-object scene graph export & rendering (--scene in CLI, scene: true in MCP export for .glb, .blend, .obj, .3mf, .stl, .step, .png, and .svg, exportSceneBytes(format) in JS/TS); _-prefixed locals and del("name").

Invariant metrics (MeshInvariants)

Field Observation key Strict requirement
watertight WT=ok / WT=OPEN Must be true (boundary_edges == 0 and every undirected edge shared by 2 half-edges).
non_manifold_edges NM=0 Must be 0.
boundary_edges B=0 Must be 0.
consistent_winding Included in ok Opposite half-edge orientation across shared edges.
nan_verts Included in ok Must be 0 (all vertex coordinates finite).
degenerate_faces Included in ok Area below 1e-12 or fewer than 3 vertices.
volume, surface_area vol=... Positive volume; compactness volume / surface_area^1.5 >= 1e-9 (MIN_COMPACTNESS).
verts, faces, genus V=, F=, g= Reported for every named part along with bbox, size, and tags.

Unit conversion table (crates/forma-core/src/units.rs)

Symbol Accepted aliases (case-insensitive) Meters per unit 3MF model/@unit
um micron, microns, micrometer, micrometers, micrometre, micrometres 1e-6 micron
mm millimeter, millimeters, millimetre, millimetres 1e-3 millimeter
cm centimeter, centimeters, centimetre, centimetres 1e-2 centimeter
m (default) meter, meters, metre, metres 1.0 meter
in inch, inches 0.0254 inch
ft foot, feet 0.3048 foot

Export and import formats

Format Extension Direction Unit handling Axis / notes
Binary glTF 2.0 .glb Import + Export Scaled to meters (meters_per_unit()) Y-up conversion, sRGB→linear PBR materials (alphaMode: "BLEND", doubleSided, emissiveFactor, KHR_materials_transmission, KHR_materials_ior, KHR_materials_emissive_strength), optional TEXCOORD_0 UVs (via unwrap()); supports multi-node --scene / scene: true.
STEP AP214 .step, .stp Export Declares model unit in header Faceted B-Rep solid for CAD interoperability; supports multi-solid --scene / scene: true.
3D Manufacturing Format .3mf Export Declares model/@unit Ready for modern 3D-printing slicers; supports multi-object --scene / scene: true.
Binary STL .stl Import + Export Raw model units (format has no unit field) Triangulated mesh; supports combined --scene / scene: true.
Wavefront OBJ .obj Import + Export Raw model units (format has no unit field) Polygons/triangles; supports multi-object o <name> --scene / scene: true.
PNG preview .png Export Scale-invariant framed view Pure-Rust software rasterizer (4-view quad default; single views on native CLI); supports --scene / scene: true to render all named parts together with materials.
SVG blueprint .svg Export Dimensioned in model units 3-view orthographic engineering drawing; supports --scene / scene: true for multi-part scenes.
Blender file .blend Export (CLI & MCP) Scaled to meters via glTF bridge Invokes local Blender (BLENDER_BIN or blender on PATH); supports --scene / scene: true.