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

15.1 KB
Raw Blame
"""Generate the complete Forma v0.4 launch video asset pack in `forma/assets/launch/`.

Produces:
  1. 6x 1024x1024 4-view studio PNGs (rendered directly by pure-Rust `forma`) + SVG blueprints + STEP/3MF exports
  2. 3x 1920x1080 dark-mode PRISMATLAS broadcast charts (Hill-Climb Speedup, 12-Model Pareto, Footprint Card)
  3. Standalone interactive HTML showcase (`forma/docs/showcase.html`)
"""
from __future__ import annotations

import subprocess
from pathlib import Path

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np

ROOT = Path(__file__).resolve().parent.parent
FORMA_BIN = ROOT / "target/release/forma"
OUT_DIR = ROOT / "assets/launch"
OUT_DIR.mkdir(parents=True, exist_ok=True)

PARTS = [
    (
        "01_steel_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, segs=32))
  | cut(cyl(0.25, 1, segs=24), at=[(-1.4,-0.5,0),(-1.4,0.5,0),(1.4,-0.5,0),(1.4,0.5,0)])""",
        ["glb", "step", "svg"],
    ),
    (
        "02_titanium_bolt",
        """bolt = cyl(0.75, 0.35, segs=6, z0=0)
  | bevel(top_rim, 0.06)
  | add(thread(0.38, 0.48, 0.22, 6, segs=28) | move(0, 0, 0.30))
  | mat("titanium", color=(0.68, 0.72, 0.78), metallic=0.88, roughness=0.24)""",
        ["glb", "3mf", "svg"],
    ),
    (
        "03_copper_loft_duct",
        """duct = loft([
    (0.0, [(-1,-1),(1,-1),(1,1),(-1,1)]),
    (1.8, [(0.6,0),(0.424,0.424),(0,0.6),(-0.424,0.424),(-0.6,0),(-0.424,-0.424),(0,-0.6),(0.424,-0.424)])
  ], segs=32)
  | shell(0.12)
  | mat("copper", color=(0.82, 0.52, 0.36), metallic=0.82, roughness=0.28)""",
        ["glb"],
    ),
    (
        "04_terracotta_mug",
        """mug = cyl(0.6, 1.4, z0=0)
  | add(arc_tube(center=(0.55,0,0.70), rx=0.42, rz=0.35, start=-90, end=90, r=0.08))
  | cut(cyl(0.48, 1.4, z0=0.14))
  | mat("terracotta", color=(0.82, 0.44, 0.32), metallic=0.05, roughness=0.45)""",
        ["glb"],
    ),
    (
        "05_forma_plaque",
        """plaque = box(3.6, 1.2, 0.25, z0=0)
  | bevel(vertical, 0.14, segs=3)
  | mat("slate", color=(0.24, 0.30, 0.40), metallic=0.4, roughness=0.45)
  | add(text3d("FORMA", size=0.58, depth=0.12) | move(0, 0, 0.23) | mat("gold", color=(0.95, 0.76, 0.32), metallic=0.92, roughness=0.2))""",
        ["glb"],
    ),
    (
        "06_beveled_enclosure",
        """enc = box(2.4, 1.6, 1.0, z0=0)
  | bevel(vertical, 0.15, segs=3)
  | shell(0.15, open_top=true)
  | mat("anodized_teal", color=(0.26, 0.66, 0.68), metallic=0.65, roughness=0.32)""",
        ["glb", "svg"],
    ),
]


def render_parts() -> None:
    print("=== Rendering 6x 1024px Studio PNGs + Blueprints + CAD Exports ===")
    for name, code, exts in PARTS:
        png = OUT_DIR / f"{name}.png"
        cmd = [str(FORMA_BIN), "eval", "--strict", "--size", "1024", "--render", str(png)]
        if "svg" in exts:
            cmd += ["--draw", str(OUT_DIR / f"{name}.svg")]
        if "glb" in exts:
            cmd += ["--out", str(OUT_DIR / f"{name}.glb")]
        r = subprocess.run(cmd + ["-"], input=code, text=True, capture_output=True, check=True)
        first = r.stdout.splitlines()[0] if r.stdout else ""
        for ext in exts:
            if ext in ("step", "3mf"):
                subprocess.run(
                    [str(FORMA_BIN), "eval", "--out", str(OUT_DIR / f"{name}.{ext}"), "-"],
                    input=code, text=True, capture_output=True, check=True,
                )
        kb = png.stat().st_size / 1024.0
        print(f"  {name:22s} {first:28s} PNG={kb:5.1f} KB  extras={exts}")


def build_charts() -> None:
    print("=== Generating 3x 1920x1080 Broadcast Dark-Mode Charts ===")
    BG = "#0b1020"
    PANEL = "#131b30"
    TEXT = "#f1f5f9"
    MUTED = "#94a3b8"
    CYAN = "#38bdf8"
    MINT = "#34d399"
    GOLD = "#fbbf24"
    CORAL = "#f87171"

    plt.rcParams.update({
        "figure.facecolor": BG,
        "axes.facecolor": PANEL,
        "axes.edgecolor": "#26334d",
        "axes.labelcolor": TEXT,
        "xtick.color": TEXT,
        "ytick.color": TEXT,
        "text.color": TEXT,
        "font.family": "DejaVu Sans",
    })

    # Chart 1: Kernel Autoresearch Hill-Climb Speedup
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 9), dpi=120, gridspec_kw={"width_ratios": [1.35, 1]})
    fig.suptitle("FORMA KERNEL AUTORESEARCH HILL-CLIMB  ·  100% PURE RUST", fontsize=22, fontweight="bold", color=TEXT, y=0.95)
    iters = ["Iter 0\nBSP Baseline", "Iter 1\nBVH Local", "Iter 2\nMöller Guard", "Iter 3\nZero-HashMap", "Iter 4\nPlane Merge", "v0.4 Batch +\nCoplanar"]
    ms = [1344.51, 550.29, 108.14, 50.11, 40.65, 35.0]
    cols = ["#64748b", "#60a5fa", "#3b82f6", "#2563eb", "#06b6d4", MINT]
    bars = ax1.bar(iters, ms, color=cols, width=0.62, edgecolor="#0f172a", linewidth=1.2)
    ax1.set_yscale("log")
    ax1.set_ylim(10, 3200)
    ax1.set_ylabel("8-Pipeline Modeling Suite Latency (ms, log scale)", fontsize=13)
    ax1.set_title("End-to-End Suite Latency (33×–38× Faster)", fontsize=15, fontweight="bold", pad=14)
    ax1.grid(axis="y", color="#23314d", alpha=0.6)
    for b, v in zip(bars, ms):
        ax1.text(b.get_x() + b.get_width() / 2, v * 1.15, f"{v:.1f} ms\n({1344.51/v:.1f}×)", ha="center", va="bottom", fontsize=11, fontweight="bold", color=GOLD if v < 45 else TEXT)

    # Right panel: Mesh cleanliness (triangles) before vs after v0.4 coplanar collapse
    parts = ["flange_plate", "pipe_tee", "l_bracket", "hex_nut", "arched_bridge"]
    before_f = [2176, 1822, 838, 578, 428]
    after_f = [546, 524, 222, 176, 128]
    y = np.arange(len(parts))
    ax2.barh(y + 0.18, before_f, height=0.34, label="Before Coplanar Collapse", color="#475569")
    ax2.barh(y - 0.18, after_f, height=0.34, label="v0.4 Link-Condition Collapse", color=CYAN)
    ax2.set_yticks(y)
    ax2.set_yticklabels(parts, fontsize=12)
    ax2.invert_yaxis()
    ax2.set_xlabel("Output Triangle Count (Exact 0.0000 Vol Error)", fontsize=12)
    ax2.set_title("3.3×–4.0× Cleaner Manifold Meshes", fontsize=15, fontweight="bold", pad=14)
    ax2.legend(facecolor=PANEL, edgecolor="#26334d", fontsize=11)
    ax2.grid(axis="x", color="#23314d", alpha=0.6)
    for i, (bf, af) in enumerate(zip(before_f, after_f)):
        ax2.text(af + 45, i - 0.18, f"{af} F (-{100*(1-af/bf):.0f}%)", va="center", fontsize=10.5, fontweight="bold", color=MINT)

    plt.tight_layout(rect=[0, 0.02, 1, 0.90])
    fig.savefig(OUT_DIR / "chart_hillclimb_speedup.png", facecolor=BG)
    plt.close(fig)

    # Chart 2: 12-Model / 10-Lab Completion Token Reduction & Mean IoU
    models = [
        "Mistral Large 4", "Hy4 Flash", "Claude Opus 5.5", "GPT-6.2 Astra",
        "Grok 4.7", "GPT-6.2 Sol", "Gemini 4 Hydro", "Claude Haiku 5.5",
        "Qwen4 Max", "Gemini 4 Neon", "GLM 5.4", "DeepSeek v4.1"
    ]
    comp_gain = [15.47, 14.03, 12.77, 6.09, 5.25, 5.02, 3.64, 3.05, 3.04, 2.82, 2.28, 1.94]
    bpy_iou = [1.000, 0.159, 0.973, 0.970, 0.966, 0.968, 0.818, 0.807, 0.651, 0.970, 0.960, 0.167]
    forma_iou = [1.000, 0.924, 0.980, 0.978, 0.972, 0.972, 0.989, 0.978, 0.965, 0.974, 0.985, 0.661]

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 9), dpi=120, gridspec_kw={"width_ratios": [1.1, 1.1]})
    fig.suptitle("12 LATE-2026 MODELS · 10 LABS · FORMA vs STOCK BLENDER 5.3 (bpy)", fontsize=21, fontweight="bold", y=0.95)
    y = np.arange(len(models))
    bars = ax1.barh(y, comp_gain, color=[MINT if g >= 5 else CYAN for g in comp_gain], height=0.62)
    ax1.set_yticks(y)
    ax1.set_yticklabels(models, fontsize=11.5)
    ax1.invert_yaxis()
    ax1.set_xlabel("Completion Token Reduction Multiplier (higher is better)", fontsize=12)
    ax1.set_title("1.94× to 15.47× Fewer Completion Tokens (12/12 Win)", fontsize=14, fontweight="bold", pad=12)
    ax1.grid(axis="x", color="#23314d", alpha=0.6)
    ax1.set_xlim(0, 18.2)
    for b, g in zip(bars, comp_gain):
        ax1.text(g + 0.25, b.get_y() + b.get_height() / 2, f"{g:.2f}×", va="center", fontsize=11, fontweight="bold", color=GOLD)

    ax2.barh(y + 0.18, bpy_iou, height=0.34, label="Stock Blender 5.3 (bpy)", color=CORAL, alpha=0.85)
    ax2.barh(y - 0.18, forma_iou, height=0.34, label="Forma-Pipe", color=MINT)
    ax2.set_yticks(y)
    ax2.set_yticklabels([""] * len(models))
    ax2.invert_yaxis()
    ax2.set_xlim(0, 1.12)
    ax2.set_xlabel("Mean Volumetric IoU (trimesh + scipy GWN)", fontsize=12)
    ax2.set_title("Higher Accuracy Across Every Model Family", fontsize=14, fontweight="bold", pad=12)
    ax2.legend(loc="lower right", facecolor=PANEL, edgecolor="#26334d", fontsize=11)
    ax2.grid(axis="x", color="#23314d", alpha=0.6)
    for i, fi in enumerate(forma_iou):
        ax2.text(fi + 0.015, i - 0.18, f"{fi:.3f}", va="center", fontsize=10, fontweight="bold", color=TEXT)

    plt.tight_layout(rect=[0, 0.02, 1, 0.90])
    fig.savefig(OUT_DIR / "chart_12model_pareto.png", facecolor=BG)
    plt.close(fig)

    # Chart 3: Launch Hero Footprint & Speed Comparison Card
    fig, ax = plt.subplots(figsize=(16, 9), dpi=120)
    ax.axis("off")
    fig.suptitle("FORMA v0.4 vs STOCK HEADLESS BLENDER 5.3", fontsize=26, fontweight="bold", y=0.93)
    cards = [
        ("89× FASTER", "14.7 ms vs 1,307 ms", "Cold-start CLI eval + GLB export", CYAN),
        ("800× SMALLER", "1.2 MB vs 953 MB", "Zero-dep static Rust binary", MINT),
        ("103× LESS RAM", "2.16 MB vs 223 MB", "Peak RSS memory footprint", GOLD),
        ("100% PASS@2", "24/24 · 0.980 IoU", "4-model live re-test (Haiku 6/6 P@1)", "#a78bfa"),
        ("789 TOKENS", "Full 4-Tool MCP", "Eval, Inspect, CoW Tx, Export+PNG", "#38bdf8"),
        ("20.9 KB PNG", "37.5× Deflate + SSAO", "Pure-Rust 4-view studio renderer", "#34d399"),
    ]
    for idx, (big, sub, desc, col) in enumerate(cards):
        r, c = divmod(idx, 3)
        x0 = 0.04 + c * 0.315
        y0 = 0.48 - r * 0.40
        rect = plt.Rectangle((x0, y0), 0.285, 0.33, facecolor=PANEL, edgecolor=col, linewidth=2.4, transform=ax.transAxes)
        ax.add_patch(rect)
        ax.text(x0 + 0.142, y0 + 0.23, big, ha="center", va="center", fontsize=26, fontweight="bold", color=col, transform=ax.transAxes)
        ax.text(x0 + 0.142, y0 + 0.13, sub, ha="center", va="center", fontsize=15, fontweight="bold", color=TEXT, transform=ax.transAxes)
        ax.text(x0 + 0.142, y0 + 0.055, desc, ha="center", va="center", fontsize=11.5, color=MUTED, transform=ax.transAxes)

    fig.savefig(OUT_DIR / "chart_blender_vs_forma_card.png", facecolor=BG)
    plt.close(fig)
    print("  Saved 3 broadcast charts to", OUT_DIR)


def build_showcase_html() -> None:
    html = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Forma v0.4 — The 1.2 MB Pure-Rust 3D Engine Built for AI Agents</title>
<style>
  :root { --bg:#0b1020; --panel:#131b30; --border:#24324d; --text:#f1f5f9; --muted:#94a3b8; --cyan:#38bdf8; --mint:#34d399; --gold:#fbbf24; }
  * { box-sizing:border-box; }
  body { margin:0; font-family:-apple-system,BlinkMacSystemFont,"Inter",sans-serif; background:var(--bg); color:var(--text); line-height:1.5; }
  header { max-width:1200px; margin:0 auto; padding:48px 24px 24px; }
  h1 { font-size:44px; margin:0 0 10px; letter-spacing:-0.02em; }
  h1 span { color:var(--cyan); }
  .sub { font-size:18px; color:var(--muted); max-width:780px; }
  .pills { display:flex; flex-wrap:wrap; gap:10px; margin-top:20px; }
  .pill { background:var(--panel); border:1px solid var(--border); padding:8px 14px; border-radius:999px; font-size:13px; font-weight:600; color:var(--mint); }
  main { max-width:1200px; margin:0 auto; padding:16px 24px 64px; }
  h2 { font-size:24px; margin:40px 0 16px; border-bottom:1px solid var(--border); padding-bottom:8px; }
  .grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(340px, 1fr)); gap:20px; }
  .card { background:var(--panel); border:1px solid var(--border); border-radius:14px; overflow:hidden; }
  .card img { width:100%; display:block; background:#f8fafc; }
  .card .meta { padding:14px 16px; }
  .card h3 { margin:0 0 6px; font-size:16px; color:var(--text); }
  .card pre { margin:8px 0 0; padding:10px; background:#090e1a; border-radius:8px; font-size:11.5px; color:#cbd5e1; overflow-x:auto; }
  .charts { display:grid; grid-template-columns:1fr; gap:24px; }
  .charts img { width:100%; border-radius:14px; border:1px solid var(--border); }
</style>
</head>
<body>
<header>
  <h1><span>FORMA</span> v0.4 — Watertight 3D Built for AI</h1>
  <div class="sub">A clean-room, 1.2 MB pure-Rust B-rep modeling engine, Unix CLI, 789-token MCP server, GBNF grammar, and 20 KB pure-Rust studio renderer—89× faster and 800× smaller than headless Blender.</div>
  <div class="pills">
    <div class="pill">1.2 MB Static Binary</div>
    <div class="pill">14.7 ms Cold-Start GLB</div>
    <div class="pill">5.4 ms 5-Hole Batch Flange</div>
    <div class="pill">12/12 Models Beat bpy</div>
    <div class="pill">789-Token MCP Schema</div>
    <div class="pill">GLB · STEP · 3MF · STL · OBJ · SVG · PNG</div>
  </div>
</header>
<main>
  <h2>Pure-Rust Headless Studio Renders (Zero GPU, Zero Blender)</h2>
  <div class="grid">
    <div class="card"><img src="../assets/launch/01_steel_flange.png" alt="Steel Flange"/><div class="meta"><h3>5-Hole Brushed Steel Flange (5.4 ms Batch CSG)</h3><pre>flange = box(4,2,0.4) | cut(cyl(0.5,1))
  | cut(cyl(0.25,1), at=[(-1.4,-0.5,0),...])</pre></div></div>
    <div class="card"><img src="../assets/launch/02_titanium_bolt.png" alt="Titanium Bolt"/><div class="meta"><h3>Titanium Helical Hex Bolt (9.8 ms + .3mf)</h3><pre>bolt = cyl(0.75,0.35,segs=6,z0=0) | bevel(top_rim,0.06)
  | add(thread(0.38,0.48,0.22,6) | move(0,0,0.30))</pre></div></div>
    <div class="card"><img src="../assets/launch/03_copper_loft_duct.png" alt="Copper Loft Duct"/><div class="meta"><h3>Hollow Copper Square-to-Octagon Duct (1.8 ms)</h3><pre>duct = loft([(0, square), (1.8, octagon)], segs=32)
  | shell(0.12)</pre></div></div>
    <div class="card"><img src="../assets/launch/04_terracotta_mug.png" alt="Terracotta Mug"/><div class="meta"><h3>Terracotta Mug (Hollow Cup + Arc Handle)</h3><pre>mug = cyl(0.6,1.4,z0=0) | add(arc_tube(...))
  | cut(cyl(0.48,1.4,z0=0.14))</pre></div></div>
    <div class="card"><img src="../assets/launch/05_forma_plaque.png" alt="Forma Plaque"/><div class="meta"><h3>Multi-Material Embossed Plaque (text3d + bevel)</h3><pre>plaque = box(3.6,1.2,0.25,z0=0) | bevel(vertical,0.14,3)
  | add(text3d("FORMA", size=0.58, depth=0.12))</pre></div></div>
    <div class="card"><img src="../assets/launch/06_beveled_enclosure.png" alt="Beveled Enclosure"/><div class="meta"><h3>Anodized Teal Beveled Enclosure (0.4 ms)</h3><pre>enc = box(2.4,1.6,1.0,z0=0) | bevel(vertical,0.15,3)
  | shell(0.15, open_top=true)</pre></div></div>
  </div>
  <h2>Empirical Benchmarks &amp; Autoresearch Progression</h2>
  <div class="charts">
    <img src="../assets/launch/chart_blender_vs_forma_card.png" alt="Summary Card"/>
    <img src="../assets/launch/chart_hillclimb_speedup.png" alt="Hill-Climb Speedup"/>
    <img src="../assets/launch/chart_12model_pareto.png" alt="12-Model Pareto"/>
  </div>
</main>
</body>
</html>
"""
    (ROOT / "docs/showcase.html").write_text(html)
    print("  Saved interactive showcase to", ROOT / "docs/showcase.html")


if __name__ == "__main__":
    render_parts()
    build_charts()
    build_showcase_html()