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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
chore: rig-path bake-off decided — rig-worker lane wins, proximity lib demoted to test harness
nirholas3839deea0588
diff --git a/scripts/garment-rig-bakeoff.mjs b/scripts/garment-rig-bakeoff.mjsnew file mode 100644index 000000000..da1e026b6--- /dev/null+++ b/scripts/garment-rig-bakeoff.mjs@@ -0,0 +1,107 @@+// Rig-path bake-off: the SAME garment skinned by (A) the rig-worker lane vs+// (B) proximity transfer, attached to the parametric base, driven through the+// canonical walk clip. Metric: distance from each skinned garment vertex to+// the nearest skinned body vertex, sampled across the gait — good cloth keeps+// a small bounded offset; broken skinning spikes.+//+// Usage (SCRATCH dir must contain base-notex.glb + the two garment variants —+// see workers/garment-forge/README.md "Skinning bake-off" for how to produce+// them from any published garment):+//+// SCRATCH=/path/to/dir node scripts/garment-rig-bakeoff.mjs+//+// Verdict of 2026-07-25 on the first seeded shirt (5 gait samples, 15,210+// measurements): rig-worker mean 2.87cm / p95 6.36cm; proximity mean 5.88cm /+// p95 13.06cm. The rig-worker lane is production; the proximity lib survives+// only as the offline test harness (workers/garment-forge/lib/).+// Re-run this whenever either skinning path changes.+import { readFile } from 'node:fs/promises';+import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';+import { Group, Vector3, AnimationClip, AnimationMixer } from 'three';+import { attachGarment } from '/workspaces/three.ws/src/avatar-garment.js';+import { retargetClipToObject } from '/workspaces/three.ws/src/animation-retarget.js';++const SCRATCH = process.env.SCRATCH;+const load = async (p) => {+ const buf = await readFile(p);+ const loader = new GLTFLoader();+ return new Promise((res, rej) => loader.parse(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength), '', res, rej));+};++const clipJson = JSON.parse(await readFile('/workspaces/three.ws/public/animations/clips/walk.json', 'utf8'));+const clip = AnimationClip.parse(clipJson.clip || clipJson);++async function evaluate(garmentPath, label) {+ const avatar = await load(`${SCRATCH}/base-notex.glb`);+ const root = new Group();+ root.add(avatar.scene);+ root.updateMatrixWorld(true);++ const garment = await load(garmentPath);+ const res = attachGarment(root, garment.scene, { slot: 'top' });+ if (!res.ok) { console.log(label, 'ATTACH FAILED:', res.reason); return; }+ const gMesh = res.meshes[0];++ let body;+ root.traverse((o) => { if (o.isSkinnedMesh && !o.userData.garmentSlot && (!body || o.geometry.attributes.position.count > body.geometry.attributes.position.count)) body = o; });++ const { clip: rClip } = retargetClipToObject(clip, root);+ if (!rClip) { console.log(label, 'RETARGET FAILED'); return; }+ const mixer = new AnimationMixer(root);+ mixer.clipAction(rClip).play();++ const stats = { mean: 0, p95: 0, max: 0, n: 0 };+ const all = [];+ const v = new Vector3();+ for (const t of [0.1, 0.3, 0.5, 0.7, 0.9]) {+ mixer.setTime(t * rClip.duration);+ root.updateMatrixWorld(true);+ body.skeleton.update();+ gMesh.skeleton.update();++ // body surface samples in world space+ const bp = body.geometry.attributes.position;+ const bodyPts = [];+ for (let i = 0; i < bp.count; i += 4) {+ v.fromBufferAttribute(bp, i); body.applyBoneTransform(i, v); v.applyMatrix4(body.matrixWorld);+ bodyPts.push(v.x, v.y, v.z);+ }+ // coarse grid for nearest lookup+ const cell = 0.05;+ const grid = new Map();+ for (let i = 0; i < bodyPts.length / 3; i++) {+ const k = `${Math.floor(bodyPts[i*3]/cell)},${Math.floor(bodyPts[i*3+1]/cell)},${Math.floor(bodyPts[i*3+2]/cell)}`;+ (grid.get(k) || grid.set(k, []).get(k)).push(i);+ }+ const nearest = (x, y, z) => {+ let best = Infinity;+ const cx = Math.floor(x/cell), cy = Math.floor(y/cell), cz = Math.floor(z/cell);+ for (let r = 0; r < 8; r++) {+ for (let dx = -r; dx <= r; dx++) for (let dy = -r; dy <= r; dy++) for (let dz = -r; dz <= r; dz++) {+ if (Math.max(Math.abs(dx),Math.abs(dy),Math.abs(dz)) !== r) continue;+ const b = grid.get(`${cx+dx},${cy+dy},${cz+dz}`);+ if (!b) continue;+ for (const i of b) {+ const d = (bodyPts[i*3]-x)**2 + (bodyPts[i*3+1]-y)**2 + (bodyPts[i*3+2]-z)**2;+ if (d < best) best = d;+ }+ }+ if (best < Infinity && r > 1) break;+ }+ return Math.sqrt(best);+ };++ const gp = gMesh.geometry.attributes.position;+ for (let i = 0; i < gp.count; i += 8) {+ v.fromBufferAttribute(gp, i); gMesh.applyBoneTransform(i, v); v.applyMatrix4(gMesh.matrixWorld);+ const d = nearest(v.x, v.y, v.z);+ if (Number.isFinite(d)) all.push(d);+ }+ }+ all.sort((a, b) => a - b);+ const mean = all.reduce((s, x) => s + x, 0) / all.length;+ console.log(`${label}: n=${all.length} mean=${(mean*100).toFixed(2)}cm p95=${(all[Math.floor(all.length*0.95)]*100).toFixed(2)}cm max=${(all[all.length-1]*100).toFixed(2)}cm`);+}++await evaluate(`${SCRATCH}/seed-shirt-notex.glb`, 'A rig-worker ');+await evaluate(`${SCRATCH}/seed-shirt-proximity.glb`, 'B proximity ');diff --git a/workers/garment-forge/README.md b/workers/garment-forge/README.mdindex da067dae5..9f457fb66 100644--- a/workers/garment-forge/README.md+++ b/workers/garment-forge/README.md@@ -15,6 +15,26 @@ skin onto the target avatar's skeleton and refuses anything that binds undernumber before publishing and fails the job loudly rather than emitting a badasset.+## Skinning bake-off (why the rig-worker lane)++Two candidate skinning paths were built independently and raced on 2026-07-25:+the same generated shirt was skinned by (A) the rig-worker composite lane this+worker uses and (B) a local proximity weight-transfer+([lib/skin-transfer.mjs](lib/skin-transfer.mjs)), then both were attached to+the parametric base and driven through the canonical walk clip+([scripts/garment-rig-bakeoff.mjs](../../scripts/garment-rig-bakeoff.mjs)).+Cloth-to-body deviation across the gait:++| Path | mean | p95 | max |+|---|---|---|---|+| A rig-worker (production) | **2.87 cm** | **6.36 cm** | 16.12 cm |+| B proximity transfer | 5.88 cm | 13.06 cm | 21.02 cm |++A won decisively and is the only production lane. The proximity lib is kept+solely as the offline test harness for the runtime binder's contract test+(`tests/garment-forge-skin-transfer.test.js`) — see the note in its header.+Re-run the bake-off whenever either path changes.+## How it worksThis is a **CPU orchestrator**, not a model host. Every heavy stage runs on adiff --git a/workers/garment-forge/lib/skin-transfer.mjs b/workers/garment-forge/lib/skin-transfer.mjsindex 6355af56c..c271b5971 100644--- a/workers/garment-forge/lib/skin-transfer.mjs+++ b/workers/garment-forge/lib/skin-transfer.mjs@@ -1,21 +1,20 @@-// Garment skinning core — fit a generated garment mesh to the canonical body-// and give it skin weights by proximity transfer.+// Garment skinning — TEST-HARNESS / REFERENCE implementation.//-// Generated garment meshes arrive unrigged, at arbitrary scale, centred-// arbitrarily. Auto-riggers are the wrong tool here — they predict skeletons-// for BODIES. The correct treatment for a garment is the one clothing tools-// use: place it around the reference body it will be worn on, then copy each-// garment vertex's skin influence from the nearest point on the body surface.-// The result deforms exactly like the flesh underneath it, which is the-// definition of a well-skinned garment.+// NOT the production skinning lane. The bake-off of 2026-07-25 (same shirt,+// parametric base, canonical walk.json, scripts/garment-rig-bakeoff.mjs)+// measured cloth-to-body deviation across the gait://-// The reference body is the platform's CC0 parametric base-// (public/avatars/parametric-base.glb, mixamorig 52-bone skeleton — every name-// canonicalizes via src/glb-canonicalize.js, so the emitted garment satisfies-// `rig.skeleton: "three.ws-canonical-v1"` in specs/GARMENT_MANIFEST.md).+// rig-worker lane (production, main.py rig_composite): mean 2.87 cm, p95 6.36 cm+// this proximity lane: mean 5.88 cm, p95 13.06 cm//-// Pure module: operates on @gltf-transform Documents, no HTTP, no GCS — fully-// unit-testable (tests/garment-forge-skin-transfer.test.js).+// The rig-worker path won decisively and the worker uses it exclusively. This+// module is retained for one purpose: tests/garment-forge-skin-transfer.test.js+// builds synthetic wearables with it offline (no GPU, no network) to prove the+// runtime binder (src/avatar-garment.js attachGarment) accepts any conforming+// `three.ws-canonical-v1` garment at MIN_BIND_COVERAGE. If the contract test+// gains a committed fixture from the production lane, delete this file.+//+// Pure module: operates on @gltf-transform Documents — fully unit-testable.import { canonicalizeBoneName } from '../../../src/glb-canonicalize.js';import { REGION_BONES, BODY_REGIONS } from '../../../src/garment-taxonomy.js';@@ -462,14 +461,26 @@ export function transferSkinWeights(garmentMesh, bodyDoc, doc) {/* ── occludes derivation ─────────────────────────────────────────────────── */+/** Mirror of SLOT_OCCLUDABLE in garment_glb.py: regions a slot may hide at+ * all. Evidence decides within this set — a top can never hide feet. */+export const SLOT_OCCLUDABLE = Object.freeze({+ top: ['torso', 'upperArms', 'lowerArms', 'neck', 'hips', 'upperLegs'],+ outerwear: ['torso', 'upperArms', 'lowerArms', 'neck', 'hips', 'upperLegs'],+ bottom: ['hips', 'upperLegs', 'lowerLegs'],+ footwear: ['feet', 'lowerLegs'],+ hair: ['scalp'],+ headwear: ['scalp'],+ glasses: [],+ accessory: [],+});+/*** Which body regions this garment covers, measured from where its transferred- * skin weight actually landed. A region counts as covered once it carries at- * least `threshold` of the garment's total weight — deliberately low, because- * the spec says over-declare (hidden skin is invisible, exposed skin is the- * artefact). The slot's own regions are always included as a floor.+ * skin weight actually landed. Two gates, matching garment_glb.py: evidence+ * (≥ threshold of total weight — 10%, because a waistband graze at a few+ * percent must not amputate the pelvis) and per-slot plausibility.*/-export function deriveOccludes(garmentMesh, skin, slot, threshold = 0.05) {+export function deriveOccludes(garmentMesh, skin, slot, threshold = 0.1) {const names = canonicalJointNames(skin);const regionOf = new Map();for (const [region, bones] of Object.entries(REGION_BONES)) {@@ -491,11 +502,12 @@ export function deriveOccludes(garmentMesh, skin, slot, threshold = 0.05) {}}+ const allowed = new Set(SLOT_OCCLUDABLE[slot] || BODY_REGIONS);const out = new Set(SLOT_REGIONS[slot] || []);if (total > 0) {for (const [region, w] of perRegion) {if (w / total >= threshold) out.add(region);}}- return BODY_REGIONS.filter((r) => out.has(r));+ return BODY_REGIONS.filter((r) => out.has(r) && allowed.has(r));}