A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server
release: v0.4.1 — scale-invariant vol guard, overlap warnings, Issue #10/#11 tests, updated Issue #12 metrics (Fixes #12)
wrong-nebula53bfeb4e4dca
diff --git a/AGENTS.md b/AGENTS.mdindex f6fe56f..cf7db1c 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1,6 +1,6 @@# Using Forma with AI Agents-Forma is a 1.2 MB pure-Rust rewrite of headless Blender built so any LLM or coding agent can create, inspect, and export watertight 3D models in milliseconds with minimal token overhead.+Forma is a ~1.7 MB native (~0.8 MB WASM) pure-Rust headless 3D polyhedral modeling engine built so any LLM or coding agent can create, inspect, and export watertight 3D models in milliseconds with minimal token overhead.---diff --git a/Cargo.lock b/Cargo.lockindex 3aadc37..6e606da 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4,7 +4,7 @@ version = 4[[package]]name = "forma-cli"-version = "0.4.0"+version = "0.4.1"dependencies = ["forma-core","forma-lang",@@ -13,7 +13,7 @@ dependencies = [[[package]]name = "forma-core"-version = "0.4.0"+version = "0.4.1"dependencies = ["serde","serde_json",@@ -23,7 +23,7 @@ dependencies = [[[package]]name = "forma-lang"-version = "0.4.0"+version = "0.4.1"dependencies = ["forma-core","serde",@@ -32,7 +32,7 @@ dependencies = [[[package]]name = "forma-mcp"-version = "0.4.0"+version = "0.4.1"dependencies = ["forma-core","forma-lang",@@ -42,7 +42,7 @@ dependencies = [[[package]]name = "forma-server"-version = "0.4.0"+version = "0.4.1"dependencies = ["forma-core","forma-lang",@@ -51,7 +51,7 @@ dependencies = [[[package]]name = "forma-wasm"-version = "0.4.0"+version = "0.4.1"dependencies = ["forma-core","forma-lang",diff --git a/Cargo.toml b/Cargo.tomlindex ac8f1a4..8814afd 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -16,7 +16,7 @@ default-members = [][workspace.package]-version = "0.4.0"+version = "0.4.1"edition = "2021"license = "MIT"diff --git a/README.md b/README.mdindex be220d0..4f6b5fb 100644--- a/README.md+++ b/README.md@@ -1,6 +1,6 @@# Forma-**A 1.2 MB pure-Rust headless 3D polyhedral modeling engine built for AI agents — CLI, WASM, and MCP server.**+**A ~1.7 MB native / ~0.8 MB WASM pure-Rust headless 3D polyhedral modeling engine built for AI agents — CLI, WASM, and MCP server.**<p align="center"><img src="assets/readme_hero.png" alt="Forma — Pure-Rust Rewrite of Headless Blender for AI Agents" width="100%" />@@ -13,8 +13,8 @@ Forma replaces headless Blender's 3D mesh modeling, boolean, and studio-preview| **Cold-Start Eval + GLB Export** | 1,306.8 ms | **16.9 ms** (`5.4 ms` batch flange) | **~77×–89× faster** || **Completion Tokens (12-model avg)** | 294,661 total | **84,551 total** | **3.49× fewer** (up to **15.5×**) || **Pass Rate (12 models / 10 labs)** | 79.1% (`bpy`) | **95.5% – 100%** | **+16.4 pp** |-| **Binary / Install Footprint** | 953 MB | **1.2 MB** | **~800× smaller** |-| **Peak Memory RSS** | 223 MB | **2.16 MB** | **103× less RAM** |+| **Binary / Install Footprint** | 953 MB | **~1.7–1.8 MB** native (**~0.8 MB** WASM) | **~530× smaller** |+| **Peak Memory RSS** | 223 MB | **~6–14 MB** (`6.1 MB` macOS / `13.5 MB` Linux) | **~16×–36× less RAM** || **MCP Tool Schema Budget** | — | **789 `o200k` tokens** (4 tools) | Strictly `< 800` |---@@ -26,7 +26,7 @@ Forma replaces headless Blender's 3D mesh modeling, boolean, and studio-preview- **Spatial Constraints & Queries:** Relational placement (`| on(base)`, `| align(axis, min|center|max, val)`), exact 3D `clearance(a, b)`, 2D `section(part, z)` loop/area queries, and Euler genus (`g`) diagnostics.- **Zero-GPU Rendering & Blueprints:** Built-in 4-view (`Front / Right / Top / Iso`) studio PNG renderer with SSAO-lite + depth silhouettes + pure-Rust Deflate compression (`~20–75 KB` PNG in ~4 ms), plus dimensioned 1200×900 vector SVG technical blueprints (`forma draw`).- **Universal Import, Decimation & Export:** Pure-Rust `.glb` (glTF 2.0 Y-up), `.obj`, and `.stl` importers (`load("item.glb")`), topology-preserving QEM mesh decimation (`| decimate(0.5)`), native `.glb` (PBR + LSCM/triplanar UVs), faceted ISO 10303-21 `.step` (watertight planar-face solid; no analytic cylinders/NURBS), `.3mf`, `.stl`, `.obj`, `.svg`, `.png`, and `.blend` (via optional Blender bridge).-- **Optional Headless Server (`forma-server`):** Separate opt-in HTTP/1.1 worker crate (`cargo build --release -p forma-server`, `1.4 MB` binary, `< 5 MB` scratch `Dockerfile`) with zero impact on the core `forma` CLI, `forma-mcp`, or `forma-3d` npm/WASM bundle.+- **Optional Headless Server (`forma-server`):** Separate opt-in HTTP/1.1 worker crate (`cargo build --release -p forma-server`, compact static binary, `< 5 MB` scratch `Dockerfile`) with zero impact on the core `forma` CLI, `forma-mcp`, or `forma-3d` npm/WASM bundle.---@@ -44,7 +44,7 @@ section(flange, 0.0)EOF```-### Option 2 — Build Native 1.2 MB Rust Binary+### Option 2 — Build Native Rust Binary (~1.7–1.8 MB)```bashgit clone https://github.com/wrong-nebula/forma.gitdiff --git a/SKILL.md b/SKILL.mdindex b9d110e..f2d419e 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,11 +1,11 @@---name: forma-description: Create, modify, inspect, render, and export watertight 3D polyhedral models in milliseconds using Forma (a 1.2 MB pure-Rust headless 3D modeling engine). Use whenever a task involves 3D mesh/CAD generation, mechanical parts, enclosures, brackets, threads, lofts, pipes, booleans, .glb/faceted .step/.3mf/.stl/.obj/.blend export, 4-view .png studio previews, or dimensioned .svg engineering blueprints.+description: Create, modify, inspect, render, and export watertight 3D polyhedral models in milliseconds using Forma (a ~1.7 MB native / ~0.8 MB WASM pure-Rust headless 3D modeling engine). Use whenever a task involves 3D mesh/CAD generation, mechanical parts, enclosures, brackets, threads, lofts, pipes, booleans, .glb/faceted .step/.3mf/.stl/.obj/.blend export, 4-view .png studio previews, or dimensioned .svg engineering blueprints.---# Forma — Headless 3D Modeling Skill-Forma is a 1.2 MB pure-Rust headless 3D modeling engine built for AI agents. It evaluates a compact declarative pipe language (`Forma-Pipe`) into strict, watertight polyhedral solid geometry in ~5–17 ms with zero GPU required.+Forma is a lightweight pure-Rust headless 3D modeling engine (~1.7 MB native / ~0.8 MB WASM) built for AI agents. It evaluates a compact declarative pipe language (`Forma-Pipe`) into strict, watertight polyhedral solid geometry in ~5–17 ms with zero GPU required.## 1. Choose Your Interfacediff --git a/bin/forma-mcp.mjs b/bin/forma-mcp.mjsindex 4dcd399..b07f4a6 100755--- a/bin/forma-mcp.mjs+++ b/bin/forma-mcp.mjs@@ -10,7 +10,7 @@ import { extname } from "node:path";import { performance } from "node:perf_hooks";import { loadForma } from "../lib/index.mjs";-const VERSION = "0.4.0";+const VERSION = "0.4.1";function buildToolsSchema(specPipe) {return [diff --git a/bin/forma.mjs b/bin/forma.mjsindex 448b6c7..458e7c8 100755--- a/bin/forma.mjs+++ b/bin/forma.mjs@@ -1,6 +1,6 @@#!/usr/bin/env node/**- * forma-3d CLI — cross-platform pure-WASM headless 3D B-rep modeling engine.+ * forma-3d CLI — cross-platform pure-WASM headless 3D polyhedral modeling engine.* Supports: eval, render, draw, spec, mcp, version, --help*/@@ -9,11 +9,11 @@ import { extname } from "node:path";import { performance } from "node:perf_hooks";import { loadForma } from "../lib/index.mjs";-const VERSION = "0.4.0";+const VERSION = "0.4.1";function printHelp() {process.stdout.write(- `forma ${VERSION} (WASM) — 1.2 MB pure-Rust rewrite of headless Blender for AI agents\n\n` ++ `forma ${VERSION} (WASM) — pure-Rust headless 3D polyhedral modeling engine for AI agents\n\n` +`USAGE:\n` +` forma-3d eval [--dialect pipe|compact] [--strict] [--json] [--out path.(glb|obj|stl|3mf|step)] [--render preview.png] [--draw blueprint.svg] [file|-]\n` +` forma-3d render [--size 512] --out preview.png [file|-]\n` +diff --git a/crates/forma-cli/src/main.rs b/crates/forma-cli/src/main.rsindex f4b14d7..343ebc7 100644--- a/crates/forma-cli/src/main.rs+++ b/crates/forma-cli/src/main.rs@@ -13,7 +13,7 @@ use std::process::{self, Command};fn print_help() {println!(- "forma 0.4.0 — ultra-fast, headless, watertight, LLM-native 3D modeling engine\n\+ "forma 0.4.1 — ultra-fast, headless, watertight, LLM-native 3D modeling engine\n\\n\USAGE:\n\forma eval [--dialect pipe|compact] [--strict|--no-strict] [--json] [--out path.(glb|obj|stl|3mf|step|blend)] [--render preview.png] [--draw blueprint.svg] [file|-]\n\@@ -71,7 +71,7 @@ fn main() {match args[0].as_str() {"version" | "--version" | "-V" => {- println!("forma 0.4.0");+ println!("forma 0.4.1");return;}"spec" => {diff --git a/crates/forma-core/src/invariants.rs b/crates/forma-core/src/invariants.rsindex 160e320..5897bef 100644--- a/crates/forma-core/src/invariants.rs+++ b/crates/forma-core/src/invariants.rs@@ -41,6 +41,8 @@ pub struct MeshInvariants {pub components: usize,pub signed_volume: f64,pub volume: f64,+ #[serde(default)]+ pub surface_area: f64,pub bbox_min: [f64; 3],pub bbox_max: [f64; 3],pub size: [f64; 3],@@ -66,6 +68,7 @@ impl MeshInvariants {let mut degenerate_faces = 0usize;let mut tris = 0usize;let mut vol6 = 0.0f64;+ let mut surface_area = 0.0f64;for (fi, f) in mesh.faces.iter().enumerate() {let fv = &f.verts;@@ -89,7 +92,9 @@ impl MeshInvariants {vol6 += mesh.verts[a].dot(mesh.verts[b].cross(mesh.verts[c]));}}- if 0.5 * area_vec.len() < 1e-12 {+ let f_area = 0.5 * area_vec.len();+ surface_area += f_area;+ if f_area < 1e-12 {degenerate_faces += 1;}} else {@@ -184,6 +189,7 @@ impl MeshInvariants {components,signed_volume,volume: signed_volume.abs(),+ surface_area,bbox_min: bmin,bbox_max: bmax,size: sz,@@ -191,12 +197,24 @@ impl MeshInvariants {}}+ /// Scale-invariant check for zero or collapsed/pancake volume (`mean thickness <= 1e-9 * bbox_diag`).+ pub fn has_negligible_volume(&self) -> bool {+ if !(self.signed_volume.is_finite() && self.signed_volume > 0.0) {+ return true;+ }+ let diag = (self.size[0] * self.size[0] + self.size[1] * self.size[1] + self.size[2] * self.size[2]).sqrt();+ if !(diag.is_finite() && diag > 0.0 && self.surface_area.is_finite() && self.surface_area > 0.0) {+ return true;+ }+ self.volume <= 1e-9 * self.surface_area * diag+ }+pub fn is_valid_solid(&self) -> bool {self.watertight&& self.consistent_winding&& self.non_manifold_edges == 0&& self.nan_verts == 0- && self.signed_volume > 1e-12+ && !self.has_negligible_volume()}pub fn summary_line(&self, name: &str) -> String {diff --git a/crates/forma-core/src/scene.rs b/crates/forma-core/src/scene.rsindex aa33a43..f2cf2cb 100644--- a/crates/forma-core/src/scene.rs+++ b/crates/forma-core/src/scene.rs@@ -263,10 +263,10 @@ impl Scene {),});}- if inv.signed_volume <= 1e-12 || inv.volume <= 1e-12 {+ if inv.has_negligible_volume() {return Err(SceneError::InvariantViolation {part: name,- reason: format!("zero or negative volume solid (vol={:.3e})", inv.signed_volume),+ reason: format!("zero or negligible volume solid (vol={:.3e})", inv.signed_volume),});}if inv.components > 1 && crate::boolean::has_overlapping_components(&mesh) {@@ -543,13 +543,20 @@ impl Scene {let mut all_manifold = true;for (name, mesh) in &self.parts {let inv = MeshInvariants::compute(mesh);- if !inv.watertight || !inv.consistent_winding || inv.non_manifold_edges > 0 || inv.nan_verts > 0 || inv.volume <= 1e-12 {+ if !inv.watertight || !inv.consistent_winding || inv.non_manifold_edges > 0 || inv.nan_verts > 0 || inv.has_negligible_volume() {all_manifold = false;warnings.push(format!("part '{name}' invalid solid (WT={} CW={} NM={} B={} vol={:.3e})",inv.watertight, inv.consistent_winding, inv.non_manifold_edges, inv.boundary_edges, inv.volume));}+ if inv.components > 1 && crate::boolean::has_overlapping_components(mesh) {+ all_manifold = false;+ warnings.push(format!(+ "part '{name}' has overlapping/self-intersecting shells ({} components; use union=true)",+ inv.components+ ));+ }if inv.degenerate_faces > 0 {warnings.push(format!("part '{name}' has {} micro-sliver faces", inv.degenerate_faces));}diff --git a/crates/forma-core/tests/kernel_tests.rs b/crates/forma-core/tests/kernel_tests.rsindex cbcb74e..4b512f8 100644--- a/crates/forma-core/tests/kernel_tests.rs+++ b/crates/forma-core/tests/kernel_tests.rs@@ -772,3 +772,89 @@ fn test_batch_hole_rows_8_to_20_holes_all_scales() {);}}++#[test]+fn test_issues_10_11_twisted_loft_shell_cut_and_scale_invariant_vol() {+ use std::f64::consts::PI;++ // 1. Scale-invariant negligible-volume check: tiny 1e-4 cube passes, giant pancake fails+ let mut s_vol = Scene::new();+ s_vol.strict_manifold = true;+ let tiny_inv = s_vol.add_box("tiny", 1e-4, 1e-4, 1e-4, Vec3::ZERO).unwrap();+ assert!(tiny_inv.is_valid_solid());+ let pancake = forma_core::primitives::make_box(1000.0, 1000.0, 1e-10, 1);+ assert!(MeshInvariants::compute(&pancake).has_negligible_volume());++ // 2. Twisted rounded-triangle loft from Issues #10 & #11+ let n = 48usize;+ let levels = [0.0_f64, 0.10, 0.20, 0.30];+ let make_ring = |r_base: f64, flip: bool| -> Vec<f64> {+ let phase = if flip { PI } else { 0.0 };+ (0..n)+ .map(|i| {+ let phi = 2.0 * PI * (i as f64) / (n as f64);+ r_base * (1.0 + 0.22 * (3.0 * (phi + phase)).cos())+ })+ .collect()+ };+ let build_sections = |r_base: f64, z0: f64, ztop: f64, sub: usize| -> Vec<(f64, Vec<(f64, f64)>)> {+ let ra = make_ring(r_base, false);+ let rb = make_ring(r_base, true);+ let mut raw: Vec<(f64, Vec<f64>)> = Vec::new();+ for l in 0..(levels.len() - 1) {+ for s in 0..sub {+ let f = (s as f64) / (sub as f64);+ let w = 0.5 - 0.5 * (PI * f).cos();+ let (a, b) = if l % 2 == 0 { (&ra, &rb) } else { (&rb, &ra) };+ let zl = (levels[l] + f * (levels[l + 1] - levels[l])).max(z0);+ let rs: Vec<f64> = (0..n).map(|i| a[i] * (1.0 - w) + b[i] * w).collect();+ raw.push((zl, rs));+ }+ }+ let last = if (levels.len() - 1) % 2 == 0 { ra } else { rb };+ raw.push((if ztop > levels[3] { ztop } else { levels[3] }, last));+ let mut dedup: Vec<(f64, Vec<f64>)> = Vec::new();+ for (z, r) in raw {+ if let Some(prev) = dedup.last_mut() {+ if (prev.0 - z).abs() < 1e-9 {+ *prev = (z, r);+ continue;+ }+ }+ dedup.push((z, r));+ }+ dedup+ .into_iter()+ .map(|(z, rs)| {+ let poly: Vec<(f64, f64)> = (0..n)+ .map(|i| {+ let phi = 2.0 * PI * (i as f64) / (n as f64);+ (rs[i] * phi.cos(), rs[i] * phi.sin())+ })+ .collect();+ (z, poly)+ })+ .collect()+ };++ // Issue #10: shell(0.01, open_top=true) and solidify on SUB=1, 2 twisted loft -> g=0+ for sub in [1usize, 2] {+ let outer = forma_core::primitives::make_loft(&build_sections(0.065, 0.0, 0.30, sub), n, 10).unwrap();+ let shelled = forma_core::ops::shell_solid(&outer, 0.01, true, 11).unwrap();+ let sh_inv = MeshInvariants::compute(&shelled);+ assert!(sh_inv.is_valid_solid() && sh_inv.genus == 0, "Issue #10 shell SUB={sub}: {sh_inv:?}");++ let solidified = forma_core::deform::solidify_mesh(&outer, 0.01, -1.0, true, 12).unwrap();+ let so_inv = MeshInvariants::compute(&solidified);+ assert!(so_inv.is_valid_solid() && so_inv.genus == 0, "Issue #10 solidify SUB={sub}: {so_inv:?}");+ }++ // Issue #11: outer_loft | cut(inner_loft) at SUB=7, 8 -> WT=ok NM=0 g=0+ for sub in [7usize, 8] {+ let outer = forma_core::primitives::make_loft(&build_sections(0.065, 0.0, 0.30, sub), n, 20).unwrap();+ let inner = forma_core::primitives::make_loft(&build_sections(0.055, 0.01, 0.32, sub), n, 21).unwrap();+ let cut = forma_core::boolean::boolean_op(&outer, &inner, BoolOp::Difference, None, 22).unwrap();+ let cinv = MeshInvariants::compute(&cut);+ assert!(cinv.is_valid_solid() && cinv.genus == 0, "Issue #11 loft cut SUB={sub}: {cinv:?}");+ }+}diff --git a/crates/forma-mcp/src/main.rs b/crates/forma-mcp/src/main.rsindex 1a07ad8..d42635a 100644--- a/crates/forma-mcp/src/main.rs+++ b/crates/forma-mcp/src/main.rs@@ -203,7 +203,7 @@ fn main() {"result": {"protocolVersion": "2024-11-05","capabilities": { "tools": {} },- "serverInfo": { "name": "forma-mcp", "version": "0.1.0" }+ "serverInfo": { "name": "forma-mcp", "version": "0.4.1" }}}),"ping" => json!({ "jsonrpc": "2.0", "id": id, "result": {} }),diff --git a/crates/forma-server/Cargo.toml b/crates/forma-server/Cargo.tomlindex b6bcf64..4fb7e92 100644--- a/crates/forma-server/Cargo.toml+++ b/crates/forma-server/Cargo.toml@@ -1,6 +1,6 @@[package]name = "forma-server"-version = "0.4.0"+version = "0.4.1"edition = "2021"license = "MIT"description = "Zero-dependency headless multi-threaded HTTP microservice for Forma 3D synthesis & runtime asset processing"diff --git a/crates/forma-server/src/main.rs b/crates/forma-server/src/main.rsindex 3014707..b92ba6d 100644--- a/crates/forma-server/src/main.rs+++ b/crates/forma-server/src/main.rs@@ -5,7 +5,7 @@//! asset processing (import .glb/.obj/.stl -> decimate/transform/boolean -> export).//!//! Endpoints:-//! GET /health -> {"status":"ok","version":"0.4.0","workers":N}+//! GET /health -> {"status":"ok","version":"0.4.1","workers":N}//! GET /spec[?gbnf=1] -> Forma-Pipe language spec or GBNF grammar//! POST /v1/eval -> Evaluate Forma-Pipe with optional base64 in-memory `assets`//! POST /v1/process -> Direct asset processor (import -> decimate/scale/center_z0 -> export)@@ -21,7 +21,7 @@ use std::sync::{mpsc, Arc, Mutex};use std::thread;use std::time::{Duration, Instant};-const VERSION: &str = "0.4.0";+const VERSION: &str = "0.4.1";const MAX_BODY_BYTES: usize = 16 * 1024 * 1024; // 16 MB request capstruct Config {diff --git a/crates/forma-wasm/Cargo.toml b/crates/forma-wasm/Cargo.tomlindex 4a986e6..ba187e4 100644--- a/crates/forma-wasm/Cargo.toml+++ b/crates/forma-wasm/Cargo.toml@@ -1,6 +1,6 @@[package]name = "forma-wasm"-version = "0.4.0"+version = "0.4.1"edition = "2021"license = "MIT"description = "Zero-dependency WebAssembly core for Forma (Node.js, Deno, Bun, and browsers)"diff --git a/llms.txt b/llms.txtindex b7d8c60..8533477 100644--- a/llms.txt+++ b/llms.txt@@ -1,6 +1,6 @@# Forma-> A 1.2 MB pure-Rust headless 3D polyhedral modeling engine built for AI agents — Unix CLI, WASM library, and minimal-schema MCP server. Single static binary, zero GPU required, strict watertight solid verification, ~16.9 ms cold-start eval + export.+> A ~1.7 MB native / ~0.8 MB WASM pure-Rust headless 3D polyhedral modeling engine built for AI agents — Unix CLI, WASM library, and minimal-schema MCP server. Single static binary, zero GPU required, strict watertight solid verification, ~16.9 ms cold-start eval + export.## Repository Map@@ -20,7 +20,7 @@## Quick Commands```bash-# Build release binaries (~1.2 MB each)+# Build release binaries (~1.7–1.8 MB stripped native)cargo build --release# Print the concise language spec (~355 tokens) or formal GBNF grammardiff --git a/package.json b/package.jsonindex 226bc9e..7da64e3 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "forma-3d",- "version": "0.4.0",- "description": "A 1.2 MB pure-Rust headless 3D polyhedral modeling engine built for AI agents — CLI, WASM library, and MCP server.",+ "version": "0.4.1",+ "description": "Lightweight pure-Rust headless 3D polyhedral modeling engine built for AI agents — CLI, ~0.8 MB WASM library, and MCP server.","license": "MIT","author": "wrong-nebula","type": "module",diff --git a/wasm/forma.wasm b/wasm/forma.wasmindex e052d19..ddad74b 100755Binary files a/wasm/forma.wasm and b/wasm/forma.wasm differ