forma
GitHub基于Rust的无头3D建模引擎,通过声明式管道语言快速生成水密多面体模型。支持机械零件、CAD生成及多种格式导出(GLB/STEP等),适用于AI代理进行3D网格设计与工程蓝图绘制。
触发场景
安装
npx skills add wrong-nebula/forma --skill forma -g -y
SKILL.md
Frontmatter
{
"name": "forma",
"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 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 Interface
Option A — MCP Server (preferred for iterative modeling)
Connect forma-mcp (native binary) or npx -y -p forma-3d forma-3d-mcp (zero-install WASM via npm):
{
"mcpServers": {
"forma": {
"command": "npx",
"args": ["-y", "-p", "forma-3d", "forma-3d-mcp"]
}
}
}
Exposed tools (4 tools, 789 o200k tokens total):
eval— Run transactionalForma-Pipecode (strict: trueauto-rolls back any non-manifold result) and return a ~100-token spatial diff (WT,NM,g,vol,bbox,size, tags).inspect— Read current scene invariants and bounding boxes without mutating state.tx— Instant copy-on-write state control:checkpoint,rollback,undo,reset.export— Export to.glb,.step,.3mf,.stl,.obj,.svg,.png(4-view studio), or.blend(via optional Blender bridge).
Option B — CLI (single-shot Unix pipes)
Use either the compiled native binary (forma) or the cross-platform npm CLI (npx -y forma-3d):
forma spec # Print ~355-token language reference
forma spec --gbnf # Print GBNF grammar for constrained decoding
forma eval --strict \
--out part.glb \
--render preview.png \
--draw blueprint.svg <<'EOF'
...Forma-Pipe script...
EOF
2. Standard 5-Step Modeling Workflow
- Plan coordinates (Z-up) and unit. Numbers are unit-agnostic and default to meters; if you model in another unit (e.g. a Pi case in mm) declare it with
units("mm")(orforma eval --unit mm) so.3mf/.stepexports open at the right size (.glbis scaled to metres;.stl/.objkeep model units). Primitives are centered at(0, 0, 0)unless placed withat=(x,y,z)orz0=Z(sets bottom Z; if bothat=andz0=are given,z0=overrides the Z coordinate afterat=positions X/Y). - Checkpoint before risky ops (MCP). Call
tx(action="checkpoint", tag="base")before complex cuts/bevels so you can roll back in O(1). - Write declarative
Forma-Pipe. Chain operations with|. Intermediate named parts still appear in the spatial diff (parts=N), while the last assigned variable is exported by default (or passpartin MCPexportto pick a specific part). - Always evaluate with
--strict/strict: true. Verify the returned spatial diff reportsWT=okandNM=0, plus exactbbox/size/section/clearance. - Visually inspect & export. Render a 4-view
.png(--render preview.png) to confirm proportions visually, then export.glb(PBR + triplanar UVs),.step,.3mf,.stl,.obj,.blend(native CLI with Blender installed), or.svgblueprint (--draw blueprint.svg).
3. Forma-Pipe Language Reference
- Syntax:
name = expr | op | op(multi-line|supported; math+ - * / sqrt sin cos asin acos abs pi). - Common primitive kwargs:
at=(x,y,z)orat=[(x,y,z), ...](batch),z0=Z,rot=(rx,ry,rz).
Primitives
| Primitive | Notes |
|---|---|
box(sx, sy, sz, at=, z0=) |
Axis-aligned box |
cyl(r, h, segs=32, axis=x|y|z, at=, z0=) |
Cylinder (axis=x, y, or z unquoted, default z; segs=6 gives hex vertices at k*60°) |
cone(r0, r1, h) |
Frustum / cone |
sphere(r) |
UV sphere |
torus(R, r) |
Major radius R, tube radius r |
pipe(ro, ri, h) |
Hollow cylindrical tube |
extrude2d([(x,y), ...], z0, z1) |
Extrude closed 2D polygon |
revolve([(r,z), ...], segs=32) |
Lathe profile around Z (auto-closes at r=0) |
loft([(z, [(x,y), ...]), ...], segs=24) |
Multi-section smooth loft (segs 8..128; warns if clamped) |
thread(r0, r1, pitch, turns) |
Watertight helical screw thread |
arc_tube(center=(x,y,z), rx=, rz=, start=-90, end=90, r=0.08) |
Curved handle / arc sweep |
tube([(x,y,z), ...], r=0.08) |
Polyline pipe sweep |
text3d("TEXT", height=0.3, depth=0.08) |
Watertight 3D extruded vector text |
load("path.glb|obj|stl") |
Import existing .glb, .obj, or .stl mesh (or uploaded asset key in forma-server) |
Operations & Selectors
- Booleans:
add(b, at=),cut(b, at=),intersect(b)—at=[...]runs fast batch CSG. - Features:
bevel(edges, w, segs=1)— semantic selectors:vertical,top_rim,bottom_rim,outer_rim,sharp,all(never guess integer edge indices).shell(t, open_top=true)— hollow solid with wall thicknesst.subsurf(levels=1, crease=false)— Catmull-Clark subdivision (crease=truepreserves sharp rims).extrude(faces, d)|inset(faces, amt, depth=0)— face selectors:top,bottom,sides,all.mirror(x|y|z)|pattern_linear(n, step=(dx,dy,dz))/array(n, step=)|pattern_radial(n, r=, axis=z)/radial(n, r=, axis=z)|decimate(ratio=0.5, faces=)(QEM LOD reduction preserving watertightness)
- Transforms & Relational Placement:
move(x, y, z)|rot(rx, ry, rz)(degrees) |scale(sx, sy, sz)on(base)(rests cleanly on top ofbase) |align(x|y|z, min|center|max, val)|align_z0(z)
- Materials & Spatial Queries:
mat("name", color=(r,g,b), metallic=0.1, roughness=0.5)|color(r,g,b)section(part, z)— returns 2D cross-section loop count & area at planeZ.clearance(a, b)— returns exact minimum 3D distance between partsaandb.
4. Verified Recipes
Brushed-Steel 5-Hole Mounting Flange
flange = box(4, 2, 0.4)
| mat("brushed_steel", color=(0.55, 0.68, 0.85), metallic=0.9, roughness=0.25)
| cut(cyl(0.5, 1.0))
| cut(cyl(0.25, 1.0), at=[(-1.4,-0.5,0), (-1.4,0.5,0), (1.4,-0.5,0), (1.4,0.5,0)])
section(flange, 0.0)
Beveled Hollow Enclosure
enclosure = box(3.0, 2.0, 1.0, z0=0)
| bevel(vertical, 0.2, segs=3)
| shell(0.15, open_top=true)
| mat("anodized_teal", color=(0.18, 0.56, 0.60), metallic=0.7, roughness=0.35)
Helical Threaded Hex Bolt
head = cyl(0.7, 0.4, segs=6, z0=0)
shank = thread(0.32, 0.42, 0.16, 6) | align_z0(0.38)
bolt = head | add(shank)
| mat("titanium", color=(0.74, 0.78, 0.84), metallic=0.92, roughness=0.22)
Ceramic Mug (Shell + Arc Handle)
body = cyl(0.5, 1.0, segs=32, z0=0) | shell(0.08, open_top=true)
handle = arc_tube(center=(0.48, 0, 0.5), rx=0.26, rz=0.28, start=-85, end=85, r=0.065)
mug = body | add(handle)
| mat("terracotta", color=(0.72, 0.36, 0.24), metallic=0.0, roughness=0.72)
5. Troubleshooting & Best Practices
- Through-cuts: Always make cutting cylinders/boxes taller than the target solid (e.g., cut a
0.4-thick plate with a1.0-tall cylinder) to avoid grazing coplanar ambiguity. - Overlapping joins: When joining two solids with
add()(like a bolt head + thread or mug body + handle), overlap them slightly (0.02units) rather than kissing at an exact zero-thickness plane. - Bevel order: Apply
bevel(vertical, w)beforeshell(t)when hollowing an enclosure so inner and outer walls stay clean and uniform. - Batch multi-hole cuts: Pass a coordinate list
cut(cyl(r, h), at=[(x1,y1,0), ...])instead of chaining separatecut()calls — it is faster and produces cleaner topology. - Strict verification: Never deliver a mesh that fails
--strict(WT=ok NM=0). If a boolean fails, adjust cutter clearance/overlap or roll back withtx(action="undo").
版本历史
- bbd1023 当前 2026-12-03 20:29


