A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server
docs: add CONTRIBUTING, ROADMAP, and contribute/ blueprints
wrong-nebulac8846a9d34b1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdnew file mode 100644index 0000000..41d798a--- /dev/null+++ b/CONTRIBUTING.md@@ -0,0 +1,117 @@+# Contributing to Forma++Thanks for your interest in contributing to **Forma**!++Forma is a pure-Rust, headless 3D polyhedral modeling engine built for AI agents — shipping as a ~1.7–1.8 MB native CLI, a ~0.8 MB WebAssembly library (`forma-3d`), and a compact stdio MCP server (`forma-mcp`).++If you are an AI agent working in this repository, also read [`AGENTS.md`](AGENTS.md) and [`SKILL.md`](SKILL.md).++---++## Quick Start: Build & Test++Prerequisites: Rust stable toolchain (`edition = "2021"`). For WASM builds: `rustup target add wasm32-unknown-unknown` and Node.js `>= 18`.++```bash+# Run core workspace unit, integration, and fuzz-invariant tests+cargo test++# Build release native binaries (forma, forma-mcp)+cargo build --release++# Build optional headless HTTP server (excluded from default-members)+cargo build --release -p forma-server++# Build WASM bundle and run npm smoke tests+npm run build:wasm+npm test+```++---++## Workspace Layout++```text+crates/+├── forma-core/ # Polyhedral mesh kernel, CSG booleans, bevel/shell/subsurf/remesh/QEM,+│ # UVs, spatial queries (clearance/section), zero-GPU renderer, import/export+├── forma-lang/ # Forma-Pipe & compact DSL parser/evaluator, transactional runner, GBNF spec+├── forma-cli/ # `forma` CLI binary (eval, render, draw, spec)+├── forma-mcp/ # `forma-mcp` stdio JSON-RPC 2.0 server (4 tools, <800 o200k tokens)+├── forma-wasm/ # WASM bindings powering the `forma-3d` npm package+└── forma-server/ # Opt-in headless HTTP/1.1 microservice (excluded from default-members)+```++Other key directories:+- [`grammar/`](grammar/) — GBNF grammar for constrained decoding (`forma_pipe.gbnf`).+- [`bin/`](bin/) & [`lib/`](lib/) — Node.js wrappers for `forma-3d` CLI, MCP, and ESM library.+- [`contribute/`](contribute/) — Forward-looking architectural blueprints, RFCs, and addon specs.+- [`docs/`](docs/) — Benchmark reports, architecture audits, and verification logs.++---++## Non-Negotiable Constraints++Forma's value comes from staying fast, tiny, deterministic, and strictly watertight. PRs must respect these constraints:++1. **Binary & WASM size budget:**+ - Core native `forma` binary stays around **~1.7–1.8 MB** (zero-dependency pure Rust; avoid heavy transitive crates).+ - Core `forma.wasm` stays around **~0.8 MB** (`--profile wasm-release`).+ - Heavy or domain-specific capabilities do **not** go into `default-members` — they ship as opt-in workspace crates (see [Core vs. Opt-In Crates](#core-vs-opt-in-crates)).+2. **MCP tool-schema budget (`< 800` `o200k` tokens):**+ - `forma-mcp` exposes 4 tools (`eval`, `inspect`, `tx`, `export`) currently totaling **789 `o200k` tokens**.+ - Do not inflate the core MCP tool schemas. Extended reference docs belong in lazy `inspect(topic=...)` or a separate opt-in MCP server (e.g., `forma-print --mcp`).+3. **Strict-by-default manifold invariants:**+ - `forma-cli` and `forma-mcp` default to `strict = true` (`--no-strict` / `strict: false` is explicit opt-out).+ - Under `strict`, every modified part must satisfy `WT=ok` (watertight), `CW=true` (consistent winding), `NM=0` (zero non-manifold edges), `B=0` (zero boundary edges), `NaN=0`, and non-negligible positive volume (scale-invariant check). Failed ops must roll back cleanly via transactional snapshots.+4. **Determinism & zero panics:**+ - Core ops must not panic or produce `NaN`s on adversarial inputs, and `.glb` export must remain deterministic.+ - Use `BTreeMap` / deterministic ordering rather than `HashMap` where output order is observable.+5. **Honest documentation:**+ - Never overclaim geometric capabilities (for example, `.step` export is a watertight planar-face ISO 10303-21 solid, not analytic NURBS).+6. **License:**+ - All contributions are licensed under `GPL-3.0-or-later` (see [`LICENSE`](LICENSE)).++---++## Core vs. Opt-In Crates (and Out-of-Scope Work)++| Tier | What Belongs Here | Impact on Core |+|---|---|---|+| **Core (`default-members`)** | Mesh kernel fixes, boolean/bevel/selector robustness, spatial queries, `Forma-Pipe` ergonomics, diagnostic/craftsmanship tooling, WASM/CLI/MCP parity | Must stay within native/WASM size & `<800`-token MCP budgets |+| **Opt-In Workspace Crates** | Domain-specific workflows built on `forma-core` (e.g. `forma-server`, [`forma-print`](contribute/forma-print.md), [`forma-ue`](contribute/forma-ue.md), [`forma-retopo`](contribute/retopo.md)) | Listed in `workspace.members`, **excluded** from `default-members` → `0 bytes` on core/WASM and `0 tokens` on core `forma-mcp` |+| **Separate Companion Apps / Addons** | Rigging/armatures, skinning, shape keys/morph targets, animation retargeting, high-to-low map baking, and full PBR/EEVEE-class headless rendering | Out of scope for core `forma`; planned as separate companion tooling that consumes Forma's `.glb`/mesh output |++---++## Design Review Before Large Changes++Before opening a multi-PR series or introducing a new surface (a `Forma-Pipe` op, a new file format, a new opt-in crate, or an MCP change):++1. Check [`ROADMAP.md`](ROADMAP.md) and [`contribute/`](contribute/README.md) to see if a blueprint already exists.+2. Open a GitHub Issue (or a short RFC markdown PR in `contribute/`) describing:+ - What problem it solves and whether it lives in core or an opt-in crate.+ - Public syntax / CLI / API shape and expected binary-size & token-budget impact.+ - Test and invariant verification plan.+3. Wait for maintainer sign-off on the design before sending implementation PRs. This avoids wasted work and keeps the codebase cohesive.++---++## Pull Request Checklist++- [ ] `cargo test` passes with zero warnings on touched crates.+- [ ] New geometric ops include unit/invariant tests in `crates/forma-core/tests/` verifying `WT=ok`, `NM=0`, `B=0`, and strict rollback behavior.+- [ ] Any `Forma-Pipe` syntax change updates `SPEC_PIPE`, `grammar/forma_pipe.gbnf`, `SKILL.md`, and `AGENTS.md` as appropriate.+- [ ] Core binary size, WASM size, and `forma-mcp` token budget are not regressed (run `npm run build:wasm && npm test` if touching core/lang/wasm).+- [ ] PR is focused on a single concern with a clear description and reproduction/verification notes.++---++## Where Help Is Wanted Most++See [`ROADMAP.md`](ROADMAP.md) and [`contribute/README.md`](contribute/README.md) for active blueprints and open items, especially:++- **Kernel & geometry hardening:** curved-tool boolean edge cases, bevel clamping, and fuzz-invariant coverage.+- **Craftsmanship & agent ergonomics:** deterministic geometric critic (`--critique`), declarative `assert` spatial contracts, `def` macros, and cutaway/wireframe preview modes ([`contribute/craftsmanship.md`](contribute/craftsmanship.md)).+- **Opt-in 3D printing addon (`forma-print`):** DFM checks, auto-orientation, multi-color AMS/MMU `.3mf` export ([`contribute/forma-print.md`](contribute/forma-print.md)).+- **Opt-in Unreal Engine / OpenUSD addon (`forma-ue`):** `UCX_`/`UBX_` collision hulls, lightmap UV2, LOD chains, pure-Rust `.usda` export ([`contribute/forma-ue.md`](contribute/forma-ue.md)).diff --git a/README.md b/README.mdindex fd28cc5..faf1d60 100644--- a/README.md+++ b/README.md@@ -167,6 +167,16 @@ Full logs and methodology: [`docs/EXTENDED_BENCHMARK_REPORT.md`](docs/EXTENDED_B---+## Contributing & Roadmap++Contributions are welcome! Start here:++- **Contributor Guide:** [`CONTRIBUTING.md`](CONTRIBUTING.md) — build/test commands, crate layout, non-negotiable binary/token/manifold budgets, and design-review process.+- **Public Roadmap:** [`ROADMAP.md`](ROADMAP.md) — what works today, planned core improvements, opt-in zero-bloat addons, and companion-app boundaries.+- **Blueprints & RFCs:** [`contribute/`](contribute/README.md) — detailed specs for [`forma-print`](contribute/forma-print.md) (3D printing DFM & multi-color `.3mf`), [`forma-ue`](contribute/forma-ue.md) (UE5 / OpenUSD), [`craftsmanship`](contribute/craftsmanship.md), and [`retopo`](contribute/retopo.md).++---+## LicenseGNU General Public License v3.0 or later (`GPL-3.0-or-later`) — see [`LICENSE`](LICENSE).diff --git a/ROADMAP.md b/ROADMAP.mdnew file mode 100644index 0000000..4644be4--- /dev/null+++ b/ROADMAP.md@@ -0,0 +1,49 @@+# Forma Roadmap++This roadmap tracks what works today in **Forma**, what is actively planned next, and where opt-in addons or separate companion apps fit into the ecosystem.++Looking to pick up a piece of work? Read [`CONTRIBUTING.md`](CONTRIBUTING.md) and browse the detailed blueprints in [`contribute/`](contribute/README.md).++---++## What Works Today (`v0.4.2`)++- **Core Polyhedral Kernel (`forma-core`):** Double-precision watertight manifold mesh kernel, BVH-localized booleans with automatic multi-hole batching, ring-preserving bevels, shell/solidify, crease-aware Catmull-Clark `subsurf`, Surface Nets voxel `remesh`, Link-Condition QEM `decimate`, `pipe`, `loft`, `sweep`, helical `thread`, `text3d`, and `pattern_linear`/`pattern_radial`.+- **Declarative Language (`forma-lang`):** `Forma-Pipe` with semantic selectors (`vertical`, `top_rim`, `bottom_rim`, `outer_rim`, `top`, `sides`), relational placement (`on`, `align`), exact `clearance()` and `section()` queries, transactional snapshots, and GBNF grammar for constrained decoding.+- **Strict-by-Default Validation:** `forma-cli` and `forma-mcp` default to `strict = true`, rejecting non-manifold, open-boundary, inconsistent-winding, `NaN`, or negligible-volume geometry and rolling back cleanly.+- **Zero-GPU Rendering & Blueprints:** Built-in 4-view (`Front / Right / Top / Iso`) studio PNG renderer (~4 ms) and dimensioned vector SVG blueprints (`forma draw`).+- **Import & Export:** Pure-Rust `.glb` (glTF 2.0 Y-up, PBR + LSCM/triplanar UVs), `.obj`, and `.stl` import; `.glb`, faceted ISO 10303-21 `.step`, `.3mf`, `.stl`, `.obj`, `.svg`, `.png`, and optional `.blend` export.+- **Distribution:** ~1.7–1.8 MB native CLI/MCP binaries, ~0.8 MB WASM npm package (`forma-3d`), and opt-in headless HTTP worker (`forma-server`).++---++## Planned — Core Engine++| Area | Goals | Blueprint / Details |+|---|---|---|+| **Kernel & Fuzz Hardening** | Expand `fuzz_invariants.rs` with curved tools (`cyl`/`cone`/`sphere`/`revolve`), tighten bevel XY clamping, add BVH self-intersection diagnostics, and surface actionable grazing-boolean hints. | Core (`forma-core`) |+| **Craftsmanship & Agent Piloting** | Deterministic geometric critic (`--critique`), declarative `assert` spatial contracts, pure parametric `def` macros + lazy stdlib (`inspect(topic="stdlib")`), and renderer `section`/`wire`/`scale` modes. | [`contribute/craftsmanship.md`](contribute/craftsmanship.md) |+| **Plugin CLI Dispatch** | Lightweight Git-style subcommand forwarding (`forma <addon> ...` → `forma-<addon>` on `$PATH`) so opt-in crates integrate seamlessly at `< 1 KB` core cost. | Shared across addons |++---++## Planned — Opt-In Workspace Addons (Zero Bloat on Core)++Opt-in addons live in `workspace.members` but stay excluded from `default-members`, adding **0 bytes** to core `forma`/`forma.wasm` and **0 tokens** to core `forma-mcp`.++| Addon Crate | Scope | Status | Blueprint |+|---|---|---|---|+| `forma-print` | 3D printing DFM audit (16+ FDM/SLA/SLS printer profiles), visual DFM heatmaps, auto-orientation, slicer-native multi-color AMS/MMU `.3mf` export, part splitting & plate nesting, optional slicer CLI / LAN bridges. | Blueprint ready — help wanted | [`contribute/forma-print.md`](contribute/forma-print.md) |+| `forma-ue` | Unreal Engine 5 pipeline: `UCX_`/`UBX_` QuickHull collision hulls, lightmap UV2 (`TEXCOORD_1`), auto `LOD0`–`LOD3`, pure-Rust `.usda` (OpenUSD) exporter, `SM_` hygiene. | Blueprint ready — help wanted | [`contribute/forma-ue.md`](contribute/forma-ue.md) |+| `forma-retopo` | Curvature/field-aligned quad retopology (Instant Meshes–style extrinsic 4-RoSy solver) for organic scan/sculpt cleanup without risking core watertight stability. | Feasibility note — deferred | [`contribute/retopo.md`](contribute/retopo.md) |++---++## Ecosystem / Separate Companion Apps (Out of Core Scope)++To keep Forma's modeling kernel lean, fast, and strictly watertight, the following areas are intentionally **outside core `forma`** and planned as separate companion apps or external addons that consume Forma's `.glb` / mesh exports:++- **Headless PBR / EEVEE-Class Renderer:** A dedicated headless rendering companion app inspired by Blender's renderer and EEVEE, built with the same agent-first philosophy as Forma (while Forma's built-in renderer stays a tiny, zero-GPU diagnostic previewer).+- **Character Rigging, Animation & Map Baking:** Armatures/skeletons, skin weights, shape keys (morph targets), animation clip retargeting, and high-to-low normal/roughness baking.++If you want to collaborate on a companion crate or interoperability contract (e.g., clean `.glb` handoff conventions between Forma and downstream rigging/rendering tools), open an issue to discuss!diff --git a/contribute/README.md b/contribute/README.mdnew file mode 100644index 0000000..749ba0c--- /dev/null+++ b/contribute/README.md@@ -0,0 +1,22 @@+# Forma Contributor Blueprints & RFCs++This folder contains forward-looking architectural blueprints, design notes, and feasibility studies for features and opt-in addons planned around **Forma**.++Before starting work on any blueprint here, please read [`CONTRIBUTING.md`](../CONTRIBUTING.md) and [`ROADMAP.md`](../ROADMAP.md), then open a GitHub Issue (or small design-review PR) to align on scope before submitting large implementation PRs.++## Active Blueprints++| Document | Target | Status | Summary |+|---|---|---|---|+| [`forma-print.md`](forma-print.md) | Opt-in crate (`crates/forma-print`) | Blueprint / Help Wanted | 3D printing DFM engine (16+ FDM/SLA/SLS profiles), visual heatmaps, auto-orientation, slicer-native multi-color AMS/MMU `.3mf`, splitting & nesting, optional slicer CLI / LAN bridges. |+| [`forma-ue.md`](forma-ue.md) | Opt-in crate (`crates/forma-ue`) | Blueprint / Help Wanted | Unreal Engine 5 export addon: `UCX_`/`UBX_` QuickHull collision hulls, lightmap UV2 (`TEXCOORD_1`), auto `LOD0`–`LOD3`, pure-Rust `.usda` (OpenUSD) exporter. |+| [`craftsmanship.md`](craftsmanship.md) | Core (`forma-core` / `forma-lang`) | Blueprint / Help Wanted | Deterministic geometric critic (`--critique`), declarative `assert` spatial contracts, `def` macros + lazy stdlib, cutaway/wireframe preview modes, grazing-boolean diagnostics. |+| [`retopo.md`](retopo.md) | Opt-in crate (`crates/forma-retopo`) | Feasibility Note / Deferred | Curvature/field-aligned quad retopology (Instant Meshes–style 4-RoSy solver) as an optional addon without risking core watertight invariants. |++## Adding a New Proposal++If you want to propose a major feature or a new opt-in crate:++1. Copy the header metadata pattern used in the blueprints above (`Status`, `Target`, `Core Impact`, `Design Review`).+2. Explicitly state binary-size / WASM / MCP token impact and how strict manifold invariants (`WT=ok NM=0 B=0`) are preserved.+3. Open a PR adding your proposal to `contribute/` or start a GitHub Issue linking to your draft.diff --git a/contribute/craftsmanship.md b/contribute/craftsmanship.mdnew file mode 100644index 0000000..d8d60bc--- /dev/null+++ b/contribute/craftsmanship.md@@ -0,0 +1,43 @@+# Core Craftsmanship & Agent Piloting Blueprint++- **Status:** Blueprint / Help Wanted (not yet implemented)+- **Target:** Core (`forma-core` & `forma-lang`)+- **Core Impact:** Strictly zero ML weights, `< 5 ms` deterministic checks, `0` extra base tokens on `forma-mcp`+- **Design Review:** Required per feature PR (see [`CONTRIBUTING.md`](../CONTRIBUTING.md))++---++## Architectural Principle++Do **not** bundle a local neural critique model into core `forma` — that would destroy the ~1.7–1.8 MB native / ~0.8 MB WASM / zero-GPU footprint while still having weaker 3D spatial judgment than the host frontier model.++Instead, split quality feedback into:+- **Layer A (Deterministic, inside `forma-core`, 0 KB weights, `< 5 ms`):** Fast geometric linting, spatial assertions, and cutaway/wireframe diagnostic views.+- **Layer B (Host VLM visual loop):** The calling agent inspects the 4-view render and deterministic lint notes to refine geometry.++---++## Prioritized Craftsmanship Features++1. **Deterministic Geometric Craftsmanship Critic (`forma lint` / `--critique`, `invariants.rs`):**+ - Emits zero tokens on clean builds.+ - Flags unintended floating shells, grazing contacts (`0 <= clearance < 1e-3`), thin walls via inward BVH rays, center-of-mass stability/tipping overhang, and an opt-in "un-beveled raw 90° box" lint.++2. **Declarative Spatial Assertions (`assert` in `Forma-Pipe`):**+ - 1-line engineering contracts that auto-rollback with exact deltas on failure:+ ```text+ assert clearance(shaft, bore) >= 0.005+ assert connected(assembly)+ assert grounded(base, z=0)+ assert section_loops(flange, z=0) == 6+ ```++3. **Pure Parametric Macros (`def`) + Lazy Industrial-Design Stdlib (`inspect(topic="stdlib")`):**+ - Reusable sub-assemblies (`def standoff(r_out, r_in, h) = ...`).+ - On-demand high-craft detail recipes (counterbored bosses, gusset ribs, snap-fit lips, flanged collars, Gothic arches) loaded lazily via `inspect(topic=...)` at **0 base-schema tokens**.++4. **Visual-Critique Renderer Modes (`render.rs`):**+ - `mode="section|wire|scale"` — mid-plane cutaways (exposing internal walls and clearances), clay+wireframe overlays, and orthographic ruler ticks for a tight 2-pass visual refinement loop.++5. **Actionable Grazing-Boolean Diagnostics (`boolean.rs`):**+ - Pinpoint the exact offending edge centroid `(x, y, z)` and suggest a concrete overlap/extension fix whenever `--strict` rolls back a grazing coplanar boolean.diff --git a/contribute/forma-print.md b/contribute/forma-print.mdnew file mode 100644index 0000000..dc9648d--- /dev/null+++ b/contribute/forma-print.md@@ -0,0 +1,134 @@+# `forma-print`: Optional 3D Printing Addon Blueprint++- **Status:** Blueprint / Help Wanted (not yet implemented)+- **Target:** Opt-in workspace crate (`crates/forma-print`, excluded from `default-members`)+- **Core Impact:** `0 bytes` on core `forma` / `forma.wasm`, `0 tokens` on core `forma-mcp`+- **Design Review:** Required before multi-PR implementation (see [`CONTRIBUTING.md`](../CONTRIBUTING.md))++> [!IMPORTANT]+> **Zero-Bloat Guarantee:** `crates/forma-print` sits in `workspace.members` but is excluded from `default-members` (the exact same pattern as `forma-server`). When not installed/enabled, it adds **`0 bytes`** to core `forma` / `forma-mcp` / `forma.wasm` and **`0 tokens`** to `forma-mcp`'s `<800`-token schema.++---++## 1. 3D Printer Hardware Matrix & Printability Physics++### 1.1 Built-In Verified Printer Profiles (`profiles.rs`)++| Printer Profile ID | Tech | Kinematics | Build Volume X × Y × Z (mm) | Nozzle / XY Res | Multi-Material & Special Notes |+|---|---|---|---|---|---|+| `bambu_a1_mini` | FDM | Bedslinger | `180 × 180 × 180` | 0.2 / **0.4** / 0.6 / 0.8 mm | AMS Lite (4 slots); bedslinger Y-inertia favors low-Z |+| `bambu_a1` | FDM | Bedslinger | `256 × 256 × 256` | 0.2 / **0.4** / 0.6 / 0.8 mm | AMS Lite (4 slots) |+| `bambu_p1s` | FDM | CoreXY (enclosed) | `256 × 256 × 256` | 0.2 / **0.4** / 0.6 / 0.8 mm | AMS up to 16 slots; front-left cutter exclusion (~18 × 28 mm) |+| `bambu_x1c` | FDM | CoreXY (enclosed) | `256 × 256 × 256` | 0.2 / **0.4** / 0.6 / 0.8 mm | Hardened steel, LiDAR, AMS up to 16 slots; ABS/ASA/PA-CF |+| `bambu_h2d_single` | FDM | Dual-Nozzle CoreXY | `325 × 320 × 325` | 0.2–0.8 mm | Single-nozzle zone (total physical bed `350 × 320 × 325`) |+| `bambu_h2d_dual` | FDM | Dual-Nozzle CoreXY | `300 × 320 × 320` | 0.2–0.8 mm | Dual-nozzle overlap zone (dissimilar support interfaces, ~0 purge) |+| `prusa_mk4s` | FDM | Bedslinger | `250 × 210 × 220` | 0.25–0.8 mm (**0.4 HF**) | 360° high-flow cooling (strong overhangs up to ~55°), MMU3 (5 slots) |+| `prusa_core_one` | FDM | CoreXY (enclosed) | `250 × 220 × 270` | 0.25–0.8 mm (**0.4 HF**) | Active chamber temp control, MMU3 |+| `prusa_xl` | FDM | CoreXY Toolchanger | `360 × 360 × 360` | 0.25–0.8 mm | 1–5 independent toolheads (near-zero purge, TPU+PLA) |+| `voron_24_250/300/350` | FDM | Flying-Gantry CoreXY | `250³` / `300³` / `350³` | 0.4 / 0.6 mm | Klipper/Moonraker native; ABS/ASA; optional ERCF/BoxTurtle |+| `creality_k1c` | FDM | CoreXY (enclosed) | `220 × 220 × 250` | **0.4 mm** hardened | CF-ready, Klipper-based |+| `creality_k2_plus` | FDM | CoreXY (enclosed) | `350 × 350 × 350` | 0.4–0.8 mm | CFS multi-color (up to 16 slots), actively heated chamber |+| `elegoo_mars_5_ultra` | MSLA | Tilt-Release LCD | `153.36 × 77.76 × 165` | `18 × 18 µm` (9K) | Tilt-vat; drain holes & suction checks critical |+| `elegoo_saturn_4_ultra` | MSLA | Tilt-Release LCD | `218.88 × 122.88 × 220` | `19 × 24 µm` (12K) | Tilt-vat; brittle unsupported walls < 1.0 mm |+| `formlabs_form_4` | MSLA (LFD) | Masked SLA | `200 × 125 × 210` | `50 µm` XY | Engineering resins; 0.5 mm supported / 1.0 mm unsupported walls |+| `formlabs_fuse_1p` | SLS | Laser Powder Bed | `165 × 165 × 300` | `~110 µm` laser | Zero supports; requires powder escape holes & ≥0.5 mm clearance |++> [!NOTE]+> **Critical Unit Bridge (`meters` → `millimeters`):** Core Forma uses Z-up **meters** (`3MF` writes `unit="meter"`, `STEP` writes `SI_UNIT($,.METRE.)`), whereas slicers expect **millimeters**. `forma-print` should expose `--unit m|mm|auto` / `--scale`, emitting `unit="millimeter"` in `.3mf` and `SI_UNIT(.MILLI.,.METRE.)` in `.step`.++### 1.2 Printability Physics & Pure-Rust Detection Math++| Constraint | FDM (`0.4 mm` Nozzle) | SLA / MSLA Resin | SLS (PA12) | Detection Algorithm in `forma-print` |+|---|---|---|---|---|+| **Min Wall Thickness** | `≥ 0.84 mm` (2 lines); functional `≥ 1.6 mm` | `≥ 0.5 mm` supported / `≥ 1.0 mm` unsupported | `≥ 0.7–1.0 mm` | Inward BVH raycast along `-n_f` (+ 4 tilted cone rays ±12°) from face centroids; flag `t_min < min_wall`. |+| **Overhang Angle** | **45°** (`n.z < -0.7071`; MK4S/X1C ~55°) | **30°** (`n.z < -0.866`) | None (powder bed) | Exclude bed faces (`z <= z_min + layer_h`); flag downward faces exceeding angle limit (excluding short bridges). |+| **Floating Islands (Z-Minima)** | Fatal without supports | **Catastrophic** (cured flake tears FEP/LCD) | N/A | Vertex-adjacency local Z-minima above `z_min` + `spatial::section_z` slice-to-slice XY overlap check (new loop with 0 overlap below = floating island). |+| **Bridge Spans** | Safe `≤ 10–25 mm` (PLA/PETG), `≤ 8–12 mm` (ABS) | Poor (`≤ 2–3 mm`) | Unlimited | Horizontal downward planar clusters (`n.z < -0.98`, `z > z_min + layer_h`): classify supported vs open boundary edges and span width. |+| **XY Clearances & Shrinkage** | Tight `0.15 mm`, snug `0.20 mm`, sliding/PIP `0.30–0.40 mm` | Tight `0.10 mm`, sliding `0.20–0.30 mm` | `≥ 0.50 mm` (powder clearing) | `forma_core::spatial::clearance(a, b)` on scene part pairs; flag fusing gaps `< min_clearance` or intersections. |+| **Bed Adhesion & Tipping** | Elephant's foot `0.15–0.30 mm`; warn if contact `< 100 mm²` or `H / width > 4` | Usually angled 30–45° on raft | N/A | Bed-face area sum + 2D convex hull of bed footprint + divergence-theorem Center of Mass `(com.x, com.y)` inside-hull check. |+| **SLA Suction Cups & Traps** | N/A | Vacuum tears layers / trapped liquid resin cracks part; needs ≥2 holes `Ø ≥ 3.5 mm` | Trapped powder; needs ≥2 holes `Ø ≥ 5.0 mm` | Track CW inner hole loops across `section_z` slices: closed-top downward-open cavity = **suction cup**; enclosed negative shell = **trapped cavity**. |+| **AMS / MMU Swap Waste** | `~0.4–1.5 g` purge + `~45–90 s` per swap on single-nozzle AMS/MMU | Single vat | Single bed | Count unique `mat_id` transitions per Z-layer band; estimate purge grams and recommend orientation minimizing color-change layers. |++---++## 2. Slicers, Multi-Color `.3mf` Internals & Hardware Standards++### 2.1 Slicers & Local Printer APIs++- **OrcaSlicer / Bambu Studio:** Headless CLI (`orca-slicer --slice 0 --load-settings ... --export-3mf out.gcode.3mf model.3mf`, `--pipe` for JSON progress); native `.step` and Bambu-dialect multi-extruder `.3mf`.+- **PrusaSlicer:** Headless CLI (`prusa-slicer --export-gcode --load config.ini --output out.gcode model.3mf`); native `.step` and `Metadata/Slic3r_PE_model.config`.+- **CuraEngine:** Headless C++ CLI engine (`CuraEngine slice -j machine.def.json -o out.gcode -l model.stl`).+- **MSLA Resin:** Chitubox / Lychee (GUI-first) + **UVtools** open-source CLI for `.ctb`/`.goo`/`.sl1s` inspection.+- **LAN Printer APIs:** Klipper / **Moonraker** (`POST /server/files/upload` pure-Rust HTTP/1.1 multipart) & **OctoPrint** (`POST /api/files/local`). *(Bambu Lab LAN FTPS/MQTTS requires **LAN-Only + Developer Mode** on current firmware.)*++### 2.2 Slicer-Native Multi-Color `.3mf` Layout (AMS / MMU Pre-Assigned)++```text+model.3mf (ZIP + pure-Rust RFC-1951 Deflate, 5-8x smaller than stored ZIP)+├── [Content_Types].xml+├── _rels/.rels # Points to /3D/3dmodel.model + /Metadata/plate_1.png+├── 3D/3dmodel.model # unit="millimeter", <basematerials>, <m:colorgroup>, component sub-meshes per mat_id+└── Metadata/+ ├── model_settings.config # Bambu Studio / OrcaSlicer per-part 1-indexed `extruder` + `modifier_part`+ ├── project_settings.config # JSON `filament_colour[]` & `filament_type[]` from Forma `mat()`+ ├── plate_1.json # Build plate bbox & slot map (plate_2.json... for multi-plate!)+ ├── Slic3r_PE_model.config # PrusaSlicer XL / MMU3 per-volume `extruder` mapping+ └── plate_1.png # 256×256 preview thumbnail via `forma_core::render`+```++Dragging a `forma-print`-exported `.3mf` into **Bambu Studio, OrcaSlicer, or PrusaSlicer** automatically pre-populates AMS/MMU filament slots with the colors from Forma's `mat()` calls — and supports tagging parts as `subtype="modifier_part"` (e.g. local 100% infill around bolt bosses).++### 2.3 Verified CNC Kitchen / Voron Heat-Set Insert Table++| Spec ID | Insert OD × L (mm) | CAD Pilot Ø (mm) | Blind Depth (mm) | Min Boss OD (mm) | Lead-in Chamfer |+|---|---|---|---|---|---|+| `M2` | `3.2 × 3.0` | `3.2` | `4.0` | `6.4` | `0.4 mm × 45°` |+| `M2.5` | `3.6 × 4.0` | `3.6` | `5.0` | `7.2` | `0.4 mm × 45°` |+| `M3_voron` | `5.0 × 4.0` | `4.0` | `5.0` | `8.5` | `0.5 mm × 45°` |+| `M3_std` | `4.6 × 5.7` | `4.0` | `6.7` | `8.5` | `0.5 mm × 45°` |+| `M4` | `6.3 × 8.1` | `5.6` | `9.1` | `11.0` | `0.6 mm × 45°` |+| `M5` | `7.5 × 9.5` | `6.4` | `10.5` | `13.0` | `0.7 mm × 45°` |++---++## 3. Zero-Bloat Addon Architecture++```mermaid+flowchart LR+ Core["forma-core + forma-lang\n(unchanged core crates)"] --> CLI["forma (~1.7 MB)\nGit-style dispatch: forma print ..."]+ Core --> MCP["forma-mcp (<800 tok)\n0 extra tokens"]+ Core --> WASM["forma-3d (~0.8 MB WASM)\n0 extra bytes"]+ Core -. "opt-in crate\n(excluded from default-members)" .-> Print["forma-print (standalone binary)\nCLI + --mcp (~380 tok) + --features print"]+ Print -. "optional npm" .-> PrintWasm["@forma-3d/print\nBrowser WASM 3MF + DFM"]+```++### Five Clean Integration Surfaces++1. **Standalone Binary (`forma-print`):** `forma-print check|orient|pack|split|export ...` (accepts `.forma`, `.glb`, `.stl`, `.obj`, or stdin).+2. **Git-Style CLI Dispatch (`forma print ...`):** ~25 LOC in `forma-cli` / `bin/forma.mjs` forwards `forma <subcmd>` to `forma-<subcmd>` on `$PATH` (`< 1 KB` core impact, `0` new deps).+3. **Opt-In MCP Server (`forma-print --mcp`):** Registered separately *only* for 3D printing workflows — 4 composable tools (`print_check`, `print_prep`, `print_export`, `print_profiles`) at **`~380 o200k` tokens** (`0` tokens on core `forma-mcp`).+4. **Optional npm WASM (`@forma-3d/print`):** Client-side parametric `.3mf` + instant DFM heatmaps (~90–130 KB delta over core).+5. **Optional Cargo Feature (`--features print`):** Embeds `forma print` into `forma-cli` or `/v1/print/*` routes into `forma-server` on demand.++---++## 4. Three-Tier Implementation Roadmap++### Tier 1 — MVP (~2k LOC, 0 new crates, ~160–220 KB delta)+- **`profiles.rs`:** 16+ verified FDM/SLA/SLS printer & filament profiles.+- **`bvh.rs` + `dfm.rs`:** Pure-Rust DFM audit (`~8–25 ms` on 10k tris): watertight/manifold, build-volume fit, overhangs, floating islands, bridge vs. unsupported ceilings, BVH inward raycast min wall thickness, bed-adhesion/CoM stability, multi-part clearance, AMS swap count, material mass/time estimate.+- **`heatmap.rs`:** Color-coded 4-view diagnostic PNG (`< 4 ms`) by assigning a 5-slot DFM severity palette to `face.mat_id` and calling `forma_core::render::render_quad_png_bytes` directly (no duplicate renderer).+- **`orient.rs`:** Auto-orientation solver testing planar face clusters + convex-hull facets against weighted `(overhangs, islands, support_vol, bed_area, z_height, ams_swaps)` in `~15–40 ms`.+- **`export_3mf.rs`:** Pure-Rust Deflate-compressed `unit="millimeter"` 3MF with `<basematerials>`, `<m:colorgroup>`, Bambu/Orca `Metadata/model_settings.config` + `project_settings.config`, Prusa `Slic3r_PE_model.config`, embedded `256×256` thumbnail, plus mm-scaled `.step`.++### Tier 2 — Print-Native CAD, Splitting & Plate Nesting (~2.8k LOC, 0 new crates)+- **SLA Suction-Cup & Trapped-Cavity Detector:** Slice-graph tracking of CW inner loops across `section_z` + enclosed negative shells (`~20–60 ms`), plus **auto-hollow + lowest-Z drain & top vent holes** (`solidify_mesh` + boolean plugs).+- **Multi-Part & Multi-Plate 2D Nesting (`nest.rs`):** Reuses `uv.rs`'s convex-hull rotating calipers + MaxRects packer (`< 10 ms` for 50 parts), including purge-tower exclusion zones and automatic multi-plate spillover (`plate_1.json`, `plate_2.json`, ...).+- **Auto-Split Oversized Parts (`split.rs`):** Minimum-cross-section `bisect_mesh` + interlocking **15° dovetail** or **clearance-compensated alignment pin/socket** boolean joints.+- **Print-Native Ops (`ops_print.rs`):** `teardrop()` horizontal holes, `counterbore_bridged()` sacrificial 1-layer ceilings, `heat_insert()` (M2–M5 CNC Kitchen/Voron specs), `thread_printable()` (45° flanks + clearance), `elephant_chamfer()`, `brim_ears()`, `snap_fit()`, and `modifier_part` tagging.+- **`@forma-3d/print` WASM package.**++### Tier 3 — Slicer CLI Bridge & LAN Fleet Dispatch (opt-in features)+- **`slicer.rs` (`slicer-cli` feature, 0 extra crates):** Auto-discovers local `orca-slicer`, `BambuStudio`, `prusa-slicer`, or `CuraEngine` via `std::process::Command` to return **exact sliced print time, per-slot AMS grams, purge grams, and layer count**.+- **`printer_api.rs` (`net-lan` feature, off by default):** Pure-Rust HTTP/1.1 upload & status polling for **Klipper/Moonraker** and **OctoPrint** (plus documented Bambu LAN Developer Mode option).+- **Closed-Loop Agent Print Workflow:** `forma eval` → `print_check` (visual heatmap + metrics) → `print_prep` (`orient`, `elephant_chamfer`, `split`) → `print_export` (AMS-ready `.3mf`) → optional headless slicer verification.diff --git a/contribute/forma-ue.md b/contribute/forma-ue.mdnew file mode 100644index 0000000..ea3aa6a--- /dev/null+++ b/contribute/forma-ue.md@@ -0,0 +1,38 @@+# `forma-ue`: Optional Unreal Engine 5 & OpenUSD Addon Blueprint++- **Status:** Blueprint / Help Wanted (not yet implemented)+- **Target:** Opt-in workspace crate (`crates/forma-ue`, excluded from `default-members`)+- **Core Impact:** `0 bytes` on core `forma` / `forma.wasm`, `0 tokens` on core `forma-mcp`+- **Design Review:** Required before multi-PR implementation (see [`CONTRIBUTING.md`](../CONTRIBUTING.md))++---++## 1. What Works Today Out of the Box (`v0.4.2`)++- **Spec-Compliant `.glb` (glTF 2.0 Y-Up) into UE5 Interchange:** Named `pbrMetallicRoughness` material slots (`baseColorFactor`, `metallicFactor`, `roughnessFactor`) and per-face material assignment.+- **Clean Shading Normals:** `smooth(angle=35, weighted=true)` computes area/angle-weighted auto-smooth normals with welded vertices.+- **Game-Ready `TEXCOORD_0` UVs:** Pure-Rust LSCM conformal unwrapping + uniform texel density + non-overlapping `[0, 1]^2` atlas packing (`76.32%` Tier-1 / `75.66%` 12-mesh mean utilization, `1.0038` stretch, `0` inversions).+- **Multi-Object Named Scene Graphs:** `--scene` / `scene: true` preserves named parts as separate glTF nodes with shared `Arc<PolyMesh>` buffer instancing.+- **Watertight LOD Decimation:** Link-Condition QEM `decimate(ratio=...)`.++---++## 2. Current Gaps vs. a Dedicated UE5 Static-Mesh Pipeline++- No `.usda`/`.usd` (OpenUSD) or `.fbx` export yet.+- No automatic `UCX_` / `UBX_` collision hulls, no `TEXCOORD_1` lightmap UV2 channel, no auto-bundled `LOD0`–`LOD3` export, and no MikkTSpace-style vertex `TANGENT` attributes.+- Core Forma is static hard-surface modeling only — rigging, skeletal animation, and map baking are intentionally out of scope for core and planned for separate companion tooling.++---++## 3. Zero-Bloat `forma-ue` Addon Architecture++- **Workspace isolation:** `crates/forma-ue` listed in `workspace.members`, excluded from `default-members` (`0 bytes` & `0 tokens` impact on core `forma` / `forma-mcp` / `forma.wasm`).+- **Invocation:** Standalone `forma-ue` CLI, Git-style `forma ue ...` plugin dispatch, opt-in `forma-ue --mcp` (~250–350 tokens), optional `--features ue` flag (~50 KB delta, 0 new crates).+- **Core Capabilities:**+ 1. **UE-Native Scale & Scene Welding:** Centimeter scale (`1 m → 100 cm`) + vertex welding on multi-node scene exports for clean UE5 Interchange import.+ 2. **Auto Collision Hulls (`UCX_` / `UBX_`):** Pure-Rust 3D QuickHull per connected component/part emitted as sibling nodes matching UE's collision naming (`UCX_<Part>_00`, `UBX_<Part>_00`).+ 3. **Lightmap UV2 (`TEXCOORD_1`):** Second LSCM unwrap pass with wider bleed margin (`0.02–0.04`) written alongside `TEXCOORD_0`.+ 4. **Auto-LOD Chain (`LOD0`–`LOD3`):** Reuses Link-Condition QEM `decimate_mesh()` at configurable ratios (`1.0 / 0.5 / 0.25 / 0.12`).+ 5. **Zero-Dep Pure-Rust `.usda` (OpenUSD) Exporter (~250–350 LOC):** `upAxis = "Z"`, `metersPerUnit = 0.01`, `UsdGeomMesh`, `primvars:st` + `primvars:st1`, `UsdPreviewSurface`, `UsdGeomSubset`, and `UCX_` prims — native in UE5 Interchange/USD Stage with zero C++ FBX SDK bloat.+ 6. **Asset Hygiene:** Optional `SM_` naming, bottom-center/origin pivots, and MikkTSpace-style vertex `TANGENT` attributes.diff --git a/contribute/retopo.md b/contribute/retopo.mdnew file mode 100644index 0000000..1a1b324--- /dev/null+++ b/contribute/retopo.md@@ -0,0 +1,23 @@+# `forma-retopo`: Curvature-Aligned Quad Retopology Feasibility Note++- **Status:** Feasibility Note / Deferred+- **Target:** Opt-in workspace crate (`crates/forma-retopo`, excluded from `default-members`)+- **Core Impact:** `0 bytes` on core `forma` / `forma.wasm`, `0 tokens` on core `forma-mcp`+- **Design Review:** Required before implementation (see [`CONTRIBUTING.md`](../CONTRIBUTING.md))++---++## 1. What Exists in Core Today++- **Voxel Quad Remesh (`remesh(voxel_size=...)`, `remesh.rs`):** Pure-Rust Surface Nets voxel remesher emitting watertight, manifold **all-quad** meshes (`WT=ok NM=0`) in ~2–15 ms with Taubin smoothing and surface-normal volume calibration. Equivalent to Blender's Voxel Remesh — great for healing dirty imports, fusing overlapping solids, or establishing uniform quad density.+- **Catmull-Clark Quad Subdivision (`subsurf`)** with crease weights + watertight **Link-Condition QEM Decimation (`decimate`)**.+- **Not Supported Yet:** Curvature-aligned / edge-flow retopology (Blender's QuadriFlow, Instant Meshes, Exoside Quad Remesher) for organic deformation loops.++---++## 2. Feasibility of a Pure-Rust Field-Aligned Quad Remesher++- **Preferred algorithm:** **Instant Meshes** (Jakob et al. 2015 — local Gauss-Seidel relaxation of an extrinsic 4-RoSy orientation field + 4-way position field) fits Forma's zero-heavy-deps pure-Rust architecture far better than QuadriFlow's global min-cost network-flow integer optimization.+- **Estimated size:** ~1,500–2,500 LOC working (~2.5k–3.5k LOC hardened for strict `WT=ok NM=0`), ~40–90 KB compiled.+- **Primary engineering risk:** 70%+ of complexity sits in quad extraction (singularities, T-junctions, non-manifold pinches, and sharp-crease preservation).+- **Recommendation:** Keep out of `forma-core`; if demand for scan/sculpt edge-flow cleanup grows, build and test it as an **opt-in workspace crate (`crates/forma-retopo`)** without risking core watertightness or binary size.