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

5.6 KB
Raw Blame

Why Forma exists

Forma exists because desktop 3D suites and AI coding agents optimize for opposite constraints. Traditional CAD and DCC tools like Blender (bpy) assume a human is looking at a live GPU viewport, clicking faces with a mouse, and tolerating multi-hundred-megabyte installations. An autonomous agent operates headless, pays for every token in its context window, and has no visual feedback unless the engine hands back structured geometric truth.

Why headless desktop 3D engines struggle under AI agents

When an agent drives a desktop engine through an imperative Python API like bpy, four structural failure modes appear repeatedly (documented empirically in the repository's Phase 1 architecture audit and Phase 1 baseline report):

  1. Fragile integer topology indices: Imperative mesh scripts select vertices, edges, and faces by numeric index (faces[14]). Any upstream boolean or subdivision renumbers every index, turning small edits into silent geometric corruption.
  2. Verbose imperative boilerplate: Modeling a single flanged bracket in raw Python requires dozens of object-mode switches, modifier stack calls, bmesh updates, and transform cleanups. More tokens mean higher latency, higher cost, and more opportunities for syntax or state errors.
  3. Silent non-manifold failures: A boolean operation can leave open boundary edges, inverted winding, zero-area faces, or non-manifold seams without raising an exception. Downstream slicers or game engines only discover the damage after the script finishes.
  4. Heavyweight deployment footprint: Shipping a full desktop runtime (>1 GB installed) inside CI runners, edge workers, air-gapped sandboxes, or container microservices makes fast, deterministic 3D verification impractical.

Four core design decisions in Forma

Forma addresses those failure modes at the kernel level rather than wrapping a desktop program in a thin adapter.

Semantic selectors instead of integer indices

Every primitive and operation in forma-core preserves topological lineage and tags faces semantically (top, bottom, front, back, left, right, hole, bevel, side). Edge selectors such as vertical, top_rim, outer_rim, and sharp resolve dynamically against current geometry rather than hard-coded vertex numbers. An agent can bevel every vertical corner after five boolean cuts without knowing how many vertices the booleans created.

Watertightness as a default invariant, not an afterthought

Forma represents solids as double-precision (f64) polyhedral meshes and runs a single-pass, sort-based topological check (MeshInvariants) after evaluation. By default, strict mode enforces closed watertightness (boundary_edges == 0), zero non-manifold edges, consistent half-edge winding, finite vertex coordinates, and non-degenerate volume compactness. When an edit breaks manifoldness, the kernel rejects it immediately instead of exporting broken geometry.

Copy-on-write transactions for safe exploration

Exploratory modeling naturally involves failed booleans or overly aggressive bevels. Because Scene stores each named part behind an Arc<PolyMesh>, taking a snapshot before an evaluation or on an explicit checkpoint clones only smart pointers in O(1) time. If a script errors or fails strict verification, Scene restores both the previous mesh pointers and the previous length unit automatically, leaving prior valid work untouched.

Compact textual observations over blind execution

Instead of returning silent success or forcing an agent to render and decode images on every intermediate step, Forma emits a compact observation channel (roughly 100 tokens) summarizing vertex/face counts, watertightness, non-manifold edge count, genus, volume, bounding box, semantic tag distribution, and the delta from the previous state. Visual PNG and SVG renders remain available when the caller wants spatial verification, while routine geometric checks stay cheap and deterministic.

Why Forma enforces strict contributor budgets

Forma's CONTRIBUTING.md treats four constraints as non-negotiable architectural invariants rather than cosmetic targets:

  • Small binary footprint (~1.3–1.8 MB native, ~0.8 MB WASM): Zero heavy C++ geometry kernels, no GPU driver stack, and no runtime dependencies in the npm package keep cold starts in milliseconds across laptops, edge workers, AWS Lambda, CI containers, and air-gapped VMs.
  • Sub-800-token MCP surface (723 o200k tokens): Every tool schema attached to an MCP session consumes context on every turn of a conversation. Keeping the core MCP interface to four tools (eval, inspect, tx, export) and deferring niche operators behind on-demand inspect(topic) queries preserves context headroom for actual user tasks.
  • Strict manifoldness by default: Opting out of watertightness requires an explicit choice rather than happening silently.
  • Opt-in crates for specialized surfaces: Capabilities such as the HTTP microservice (forma-server), WebAssembly bindings (forma-wasm), and planned domain addons stay outside Cargo's default-members so users who only need the core CLI or MCP server never pay their compile-time or dependency cost.

Further reading