Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

spec(sim-readiness): pin the physics-grade contract, its schema and the build plan

nirholas2fb63fd32a32
diff --git a/api/_lib/migrations/20260813180000_sim_readiness_grades.sql b/api/_lib/migrations/20260813180000_sim_readiness_grades.sql
new file mode 100644
index 000000000..3fbe6cd50
--- /dev/null
+++ b/api/_lib/migrations/20260813180000_sim_readiness_grades.sql
@@ -0,0 +1,61 @@
+-- Simulation-readiness grades, keyed by content hash.
+--
+-- A physics grade is a property of BYTES, not of a row in any one product
+-- table. The same GLB shows up as a forge creation, an Object Library entry, a
+-- remix of an earlier creation, and as an arbitrary third-party URL handed to
+-- the free endpoint. Keying by glb_sha256 means one grade per unique asset, a
+-- cache hit across every one of those surfaces, and no duplicated grading work
+-- when a mesh is reused. It also matches how provenance already addresses an
+-- asset (api/_lib/provenance-3d.js, specs/PROVENANCE_3D.md), so a grade and a
+-- credential for the same bytes join on one column.
+--
+-- grader_version is stored, not assumed. The grade is a claim about what a
+-- specific grader measured; when the grader changes, old rows stay valid and
+-- become re-gradeable rather than silently wrong. Re-grading writes a new row
+-- version in place and bumps graded_at, so `where grader_version <> $current`
+-- is the backfill query.
+--
+-- report holds the full JSON report exactly as api/_lib/sim-readiness.js
+-- returns it. The promoted columns duplicate the four fields the product
+-- actually filters and sorts on, because a jsonb path predicate cannot use a
+-- btree index the way `where verdict = 'simulation_ready'` can, and "show me
+-- every simulation-ready asset under 2 kg" is the query this whole lane exists
+-- to answer.
+--
+-- Draft: written by the architect pass, NOT applied. Run `npm run db:status`
+-- to confirm it reads as pending before `npm run db:migrate` applies it (and
+-- read that status first: db:migrate applies EVERY pending migration, not just
+-- this one).
+
+create table if not exists sim_readiness_grades (
+ glb_sha256 text primary key, -- 64-char hex sha256 of the GLB bytes
+ grader_version text not null, -- e.g. threews.sim.readiness.v1
+ verdict text not null, -- simulation_ready | needs_scale | needs_repair | unusable
+ blockers jsonb not null default '[]'::jsonb,
+ warnings jsonb not null default '[]'::jsonb,
+ watertight boolean, -- promoted from report.topology
+ longest_axis_m double precision, -- promoted from report.scale
+ volume_m3 double precision, -- promoted from report.mass
+ convexity_ratio double precision, -- promoted from report.collision
+ triangles integer,
+ size_bytes integer,
+ source_url text, -- the URL first graded, for triage only; never the key
+ creation_id uuid, -- forge_creations.id when the grade came from our own lane
+ grade_ms integer, -- wall-clock grading cost, for the scale envelope
+ report jsonb not null, -- the full report, verbatim
+ graded_at timestamptz not null default now()
+);
+
+-- The lane's headline query: every asset a simulator can consume, newest first.
+create index if not exists idx_sim_readiness_verdict
+ on sim_readiness_grades (verdict, graded_at desc);
+
+-- Backfill sweep after a grader version bump.
+create index if not exists idx_sim_readiness_grader
+ on sim_readiness_grades (grader_version);
+
+-- Join back to the creation that produced the asset (nullable: third-party and
+-- Object Library assets have no forge row).
+create index if not exists idx_sim_readiness_creation
+ on sim_readiness_grades (creation_id)
+ where creation_id is not null;
diff --git a/prompts/simulation-ready/00-CONTEXT.md b/prompts/simulation-ready/00-CONTEXT.md
index dc477c2fb..d0fba6248 100644
--- a/prompts/simulation-ready/00-CONTEXT.md
+++ b/prompts/simulation-ready/00-CONTEXT.md
@@ -119,6 +119,14 @@ world-model surface. It is infrastructure, not a leaf.
---
+## Work orders
+
+| # | Order | State |
+|---|---|---|
+| 01 | [The simulation-readiness grade, v1](01-architecture.md) | designed, ready to build |
+
+---
+
## The candidate table (all scored, 1 to 5 per axis)
Pull = who wants it tomorrow. Window = why now and why nobody has. Fit = machinery reused.
diff --git a/prompts/simulation-ready/01-architecture.md b/prompts/simulation-ready/01-architecture.md
new file mode 100644
index 000000000..443c7a3cd
--- /dev/null
+++ b/prompts/simulation-ready/01-architecture.md
@@ -0,0 +1,203 @@
+# 01. Architecture: the simulation-readiness grade, v1
+
+**How to run this:** paste this whole file into a fresh Claude Code chat opened in
+`/workspaces/three.ws`. Read [00-CONTEXT.md](00-CONTEXT.md) first; this file assumes it and does
+not repeat the bet. Produced by the architect pass on 2026-08-13 from the frontier HANDOFF.
+
+## Binding operating clause
+
+Finish 100%. Never end with a question or an unexecuted plan. All CLAUDE.md hard rules apply: no
+mocks, no fake data, no TODOs, no em-dash or en-dash, explicit-path commits, pushes and deploys
+owner-gated. Every architectural decision in this file is already made; if you disagree with one,
+implement it and say so in your report rather than stopping to relitigate it.
+
+**Nothing in this file is a status claim to trust.** Step 0 below re-measures.
+
+---
+
+## Step 0: re-derive the current state
+
+```bash
+npx vitest run tests/sim-readiness.test.js # the kernel: expect 6/6
+node -e "import('./api/_lib/sim-readiness.js').then(m=>console.log(Object.keys(m)))"
+npm run db:status # MUST read the draft below as pending
+ls specs/SIM_READINESS.md api/_lib/migrations/20260813180000_sim_readiness_grades.sql
+grep -rn "sim.readiness\|sim_readiness" api/ src/ pages/ --include=*.js -l # what is already wired
+curl -s "https://three.ws/api/provenance?src=https://three.ws/avatars/cesium-man.glb" | head -c 300
+```
+
+`npm run db:status` could not be run by the architect pass: this worktree's `.env` carries no
+`DATABASE_URL` and `gcloud` is not installed in the container, so the draft migration was written
+and deliberately left unapplied without a live pending-check. **Run it before you touch the
+schema, and read its full output**: `npm run db:migrate` applies every pending migration in
+`api/_lib/migrations/`, not only this one.
+
+## Contracts (already committed, do not redesign)
+
+| Artifact | Path | Status |
+|---|---|---|
+| The grade contract | [../../specs/SIM_READINESS.md](../../specs/SIM_READINESS.md) | committed |
+| Storage schema | [../../api/_lib/migrations/20260813180000_sim_readiness_grades.sql](../../api/_lib/migrations/20260813180000_sim_readiness_grades.sql) | committed, **not applied** |
+| The grader | [../../api/_lib/sim-readiness.js](../../api/_lib/sim-readiness.js) | live, 6/6 tests |
+| Kernel evidence | [../../tasks/sim-readiness/probe-2026-08-13.json](../../tasks/sim-readiness/probe-2026-08-13.json) | 20 live assets |
+
+### API shape
+
+`GET /api/sim-readiness?src=<https glb url>` or `?hash=<64-hex sha256>`
+
+Mirrors [`api/provenance.js`](../../api/provenance.js) exactly: same `wrap`/`cors` boundary, same
+`GET,OPTIONS`, no auth, no payment, no coin surface, thin wrapper over the MCP tool handler so the
+two can never disagree.
+
+| Case | Status | Body |
+|---|---|---|
+| Graded (fresh or cached) | 200 | `{ cached, gradedAt, ...report }` per the spec |
+| `?hash=` never graded | 404 | `{ error: "not graded" }` (never fetches bytes) |
+| Missing/malformed `src` and `hash` | 400 | `{ error: "…" }` |
+| `src` not https, or a blocked host | 400 | `{ error: "src must be a public https URL" }` |
+| Asset over the byte cap | 413 | `{ error: "asset exceeds 64 MB" }` |
+| Upstream fetch failed | 502 | `{ error: "could not fetch the asset", status }` |
+| Not binary glTF 2.0 | 200 | `{ readable: false, verdict: "unreadable", blockers: ["unreadable_glb"] }` |
+
+Caching: `cache-control: public, max-age=60, s-maxage=300` on a hit, `no-store` on every error.
+A grade for fixed bytes is immutable, so the only thing that expires it is a grader version bump.
+
+Rate bucket: the same one `/api/provenance` uses. Grading is 100× the cost of a hash lookup, so
+`?src=` on an ungraded asset is the expensive path and must share the forge-class bucket, not the
+free-read bucket. Reuse the existing limiter; do not invent a second one.
+
+MCP: one free tool, `grade_sim_readiness`, registered in `api/_mcp3d/tools/` following the exact
+shape of `verify_provenance` in [`api/_mcp3d/tools/provenance.js`](../../api/_mcp3d/tools/provenance.js)
+(`annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }`,
+`inputSchema` with `glb_url` and `hash`, report returned as `structuredContent`). Free, so it ships
+on both stores. Zero coin surface, like `verify_provenance`.
+
+---
+
+## Data flow, hop by hop
+
+Every hop names a real source. There are no `TBD` hops.
+
+**A. Grading our own output (the write path)**
+
+1. A forge lane finishes and `materializeCreation` in [`api/_lib/forge-store.js`](../../api/_lib/forge-store.js) copies the GLB into R2 and writes the `forge_creations` row (`glb_key`, `glb_url`, `size_bytes`).
+2. Same function, immediately after: read the GLB bytes it already holds, compute `sha256`, call `gradeSimReadiness(buf)`.
+3. Upsert `sim_readiness_grades` keyed by `glb_sha256`, carrying `creation_id`, `grader_version`, `grade_ms`, and the full report.
+4. Failure at step 2 or 3 never fails the generation. The creation is returned to the user either way; an ungraded asset simply has no row.
+
+**B. Grading anything else (the read path)**
+
+1. `GET /api/sim-readiness?src=…` → SSRF guard and https check (reuse the guard `anchor_provenance` already uses; do not write a second one).
+2. Fetch the bytes with the 64 MB cap.
+3. `sha256` → look up `sim_readiness_grades`. Hit at the current `grader_version` → return it with `cached: true`, no grading.
+4. Miss → `gradeSimReadiness(buf)` → upsert → return with `cached: false`.
+5. `?hash=` skips hops 1, 2 and 4 entirely: a pure lookup, 404 on miss.
+
+**C. Signing the grade (the trust path)**
+
+1. `anchor_provenance` already fetches the GLB and computes `glbSha256`.
+2. Look up (or compute) the grade for that hash.
+3. Pass the signed subset from [`specs/SIM_READINESS.md`](../../specs/SIM_READINESS.md#in-the-content-credential) into `buildCredential` as `simReadiness`.
+4. `buildCredential` gains one optional field and the credential version becomes `threews.provenance.3d.v2`, per that spec's own additive-field rule. **Old v1 credentials must keep verifying unchanged**; `decideVerdict` selects behaviour by `version` and is the file to read before touching this.
+
+**D. Rendering it (the surface path)**
+
+1. `/m/:id` and `/viewer?src=` already call `GET /api/provenance` for the verify badge. They gain a second call to `GET /api/sim-readiness` on the same asset.
+2. The verdict renders as a badge beside the provenance badge; the numbers render in a details panel.
+
+**E. Agent consumption**
+
+1. An assistant calls `grade_sim_readiness` with a `glb_url` from anywhere (ours or not).
+2. It receives the report as `structuredContent` and can gate on `verdict` before spending anything.
+
+---
+
+## Failure modes, every hop
+
+| Hop | Slow | Down | Garbage | Nothing |
+|---|---|---|---|---|
+| R2 / CDN fetch (B2) | 15 s timeout, then 502 with the elapsed time in the log | 502 `could not fetch the asset`; nothing is cached | Not glTF → 200 with `readable: false`, `unreadable_glb`. This is a valid grade, not an error. | 0-byte body → `unreadable_glb` |
+| Draco / meshopt decode | Bounded by the byte cap | Decoder module missing → `unreadable_glb` with the decode error. Never a silent skip. | Corrupt stream → same | n/a |
+| `gradeSimReadiness` | Hull construction dominates; 85 k triangles measured at 3.0 s. Cap input at 64 MB and grade in-process. | Cannot be down (pure, in-process) | Never throws by contract; returns `unreadable` | Zero triangles → `verdict: "unusable"`, `no_triangles` |
+| Postgres upsert (A3, B4) | Fire-and-forget on the write path; the creation never waits on it | Grade is still returned to the caller, just uncached. Log and continue. | Constraint violation → log, return the computed grade | Miss on read is the normal cold case, not an error |
+| Forge write path (A) | Grading adds ~1.5 s median to a generation that already takes tens of seconds | Grading failure must never fail a generation. Wrap it, log it, return the creation. | n/a | An ungraded creation renders the `ungraded` UI state |
+| Credential signing (C) | n/a | Missing issuer key already returns a coded error; unchanged | A grade that cannot be computed omits `simReadiness` rather than signing a null | Unanchored assets keep working exactly as today |
+| Viewer fetch (D) | Badge shows its loading state; never blocks the model render | Badge shows `ungraded`, not an error toast | Malformed JSON → treat as ungraded | 404 → `ungraded` |
+
+**Every UI state the Designer must build** (this list is inherited verbatim):
+
+1. **Loading**: grade requested, not back. Skeleton, never a spinner. Must not shift the model layout.
+2. **`simulation_ready`**: the affirmative badge. The one state worth screenshotting.
+3. **`needs_scale`**: sound geometry, unknown units. Must read as "nearly there", not as failure, and must say what to multiply by.
+4. **`needs_repair`**: names the blockers in human language ("the surface has 111 open edges"), and must visually suppress the mass numbers so nobody quotes them.
+5. **`unusable`**: terse and final.
+6. **`ungraded`**: no row for these bytes. Offers the grade action; never reads as an error.
+7. **`unreadable`**: not a valid GLB. Distinct from `unusable`.
+8. **Error**: the fetch itself failed. Actionable and retryable.
+9. **Overflow**: a report with many blockers and warnings must not blow the panel out.
+10. **Details expanded**: the full numbers: inertia tensor, hull, topology counts. Copyable as JSON, because the robotics user's next move is pasting it into their own pipeline.
+
+---
+
+## Scale envelope
+
+Measured, from [the probe run](../../tasks/sim-readiness/probe-2026-08-13.json), n = 20 real assets, 73 MB total.
+
+| Quantity | Measured |
+|---|---|
+| Grade latency, fetch included | min 184 ms, median 1551 ms, max 4840 ms |
+| Cost per geometry | ~72 ms per 1 000 triangles |
+| Largest asset graded | 85 718 triangles, 1.2 MB, 3 015 ms |
+| Report size | ~1.7 KB of JSON per asset |
+
+| Volume | Behaviour |
+|---|---|
+| 10 users | Every asset graded inline on the forge write path. No queue. Nothing to tune. |
+| 1 000 users | Still inline. At ~1.5 s per grade against generations that take tens of seconds, grading is under 5% of the lane's wall clock. The read path is cache-dominated: a repeat `?src=` is a hash lookup. |
+| 100 000 users | Grading moves off the request path into a worker fed by the existing forge completion path, and the free `?src=` endpoint grades at most N concurrently with the rest queued behind a 202. Backfilling the existing catalog is a cron over `where grader_version <> $current`, which is exactly why that index exists. |
+
+Hard limits to implement in v1: **64 MB byte cap** (already in the probe), **20 000 hull sample points**
+(already in the grader), **15 s fetch timeout**. Pagination is not needed in v1: nothing lists grades
+yet. When a browse surface lands it paginates on `idx_sim_readiness_verdict`.
+
+Caching: grades are immutable for fixed bytes and a fixed grader, so the DB row IS the cache and the
+CDN layer only needs the short `s-maxage` above. No second cache tier in v1.
+
+---
+
+## The build plan
+
+Each task is one commit with explicit paths. Ordered by risk: the task most likely to invalidate the
+design comes first.
+
+| # | Task | Files | Why it is at this position |
+|---|---|---|---|
+| 1 | Version the grader. Export `SIM_READINESS_VERSION = 'threews.sim.readiness.v1'` and include it as `grader` on every report. Update the spec's example only if the shape drifts. | [`api/_lib/sim-readiness.js`](../../api/_lib/sim-readiness.js), [`tests/sim-readiness.test.js`](../../tests/sim-readiness.test.js) | Everything downstream stores and signs this string. Getting it wrong later means a migration of signed data. |
+| 2 | Apply the schema. Read `npm run db:status` in full first, then `npm run db:migrate`. Add the store module with `getGrade(sha256)` / `putGrade(row)`. | [`api/_lib/migrations/20260813180000_sim_readiness_grades.sql`](../../api/_lib/migrations/20260813180000_sim_readiness_grades.sql), new `api/_lib/sim-readiness-store.js` | The riskiest irreversible step. If the promoted-column choice is wrong, it is far cheaper to learn now than after the endpoint ships. |
+| 3 | The MCP tool `grade_sim_readiness`, free, with the SSRF guard, byte cap and fetch timeout. | new `api/_mcp3d/tools/sim-readiness.js`, plus its registration | The handler the REST route wraps. Building it first means the two cannot disagree. |
+| 4 | The free REST route, a thin wrapper over task 3's handler. | new `api/sim-readiness.js` (filesystem-routed, no `vercel.json` entry needed) | Mechanical once 3 exists. |
+| 5 | Grade on the forge write path, wrapped so a grading failure never fails a generation. | [`api/_lib/forge-store.js`](../../api/_lib/forge-store.js) | Needs 2 and 3. Turns the lane from on-demand into a growing corpus. |
+| 6 | The credential extension: `simReadiness` in `buildCredential`, version bump to `threews.provenance.3d.v2`, v1 credentials still verifying. | [`api/_lib/provenance-3d.js`](../../api/_lib/provenance-3d.js), [`api/_mcp3d/tools/provenance.js`](../../api/_mcp3d/tools/provenance.js), [`specs/PROVENANCE_3D.md`](../../specs/PROVENANCE_3D.md), [`tests/provenance-3d.test.js`](../../tests/provenance-3d.test.js) | Touches signed bytes, so it lands only once the grade shape is settled by 1 to 5. |
+| 7 | The viewer and `/m/:id` badge plus details panel, all ten states. | [`public/viewer.html`](../../public/viewer.html), the `/m/:id` page module | The Designer stage owns the polish; this task owns reachability. |
+| 8 | Docs and changelog: `docs/sim-readiness.md` linked from `docs/start-here.md`, a `STRUCTURE.md` row, a `data/changelog.json` entry, `data/pages.json` if a page lands. | as listed | The Storyteller stage's input, but the entry is mandatory per CLAUDE.md. |
+
+## Second-order effects (the Integrator's list)
+
+- **Catalog quality gate**: a physics verdict is a harder signal than triangle count. The gate should be able to read it.
+- **Object Library**: 8 of 10 CC0 assets grade `needs_repair`. Grading the library is a cron over an existing R2 manifest and immediately makes the library filterable.
+- **Rig Doctor**: the same file, two questions ("will it animate?" and "will it simulate?"). They belong on the same page.
+- **Spatial MCP**: a spatial payload could carry the verdict alongside its affordances, which is what makes a returned scene physically usable.
+- **x402 datapoint fabric**: a graded asset is a filterable, machine-buyable asset. This is the compounding step, and it is a later slice, not v1.
+- **Search and Atlas**: `verdict` becomes a facet the moment a browse surface exists.
+- **Solana first**: nothing in v1 moves value. The credential anchor already on Solana is the only chain touchpoint and it is unchanged.
+
+## Never blocked
+
+| Blocker | Do this |
+|---|---|
+| `DATABASE_URL` missing locally | It is not in this worktree's `.env` and `gcloud` is absent from this container. Get it from the Cloud Run service per the CLAUDE.md playbook on a machine that has `gcloud`, or build tasks 1, 3 and 4 first (they need no DB) and land 2 and 5 when the DB is reachable. Never mock the store. |
+| `npm run db:status` shows other agents' pending migrations | Read them. If they are unrelated and safe, applying them is normal (that is what the command does). If any looks destructive, stop at that one and report it; do not apply blind. |
+| The credential version bump feels risky | It is the smallest correct change: `decideVerdict` selects by `version`, and `tests/provenance-3d.test.js` must gain a case proving a v1 credential still verifies. Do not add the field without the bump. |
+| Grading slows a generation noticeably | It is ~5% of the lane's wall clock. If a specific lane proves otherwise, move grading behind the existing completion path rather than dropping it. |
+| An asset grades differently on a re-run | It must not: sampling is fixed-stride and the math is deterministic. A genuine non-determinism is a bug in the grader and blocks the lane; root-cause it. |
+| Someone proposes storing the grade on `forge_creations` | Rejected in the schema header, with the reason. A grade is a property of bytes; the same bytes appear on four surfaces. |
diff --git a/specs/README.md b/specs/README.md
index 7136c02b9..d8d1e2e35 100644
--- a/specs/README.md
+++ b/specs/README.md
@@ -18,6 +18,8 @@ The specifications that define the three.ws embodied-agent platform: on-chain id
- [`ENS_AGENT_CLAIM.md`](./ENS_AGENT_CLAIM.md) — ENS / DNS Agent Claim v1. A convention of two cheap-to-set records that bidirectionally bind a human-readable name to an on-chain agent identity, with no new on-chain infrastructure.
- [`VALIDATORS.md`](./VALIDATORS.md) — Validator Allow-list Policy. Who may write to the on-chain `ValidationRegistry`, how attestations are formed, and how the allow-list is changed.
- [`SECURITY.md`](./SECURITY.md) — Security & Threat Model for three.ws Card v1. Enumerates abuse vectors specific to three.ws registration on the ERC-8004 registries and the current mitigation for each.
+- [`PROVENANCE_3D.md`](./PROVENANCE_3D.md): Verifiable 3D Provenance v1. C2PA-style signed content credentials for AI-generated 3D: creator, prompt, model, lineage and the GLB's content hash, ed25519-signed and anchored on Solana. Verification is free and public.
+- [`SIM_READINESS.md`](./SIM_READINESS.md): Simulation Readiness v1. The physics grade a 3D asset carries: watertightness, metric scale, mass and inertia, and a convex collision proxy, in four verdicts. Everything is derived from the mesh; anything unknowable from the geometry is reported as unknown rather than invented. Rides the provenance credential when signed.
## Schema
diff --git a/specs/SIM_READINESS.md b/specs/SIM_READINESS.md
new file mode 100644
index 000000000..2e4390158
--- /dev/null
+++ b/specs/SIM_READINESS.md
@@ -0,0 +1,199 @@
+# Simulation Readiness: a physics grade for 3D assets
+
+**Version `threews.sim.readiness.v1`** · Open specification · License: CC0 / public domain
+
+> Pure core: `api/_lib/sim-readiness.js`. Free grade: `GET /api/sim-readiness` and the `grade_sim_readiness` MCP tool. Probe: `scripts/sim-readiness-probe.mjs`. Companion spec: [`PROVENANCE_3D.md`](PROVENANCE_3D.md).
+
+## The problem
+
+A renderer forgives almost everything. A rigid-body solver forgives nothing. It needs a closed
+surface to integrate a volume over, consistent winding so that volume comes out positive, a
+real-world size so gravity and friction mean anything, and a convex proxy so collision queries
+stay cheap. Generated meshes routinely fail every one of those while looking perfect on screen,
+and the failure surfaces later as an object that sinks through a floor or spins like it is hollow.
+
+Nothing in the 3D asset supply chain states this. A GLB carries no claim about whether it can be
+simulated, so every robotics, game-physics and world-model pipeline rediscovers the same defects
+by hand. This spec fixes the vocabulary and the report so the claim can be made once, mechanically,
+and checked by anyone.
+
+**Everything in a report is derived from the mesh.** No model call, no heuristic dressed as a
+measurement. Where a value cannot be known from the geometry (true physical scale, material
+density) the report says so rather than inventing one, because a fabricated mass is worse than
+an absent one.
+
+## The verdict
+
+Exactly four values, ordered by how much work stands between the asset and a simulator.
+
+| Verdict | Meaning | What a consumer does |
+|---|---|---|
+| `simulation_ready` | Closed, consistently wound, positive volume, and the extents are real meters. | Use it as a rigid body as-is. |
+| `needs_scale` | The geometry is sound; only the unit anchoring is missing (the generator fitted it to a unit box). | Multiply to the intended size, then use it. Mass properties scale with it. |
+| `needs_repair` | The surface itself is open, non-manifold, or inconsistently wound. Volume and inertia are reported but unreliable. | Close the surface first. Do not trust the mass. |
+| `unusable` | No triangles, or a zero volume. | Reject. |
+
+A consumer that understands only one thing should understand this: **`verdict == "simulation_ready"`
+is the only value that licenses using the reported mass without further work.**
+
+## The report
+
+```jsonc
+{
+ "grader": "threews.sim.readiness.v1", // required: the contract version, see Versioning
+ "readable": true, // false only when the buffer is not binary glTF 2.0
+ "verdict": "simulation_ready", // required: one of the four above
+ "blockers": [], // machine reasons the verdict is not simulation_ready
+ "warnings": [], // conditions a consumer should know but that do not block
+
+ "geometry": {
+ "triangles": 4624,
+ "verticesRaw": 2796, // as authored, before welding
+ "verticesWelded": 2314, // after position welding, the topological vertex count
+ "weldToleranceMeters": 1.1e-6,
+ "skippedPrimitives": 0, // non-triangle primitives, excluded from mass
+ "skinnedPrimitives": 0,
+ "generator": "…" // glTF asset.generator, verbatim or null
+ },
+
+ "topology": {
+ "triangles": 4624, "degenerateTriangles": 0,
+ "edges": 6936, "boundaryEdges": 0, "nonManifoldEdges": 0, "inconsistentWindingEdges": 0,
+ "edgeManifold": true, "windingConsistent": true, "watertight": true
+ },
+
+ "scale": {
+ "longestAxisMeters": 0.3197, // glTF defines 1 unit = 1 meter
+ "sizeMeters": [x, y, z],
+ "centerOffsetMeters": [x, y, z],
+ "withinPhysicalWindow": true, // 0.005 m .. 20 m along the longest axis
+ "normalizedGuess": false // true = fitted to a unit box, units are not the object's
+ },
+
+ "mass": {
+ "volumeM3": 0.00298,
+ "surfaceAreaM2": 0.187,
+ "centroid": [x, y, z],
+ "inertiaUnitDensity": [ixx, ixy, ixz, iyx, iyy, iyz, izx, izy, izz], // row-major, about the centroid
+ "massAtWaterDensityKg": 2.98 // convenience only; multiply volumeM3 by your own density
+ },
+
+ "collision": {
+ "sampledPoints": 2314, "hullVertices": 680, "hullFaces": 678, "hullTriangles": 1356,
+ "hullVolumeM3": 0.00332,
+ "convexityRatio": 0.898, // meshVolume / hullVolume, in (0, 1]
+ "convexEnough": true // convexityRatio >= 0.9: one hull is an honest proxy
+ },
+
+ "bounds": { "min": [..], "max": [..], "size": [..], "diagonal": 0.41, "center": [..] }
+}
+```
+
+`mass` and `collision` are present whenever `readable` is true and the mesh has triangles, and are
+reported even for `needs_repair` so a consumer can see how far off the asset is. **Reading them
+without checking `verdict` is the one misuse this spec exists to prevent.**
+
+### Blocker and warning vocabulary
+
+Closed sets. A new value is a new spec version.
+
+| `blockers[]` | Cause |
+|---|---|
+| `open_surface` | One or more edges belong to a single triangle. |
+| `non_manifold_edges` | An edge is shared by three or more triangles. |
+| `inconsistent_winding` | A directed edge is traversed more than once: neighbouring triangles disagree on the outward face. |
+| `inverted_winding` | The whole surface is wound inward; the signed volume is negative. |
+| `zero_volume` | The surface encloses nothing. |
+| `scale_normalized` | The longest axis sits on the generator unit-box signature; the units are not the object's. |
+| `no_triangles` | No triangle primitives at all. |
+| `unreadable_glb` | Not binary glTF 2.0, or a compression extension could not be decoded. |
+
+| `warnings[]` | Meaning |
+|---|---|
+| `scale_outside_physical_window` | Real units, but outside 0.005 m to 20 m: a set piece, not a prop. |
+| `degenerate_triangles` | Triangles with repeated corners; excluded from the edge counts. |
+| `non_triangle_primitives_skipped` | Points, lines or strips present and excluded from the mass. |
+| `skinned_geometry_graded_at_bind_pose` | The mesh is skinned; it was graded unposed. Do not read it as a rigid body without saying so. |
+
+## How the numbers are derived
+
+Standard and exact for a closed, consistently wound triangle soup. All of it is unit-tested
+against closed forms in `tests/sim-readiness.test.js` (a cube of side s at unit density must
+return V = s³ and I = s⁵/6, and does to float32 accessor precision).
+
+| Quantity | Method |
+|---|---|
+| Volume, centroid | Divergence theorem over signed tetrahedra (0, a, b, c). |
+| Inertia | Tetrahedron covariance accumulation, C = det(J)·J·Ĉ·Jᵀ with Ĉ = (1/120)·[[2,1,1],[1,2,1],[1,1,2]], shifted to the centroid, then I = tr(C)·1 - C. Reported at unit density so it scales linearly with any density a caller assigns. |
+| Manifoldness | Every undirected edge shared by exactly two triangles; every directed edge traversed exactly once. Vertices are welded by quantized position first, at a tolerance relative to the model's own bounding diagonal, because UV and normal seams split geometrically identical vertices and would fake a boundary. |
+| Scale | World-space extents after node transforms, read as meters per the glTF 2.0 unit convention. |
+| Collision proxy | Convex hull over welded points (deterministic stride sampling above the point cap), with the hull volume from the same signed-tetra sum. |
+
+Compressed input (Draco, meshopt) is decoded before grading. A decode failure is `unreadable_glb`,
+never a silent skip.
+
+## Free grade over HTTP
+
+`GET /api/sim-readiness?src=<glbUrl>` (or `?hash=<sha256>` for an already-graded asset) returns the
+report. No account, no payment, no coin surface, mirroring `GET /api/provenance`. The response adds
+one envelope field:
+
+```jsonc
+{ "cached": true, "gradedAt": "2026-08-13T…Z", …the report… }
+```
+
+`?hash=` returns `404` with `{ "error": "not graded" }` when that content hash has never been
+graded; it never fetches bytes. `?src=` grades on demand and caches by content hash.
+
+The `grade_sim_readiness` MCP tool (free, `api/_mcp3d/tools/`) returns the same object as
+`structuredContent`.
+
+## In the content credential
+
+A signed grade is the point: an unsigned report is a claim anyone can forge. The grade rides the
+existing content credential ([`PROVENANCE_3D.md`](PROVENANCE_3D.md)) as one optional field:
+
+```jsonc
+{
+ "version": "threews.provenance.3d.v2", // v2, per that spec's additive-field rule
+ "glbSha256": "…",
+ "createdAt": "…",
+ "simReadiness": {
+ "grader": "threews.sim.readiness.v1",
+ "verdict": "simulation_ready",
+ "blockers": [],
+ "volumeM3": 0.00298,
+ "longestAxisMeters": 0.3197,
+ "inertiaUnitDensity": [ … 9 numbers … ],
+ "convexityRatio": 0.898
+ }
+}
+```
+
+Only that subset is signed. The full report stays out of the credential because the credential's
+canonical bytes must stay small and stable, and because every signed field is a field a future
+grader version could contradict.
+
+**The grader version is signed with the grade for exactly that reason.** A verifier that re-grades
+with a newer grader and gets a different answer must report both, attributed, and must never
+silently overwrite a signed grade. A grade signed by `threews.sim.readiness.v1` is a claim about
+what v1 measured, permanently.
+
+## Conformance
+
+- The same bytes must always produce the same report. Sampling is deterministic (fixed stride, no
+ randomness), so a grade is reproducible by any implementer from the GLB alone.
+- A one-byte change to the GLB changes its content hash and therefore its cache identity; the grade
+ is keyed by content hash, never by URL.
+- Node transforms are applied before measuring. A mesh scaled 2× by its node is 2× as large.
+- `needs_repair` must never be reported as `simulation_ready` because the numbers "look fine".
+ The verdict is topological, not aesthetic.
+
+## Versioning
+
+`grader` is the contract. Additive fields, new blocker values, and threshold changes all ship a new
+version string; consumers select behaviour by it. Thresholds that a deployment may tune without a
+version bump are exactly the two documented in `SCALE_BOUNDS`; a report generated under tuned
+bounds must still say `threews.sim.readiness.v1` only if the bounds are unchanged from this spec.
+
+CC0: reimplement and extend freely.