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
Rigging: canonicalize Rigify/Blender anatomical arm chains (forearm + shoulder collision)
nirholas70ed4b8069a7
diff --git a/src/glb-canonicalize.js b/src/glb-canonicalize.jsindex e0c83b32e..14930cbed 100644--- a/src/glb-canonicalize.js+++ b/src/glb-canonicalize.js@@ -137,6 +137,12 @@ const EXTRA_ALIASES = (() => {const SIDED = [['leftUpperArm', 'LeftArm'], ['lUpperArm', 'LeftArm'], ['shoulderL', 'LeftArm'], ['lShldr', 'LeftArm'], ['lShldrBend', 'LeftArm'],['leftLowerArm', 'LeftForeArm'], ['lLowerArm', 'LeftForeArm'], ['elbowL', 'LeftForeArm'], ['lForeArm', 'LeftForeArm'], ['lForearmBend', 'LeftForeArm'],+ // Rigify/Blender anatomical spelling (`forearm.L`, `upper_arm.L`) — the side+ // is a `.L`/`.R` SUFFIX, so it normalises to `forearml`, which none of the+ // side-PREFIX spellings above (`lForeArm`, `lLowerArm`) reach. Without this+ // the elbow bone drops and every Rigify-rigged character (Quaternius, many+ // Blender exports) animates with a rigid, unbending forearm.+ ['forearmL', 'LeftForeArm'], ['upperArmL', 'LeftArm'],['wristL', 'LeftHand'], ['lHand', 'LeftHand'],['lCollar', 'LeftShoulder'], ['collarL', 'LeftShoulder'], ['lClavicle', 'LeftShoulder'],['leftUpperLeg', 'LeftUpLeg'], ['lUpperLeg', 'LeftUpLeg'], ['hipL', 'LeftUpLeg'], ['lThigh', 'LeftUpLeg'], ['lThighBend', 'LeftUpLeg'],@@ -245,18 +251,53 @@ export function canonicalizeJointNodes(json) {for (const idx of skin.joints) jointIndices.add(idx);}}- let renamed = 0;- const samples = [];+ // Pass 1: resolve each joint to a canonical target (or null).+ const plan = [];+ const targetCount = new Map();for (const idx of jointIndices) {const node = json.nodes[idx];if (!node || typeof node.name !== 'string') continue;const canonical = canonicalizeBoneName(node.name);- if (canonical && canonical !== node.name) {- if (samples.length < 5) samples.push({ from: node.name, to: canonical });- node.name = canonical;- renamed++;+ if (!canonical || canonical === node.name) continue;+ plan.push({ node, raw: node.name, canonical });+ targetCount.set(canonical, (targetCount.get(canonical) || 0) + 1);+ }++ // Pass 1.5: collision-aware shoulder/upper-arm split. Rigify and other+ // anatomical rigs name the clavicle `shoulder.L` and the upper arm+ // `upper_arm.L`; both normalise onto `LeftArm`, so two joints would take the+ // same name and the clip's arm rotation would bind to the clavicle instead of+ // the upper arm (arm swings from the shoulder blade). When an Arm target is+ // contested and one contender is clavicle-spelled, demote it to the Shoulder+ // bone (which the clip library also drives) — but only if Shoulder is free, so+ // this can never fire on a rig that doesn't actually have the collision.+ const isClavicle = (raw) => /shoulder|clavicle|collar/i.test(raw);+ const isUpperArm = (raw) => /upper.?arm|upperarm/i.test(raw);+ for (const side of ['Left', 'Right']) {+ const arm = `${side}Arm`;+ const shoulder = `${side}Shoulder`;+ if ((targetCount.get(arm) || 0) < 2 || (targetCount.get(shoulder) || 0) > 0) continue;+ const contenders = plan.filter((p) => p.canonical === arm);+ const hasUpperArm = contenders.some((p) => isUpperArm(p.raw));+ if (!hasUpperArm) continue;+ for (const p of contenders) {+ if (isClavicle(p.raw) && !isUpperArm(p.raw)) {+ p.canonical = shoulder;+ targetCount.set(arm, targetCount.get(arm) - 1);+ targetCount.set(shoulder, 1);+ break;+ }}}++ // Pass 2: apply.+ let renamed = 0;+ const samples = [];+ for (const p of plan) {+ if (samples.length < 5) samples.push({ from: p.raw, to: p.canonical });+ p.node.name = p.canonical;+ renamed++;+ }return { renamed, samples };}diff --git a/tests/glb-canonicalize.test.js b/tests/glb-canonicalize.test.jsindex 7f2ae8938..5542e6c7a 100644--- a/tests/glb-canonicalize.test.js+++ b/tests/glb-canonicalize.test.js@@ -385,6 +385,21 @@ describe('canonicalizeBoneName', () => {expect(canonicalizeBoneName(input)).toBe(expected);});+ // Rigify / Blender anatomical arm chain: side is a `.L`/`.R` suffix and the+ // forearm is spelled `forearm` (not `lowerarm`/`elbow`). The suffix normalises+ // to `forearml`, which the side-prefix spellings never reach — so before the+ // alias was added the elbow dropped and Rigify characters (Quaternius, many+ // Blender exports) animated with a rigid forearm.+ it.each([+ ['forearm.L', 'LeftForeArm'],+ ['forearm.R', 'RightForeArm'],+ ['DEF-forearm.L', 'LeftForeArm'],+ ['DEF-upper_arm.L','LeftArm'],+ ['upper_arm.R', 'RightArm'],+ ])('maps Rigify/Blender anatomical arm bones: %s → %s', (input, expected) => {+ expect(canonicalizeBoneName(input)).toBe(expected);+ });+it('only strips the suffix when the plain form does not already resolve', () => {// A genuinely numbered finger bone must keep its index — the un-stripped// form resolves first, so we never reach the suffix strip.@@ -418,6 +433,40 @@ describe('canonicalizeJointNodes (in-place rewrite)', () => {expect(samples[0]).toEqual({ from: 'mixamorig:Hips', to: 'Hips' });});+ it('splits a Rigify shoulder/upper-arm collision (clavicle → Shoulder, upper arm → Arm)', () => {+ // Both `shoulder.L` (clavicle) and `upper_arm.L` normalise onto LeftArm.+ // Without collision resolution two joints take the name LeftArm and the arm+ // clip binds to the clavicle. The resolver demotes the clavicle to Shoulder.+ const json = {+ nodes: [+ { name: 'DEF-hips' },+ { name: 'DEF-shoulder.L' }, { name: 'DEF-upper_arm.L' }, { name: 'DEF-forearm.L' }, { name: 'DEF-hand.L' },+ { name: 'DEF-shoulder.R' }, { name: 'DEF-upper_arm.R' }, { name: 'DEF-forearm.R' }, { name: 'DEF-hand.R' },+ ],+ skins: [{ joints: [0, 1, 2, 3, 4, 5, 6, 7, 8] }],+ };+ canonicalizeJointNodes(json);+ const names = json.nodes.map((n) => n.name);+ expect(names.filter((n) => n === 'LeftArm')).toHaveLength(1);+ expect(names.filter((n) => n === 'LeftShoulder')).toHaveLength(1);+ expect(names.filter((n) => n === 'LeftForeArm')).toHaveLength(1);+ expect(names.filter((n) => n === 'RightArm')).toHaveLength(1);+ expect(names.filter((n) => n === 'RightShoulder')).toHaveLength(1);+ });++ it('does NOT invent a Shoulder when there is no collision (simple rig: shoulder = the arm)', () => {+ // A simple 3-joint rig names its upper arm `shoulderL` and has no separate+ // upper-arm bone — so shoulder must stay LeftArm, never demote to Shoulder.+ const json = {+ nodes: [{ name: 'Hips' }, { name: 'shoulderL' }, { name: 'elbowL' }, { name: 'wristL' }],+ skins: [{ joints: [0, 1, 2, 3] }],+ };+ canonicalizeJointNodes(json);+ const names = json.nodes.map((n) => n.name);+ expect(names).toContain('LeftArm');+ expect(names).not.toContain('LeftShoulder');+ });+it('returns 0 when the rig is already canonical', () => {const json = {nodes: [{ name: 'Hips' }, { name: 'Spine' }, { name: 'LeftArm' }],