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
fix(animation): give the Animation Studio the A-pose re-aim the viewer already had
nirholas7ee7a049c48c
diff --git a/packages/retarget/README.md b/packages/retarget/README.mdindex 42ea84976..3593f852e 100644--- a/packages/retarget/README.md+++ b/packages/retarget/README.md@@ -79,7 +79,7 @@ The clip URLs above are real: three.ws serves its shared clip library with open**Canonicalize** (`glb-canonicalize`):| Export | What it does || --- | --- |-| `CANONICAL_BONES` | The frozen 53-bone canonical humanoid set |+| `CANONICAL_BONES` | The frozen 52-bone canonical humanoid set || `canonicalizeBoneName(name)` | One bone name → canonical name (or passthrough) || `canonicalizeJointNodes(json)` | Rename joints across a parsed glTF JSON tree || `canonicalizeArmatureOrientation(json)` | Normalize armature up-axis quirks |diff --git a/src/animation-retarget.js b/src/animation-retarget.jsindex c5e0b1f18..ecb02f078 100644--- a/src/animation-retarget.js+++ b/src/animation-retarget.js@@ -834,6 +834,9 @@ export function retargetClipToRig(clip, rig, opts = {}) {const map = canonicalNodeMapFromRig(rig);const targetRest = canonicalRestMapFromRig(rig);const targetWorldRest = canonicalWorldRestMapFromRig(rig);+ // Same re-aim the viewer and server paths apply, so an A-posed rig previewed+ // or exported from the Animation Studio keeps its arms out of the torso.+ const targetRestDirections = canonicalRestDirectionMapFromRig(rig);let hipScale = 1;if (opts.scaleHips !== false) {const targetY = hipRestHeight(rig);@@ -857,6 +860,7 @@ export function retargetClipToRig(clip, rig, opts = {}) {minCoverage: opts.minCoverage,targetRest,targetWorldRest,+ targetRestDirections,hipsParentWorldQuat: hipsParent,morphTargets: opts.morphTargets ?? (rig.root ? morphTargetMapFromObject(rig.root) : undefined),});diff --git a/tests/animation-retarget-rig-parity.test.js b/tests/animation-retarget-rig-parity.test.jsnew file mode 100644index 000000000..4e08044f1--- /dev/null+++ b/tests/animation-retarget-rig-parity.test.js@@ -0,0 +1,76 @@+// The Animation Studio (/pose) previews and exports clips through+// retargetClipToRig, while the viewer and the server go through retargetClip+// with the rig's limb rest directions. The A-pose re-aim (commit 8561d5c5d)+// reached only the second pair, so an A-posed body animated correctly on its+// page and drove its arms through the torso in the studio and in the GLB it+// exported. Both entry points must produce the same tracks for the same rig.++import { describe, it, expect, beforeAll } from 'vitest';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';+import { parseClipJSON, retargetClipToObject, retargetClipToRig } from '../src/animation-retarget.js';+import { makeGltfRig } from '../src/pose-rig.js';++// MakeHuman-derived: rests in an A-pose with bent elbows, the case the re-aim exists for.+const GLB_PATH = resolve(process.cwd(), 'public/avatars/parametric-base.glb');++function loadScene() {+ const bytes = readFileSync(GLB_PATH);+ return new Promise((res, rej) => {+ new GLTFLoader().parse(+ bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),+ '',+ (gltf) => res(gltf.scene),+ rej,+ );+ });+}++const loadClip = (name) =>+ parseClipJSON(+ JSON.parse(readFileSync(resolve(process.cwd(), `public/animations/clips/${name}.json`), 'utf8')),+ name,+ );++const LIMBS = ['LeftArm', 'LeftForeArm', 'RightArm', 'RightForeArm', 'LeftUpLeg', 'RightUpLeg'];++let objectScene;+let rigScene;++beforeAll(async () => {+ [objectScene, rigScene] = await Promise.all([loadScene(), loadScene()]);+});++describe('retargetClipToRig matches the viewer path on an A-posed rig', () => {+ for (const clipName of ['idle', 'walk']) {+ it(`${clipName}: limb tracks agree`, () => {+ const viaObject = retargetClipToObject(loadClip(clipName), objectScene).clip;+ const rig = makeGltfRig(rigScene);+ expect(rig).not.toBeNull();+ const viaRig = retargetClipToRig(loadClip(clipName), rig, { scaleHips: false }).clip;+ expect(viaObject).not.toBeNull();+ expect(viaRig).not.toBeNull();++ const byName = (clip) => new Map(clip.tracks.map((t) => [t.name, t]));+ const a = byName(viaObject);+ const b = byName(viaRig);+ let compared = 0;+ for (const [name, track] of a) {+ if (!name.endsWith('.quaternion')) continue;+ if (!LIMBS.some((bone) => name.toLowerCase().includes(bone.toLowerCase()))) continue;+ const other = b.get(name);+ expect(other, name).toBeDefined();+ expect(other.values.length).toBe(track.values.length);+ // q and -q are the same rotation; compare by |dot| per keyframe.+ for (let i = 0; i < track.values.length; i += 4) {+ let dot = 0;+ for (let k = 0; k < 4; k++) dot += track.values[i + k] * other.values[i + k];+ expect(Math.abs(dot), `${name} key ${i / 4}`).toBeGreaterThan(0.9999);+ }+ compared++;+ }+ expect(compared).toBeGreaterThanOrEqual(LIMBS.length);+ });+ }+});