Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
CH1a: the old character SDK names SOMA's joints. sdk/character bones.ts B gives SOMA's names (Hips, Spine1, Spine2, Chest, Neck1, Head, LeftShoulder, LeftArm, LeftForeArm, LeftHand, LeftLeg, LeftShin, LeftFoot, LeftToeBase; a finger's phalanges 1 to 3 as SOMA's 2 to 4, the thumb's 1 to 3), BODY_JOINTS is SOMA's 23 with Neck2. Bodies on the old game_engine rig still load: joint() finds a SOMA name by its old one and an old name on a SOMA body (somaName, oldName, sameJoint), the side, mirror, role and finger helpers read both, captured() takes the body's own count or stops at the first joint that isn't the body's, and retarget's BVH maps keyed by old names still map. A body named as CMU or Mixamo name theirs (LeftUpLeg, their LeftLeg being the shin) is refused with a message instead of read wrong. systems/body Skeleton::joint reads a SOMA name on an old body the same way. The conformance stick body is on SOMA's names; a new test checks both names find one joint and the two turn into each other; character.test 27 of 29 pass, the 2 that fail failing the same way before the change
shinyobjectzdc8038add169
diff --git a/sdk/character/src/character.tsx b/sdk/character/src/character.tsxindex d981efd3..30462e40 100644--- a/sdk/character/src/character.tsx+++ b/sdk/character/src/character.tsx@@ -13,7 +13,7 @@// Every joint's rest frame is the world's (the T-pose the skin is bound in, no bone roll), so a joint's turn is the same// kind of thing a BVH file gives: a rotation from rest, relative to its parent's. Frame-pure: a pose is a function of// its inputs, so a render and a live play agree.-export { I, handRest, B, SIDES, BODY_JOINTS, FINGER_JOINTS, sideOf, mirrorName, roleOf, isFinger, skinJoints, add, sub, scale3, dot, cross, len, norm, qmul, qinv, qnorm, qrot, qaxis, qfromTo, slerp, qbasis, eulerXYZ, qyaw, joint, bodyScale, captured, rest, pose, withFingers, setWorld, held, aim, twoBone, softElbows, flatHand, cupHand, ballInHand, palmAt, handAlong, palmFacing, FINGERS, fingerJoints, HAND_LIMITS, RELAXED_HAND, RELAXED_CAPTURE, relaxHands, handPose, capturedHand, HAND_POSES, capturedLocal, alongPath, pathHand, pinchPoint, SKIN_GIVE, closeOn, fingerSegments, surface, handSurface, reach, plant, lookAt, sit, blend, leanToward, solve, toBody, toScene, goalsToBody, registerBody, Character, FACE_UNITS, FACE_PRESETS, faceWeights, HAIR_LOOK, HAIR_WESL, SKIN_LOOK, SKIN_SURFACE, SKIN_WESL } from "./character/all";+export { I, handRest, B, SIDES, BODY_JOINTS, FINGER_JOINTS, sideOf, mirrorName, roleOf, isFinger, somaName, oldName, sameJoint, skinJoints, add, sub, scale3, dot, cross, len, norm, qmul, qinv, qnorm, qrot, qaxis, qfromTo, slerp, qbasis, eulerXYZ, qyaw, joint, bodyScale, captured, rest, pose, withFingers, setWorld, held, aim, twoBone, softElbows, flatHand, cupHand, ballInHand, palmAt, handAlong, palmFacing, FINGERS, fingerJoints, HAND_LIMITS, RELAXED_HAND, RELAXED_CAPTURE, relaxHands, handPose, capturedHand, HAND_POSES, capturedLocal, alongPath, pathHand, pinchPoint, SKIN_GIVE, closeOn, fingerSegments, surface, handSurface, reach, plant, lookAt, sit, blend, leanToward, solve, toBody, toScene, goalsToBody, registerBody, Character, FACE_UNITS, FACE_PRESETS, faceWeights, HAIR_LOOK, HAIR_WESL, SKIN_LOOK, SKIN_SURFACE, SKIN_WESL } from "./character/all";export type { Quat, Joint, Skeleton, Pose, Posed, Side, Finger, HandShape, Closing, FingerSegment, SurfacePoint, HandGoal, FootGoal, SeatGoal, Goals, Placement, CharacterProps, CharacterGhost, FaceUnit, FacePreset, Face, HairLook } from "./character/all";diff --git a/sdk/character/src/character/bones.ts b/sdk/character/src/character/bones.tsindex 2bef97d3..fc5f1bb7 100644--- a/sdk/character/src/character/bones.ts+++ b/sdk/character/src/character/bones.ts@@ -1,65 +1,112 @@-// The joints' names: MakeHuman's game_engine rig (Unreal's mannequin names), raea's one character skeleton-// (docs/skeleton.feature SK0a). Every part of the SDK names joints through these, never with string literals.+// The joints' names: SOMA's (NVlabs/SOMA-X, Apache-2.0), raea's one character skeleton (docs/character.feature CH1,+// CH12). Every part of the SDK names joints through these, never with string literals.+//+// Bodies made before SOMA name their joints as MakeHuman's game_engine rig does (Unreal's mannequin names: pelvis,+// thigh_l, index_02_r). They still play: `joint` finds a SOMA name on such a body by its old name, and the helpers+// below read a name in either form. `oldName` and `somaName` turn one into the other (raea-sys-body rig.rs `rename`+// is the same table). SOMA has a second neck joint (Neck2) and a bone in the palm for each finger (Index1..Pinky1),+// which an old body has none for: they ride their parents.export type Side = "L" | "R";export const SIDES: readonly Side[] = ["L", "R"];-/** the suffix a side's joints carry */-const sx = (s: Side) => (s === "L" ? "l" : "r");+/** the prefix a side's joints carry */+const px = (s: Side) => (s === "L" ? "Left" : "Right");export const FINGERS = ["thumb", "index", "middle", "ring", "pinky"] as const;export type Finger = (typeof FINGERS)[number];+const cap = (f: string) => f[0].toUpperCase() + f.slice(1);+/** Joint names, by role. A body's joints are the trunk, then each arm and leg; the fingers come after all of them. */export const B = {- pelvis: "pelvis",- /** the spine from the pelvis up: spine_01 (the waist), spine_02, spine_03 (the chest, which the clavicles and neck hang from) */- spine: ["spine_01", "spine_02", "spine_03"] as const,- chest: "spine_03",- neck: "neck_01",- head: "head",- clavicle: (s: Side) => `clavicle_${sx(s)}`,- upperarm: (s: Side) => `upperarm_${sx(s)}`,- lowerarm: (s: Side) => `lowerarm_${sx(s)}`,- hand: (s: Side) => `hand_${sx(s)}`,- thigh: (s: Side) => `thigh_${sx(s)}`,- calf: (s: Side) => `calf_${sx(s)}`,- foot: (s: Side) => `foot_${sx(s)}`,+ pelvis: "Hips",+ /** the spine from the hips up: Spine1 (the waist), Spine2, Chest (which the shoulders and neck hang from) */+ spine: ["Spine1", "Spine2", "Chest"] as const,+ chest: "Chest",+ /** the neck's first joint (SOMA's second, Neck2, rides it unless something turns it) */+ neck: "Neck1",+ head: "Head",+ clavicle: (s: Side) => `${px(s)}Shoulder`,+ upperarm: (s: Side) => `${px(s)}Arm`,+ lowerarm: (s: Side) => `${px(s)}ForeArm`,+ hand: (s: Side) => `${px(s)}Hand`,+ thigh: (s: Side) => `${px(s)}Leg`,+ calf: (s: Side) => `${px(s)}Shin`,+ foot: (s: Side) => `${px(s)}Foot`,/** the ball of the foot, where the toes bend */- ball: (s: Side) => `ball_${sx(s)}`,- /** a finger's phalanx k (1 at the knuckle, 3 at the tip; the thumb's 1 is its metacarpal) */- finger: (f: Finger, k: 1 | 2 | 3, s: Side) => `${f}_0${k}_${sx(s)}`,+ ball: (s: Side) => `${px(s)}ToeBase`,+ /** a finger's phalanx k (1 at the knuckle, 3 at the tip; the thumb's 1 is its metacarpal): SOMA's 2 to 4 for a+ * finger (its 1 is the bone in the palm), 1 to 3 for the thumb */+ finger: (f: Finger, k: 1 | 2 | 3, s: Side) => `${px(s)}Hand${cap(f)}${f === "thumb" ? k : k + 1}`,arm: (s: Side) => [B.upperarm(s), B.lowerarm(s), B.hand(s)],leg: (s: Side) => [B.thigh(s), B.calf(s), B.foot(s)],/** both feet's ankles then both balls: L foot, R foot, L ball, R ball */feet: () => [B.foot("L"), B.foot("R"), B.ball("L"), B.ball("R")],};-/** The body's joints in skeleton order (parents first): what a clip turns. */+/** The body's joints in skeleton order (parents first): what a clip turns. SOMA's 23; an old body has 22 (no Neck2). */export const BODY_JOINTS: readonly string[] = [- B.pelvis, ...B.spine, B.neck, B.head,+ B.pelvis, ...B.spine, B.neck, "Neck2", B.head,...SIDES.flatMap((s) => [B.clavicle(s), B.upperarm(s), B.lowerarm(s), B.hand(s)]),...SIDES.flatMap((s) => [B.thigh(s), B.calf(s), B.foot(s), B.ball(s)]),];-/** The fingers' joints in skeleton order, after the body's: each side's thumb, index, middle, ring, pinky, 1 to 3. */+/** The fingers' joints a hand pose turns: each side's thumb, index, middle, ring, pinky, 1 to 3. */export const FINGER_JOINTS: readonly string[] = SIDES.flatMap((s) => FINGERS.flatMap((f) => ([1, 2, 3] as const).map((k) => B.finger(f, k, s))));+// ---------------------------------------------------------------- the old names++const TRUNK: [string, string][] = [["pelvis", "Hips"], ["spine_01", "Spine1"], ["spine_02", "Spine2"], ["spine_03", "Chest"], ["neck_01", "Neck1"], ["head", "Head"]];+const LIMB: [string, string][] = [["clavicle", "Shoulder"], ["upperarm", "Arm"], ["lowerarm", "ForeArm"], ["hand", "Hand"], ["thigh", "Leg"], ["calf", "Shin"], ["foot", "Foot"], ["ball", "ToeBase"]];++/** a game_engine name ("thigh_l", "index_02_r", "spine_03") as SOMA names that joint; any other name as it is */+export function somaName(name: string): string {+ const t = TRUNK.find((p) => p[0] === name);+ if (t) return t[1];+ const m = /^(.+)_([lr])$/.exec(name);+ if (!m) return name;+ const side = m[2] === "l" ? "Left" : "Right", l = LIMB.find((p) => p[0] === m[1]);+ if (l) return side + l[1];+ const f = /^(thumb|index|middle|ring|pinky)_0([123])$/.exec(m[1]);+ return f ? `${side}Hand${cap(f[1])}${Number(f[2]) + (f[1] === "thumb" ? 0 : 1)}` : name;+}++/** a SOMA name as the game_engine rig names that joint, where it has one; any other name as it is */+export function oldName(name: string): string {+ const t = TRUNK.find((p) => p[1] === name);+ if (t) return t[0];+ const m = /^(Left|Right)(.+)$/.exec(name);+ if (!m) return name;+ const sx = m[1] === "Left" ? "l" : "r", l = LIMB.find((p) => p[1] === m[2]);+ if (l) return `${l[0]}_${sx}`;+ const f = /^Hand(Thumb|Index|Middle|Ring|Pinky)([1-4])$/.exec(m[2]);+ if (!f) return name;+ const k = Number(f[2]) - (f[1] === "Thumb" ? 0 : 1);+ return k >= 1 && k <= 3 ? `${f[1].toLowerCase()}_0${k}_${sx}` : name;+}++/** whether two names are one joint, either written either way */+export const sameJoint = (a: string, b: string): boolean => a === b || somaName(a) === somaName(b);+/** a joint's side from its name ("" on the midline) */export function sideOf(name: string): Side | "" {- return name.endsWith("_l") ? "L" : name.endsWith("_r") ? "R" : "";+ return name.startsWith("Left") || name.endsWith("_l") ? "L" : name.startsWith("Right") || name.endsWith("_r") ? "R" : "";}/** a joint's name on the other side (itself on the midline) */export function mirrorName(name: string): string {+ if (name.startsWith("Left")) return "Right" + name.slice(4);+ if (name.startsWith("Right")) return "Left" + name.slice(5);return name.endsWith("_l") ? name.slice(0, -1) + "r" : name.endsWith("_r") ? name.slice(0, -1) + "l" : name;}-/** a joint's role, its name without the side: "thigh", "index_02", "spine_01" */+/** a joint's role, its name without the side: "Leg", "HandIndex3", "Spine1" (an old name's: "thigh", "index_02") */export function roleOf(name: string): string {- return name.replace(/_[lr]$/, "");+ return name.replace(/^(Left|Right)/, "").replace(/_[lr]$/, "");}-export const isFinger = (name: string): boolean => FINGERS.some((f) => name.startsWith(f + "_"));+/** whether a joint is a finger's (either naming; the bone in the palm and the tip's end joint count) */+export const isFinger = (name: string): boolean => /^(Left|Right)Hand(Thumb|Index|Middle|Ring|Pinky)/.test(name) || FINGERS.some((f) => name.startsWith(f + "_"));diff --git a/sdk/character/src/character/core.ts b/sdk/character/src/character/core.tsindex f0c86a31..0bc1c8b5 100644--- a/sdk/character/src/character/core.ts+++ b/sdk/character/src/character/core.ts@@ -27,6 +27,11 @@ export interface Skeleton {/** samples of the skin's surface: each a rest vertex of body.glb, its offset `o` from joint j[0]'s head, its normal* `n` at rest, and its joints `j` and weights `w` as the glb skins it */surface?: { part: string; side: Side | ""; j: number[]; w: number[]; o: Vec3; n: Vec3 }[];+ /** how many of the joints (from the first) a capture turns, when the body says: a SOMA body's 23 */+ captured?: number;+ /** a SOMA body's rig, and each joint's turn from bind to SOMA's T-pose (what a motion's turns are from) */+ rig?: string;+ tpose?: Record<string, Quat>;}/** The joints at a pose as the skin follows them (each body.glb bone is the joint of its name): each's place anddiff --git a/sdk/character/src/character/fingers.ts b/sdk/character/src/character/fingers.tsindex 9857d8cd..bde9da25 100644--- a/sdk/character/src/character/fingers.ts+++ b/sdk/character/src/character/fingers.ts@@ -1,12 +1,12 @@// Fingers: hand shapes and closing on a thing.import { type Vec3 } from "@raea/render/3d";-import { B, FINGERS, Finger, FingerSegment, alongPath, captured, capturedHand, I, pathHand, Pose, Posed, Quat, Side, Skeleton, add, cross, dot, fingerSegments, handRest, joint, norm, place, pose, qaxis, qmul, qrot, scale3, slerp, sub, surface, withFingers } from "./all";+import { B, FINGERS, Finger, sameJoint, FingerSegment, alongPath, captured, capturedHand, I, pathHand, Pose, Posed, Quat, Side, Skeleton, add, cross, dot, fingerSegments, handRest, joint, norm, place, pose, qaxis, qmul, qrot, scale3, slerp, sub, surface, withFingers } from "./all";// ---------------------------------------------------------------- fingers/** Each finger's own joints on a side (thumb first), phalanx 1 to 3; empty for a skeleton without them. */export function fingerJoints(skel: Skeleton, s: Side): number[][] {- if (!skel.joints.some((j) => j.name === B.finger("index", 1, s))) return [];+ if (!skel.joints.some((j) => sameJoint(j.name, B.finger("index", 1, s)))) return [];return FINGERS.map((f) => ([1, 2, 3] as const).map((k) => joint(skel, B.finger(f, k, s))));}diff --git a/sdk/character/src/character/skeleton.ts b/sdk/character/src/character/skeleton.tsindex 23ef676f..4ba2d340 100644--- a/sdk/character/src/character/skeleton.ts+++ b/sdk/character/src/character/skeleton.ts@@ -1,16 +1,23 @@// The skeleton: joints, rest, posing.import { type Vec3 } from "@raea/render/3d";-import { B, I, Pose, Posed, Quat, Skeleton, add, isFinger, qfromTo, qinv, qmul, qnorm, qrot, sub } from "./all";+import { B, BODY_JOINTS, I, Pose, Posed, Quat, Skeleton, add, oldName, qfromTo, qinv, qmul, qnorm, qrot, somaName, sub } from "./all";// ---------------------------------------------------------------- the skeletonconst indexes = new WeakMap<Skeleton, Map<string, number>>();-/** a joint's index by name (throws on a name the skeleton hasn't) */+/** a joint's index by name (throws on a name the skeleton hasn't). A SOMA name finds the joint on a body that names+ * it the old way (bones.ts), and an old name finds it on a SOMA body. */export function joint(skel: Skeleton, name: string): number {let m = indexes.get(skel);- if (!m) indexes.set(skel, (m = new Map(skel.joints.map((j, i) => [j.name, i]))));- const i = m.get(name);+ if (!m) {+ m = new Map(skel.joints.map((j, i) => [j.name, i]));+ // (CMU's and Mixamo's names share SOMA's words for other joints: their LeftLeg is the shin, SOMA's the thigh. A+ // body named so would be read wrong without a word, so it is refused: retarget it onto SOMA first)+ if (m.has("LeftUpLeg")) throw new Error(`character ${skel.name}: its joints are named as CMU's or Mixamo's (LeftUpLeg), which raea doesn't read; raea's bodies are SOMA's (or the old game_engine rig's)`);+ indexes.set(skel, m);+ }+ const i = m.get(name) ?? m.get(oldName(name)) ?? m.get(somaName(name));if (i === undefined) throw new Error(`character ${skel.name}: no joint ${name} (it has ${skel.joints.map((j) => j.name).join(", ")})`);return i;}@@ -24,14 +31,16 @@ export function bodyScale(skel: Skeleton): number {return (d(J(B.thigh("L")), J(B.calf("L"))) + d(J(B.calf("L")), J(B.foot("L")))) / 0.5944;}-/** How many of the skeleton's joints a capture turns: the body's (bones.ts BODY_JOINTS), the fingers' coming after- * them, and a clip's frames have a turn for each of these only. */+/** How many of the skeleton's joints a capture turns: the body's (bones.ts BODY_JOINTS), the rest (a SOMA body's+ * head end, jaw and eyes, every body's fingers) coming after them, and a clip's frames have a turn for each of these+ * only. The body's own count when it gives one; else up to the first joint that isn't one of the body's. */const capturedOf = new WeakMap<Skeleton, number>();+const BODY = new Set(BODY_JOINTS);export function captured(skel: Skeleton): number {let k = capturedOf.get(skel);if (k === undefined) {- k = skel.joints.findIndex((j) => isFinger(j.name));+ k = skel.captured ?? skel.joints.findIndex((j) => !BODY.has(somaName(j.name)));capturedOf.set(skel, (k = k < 0 ? skel.joints.length : k));}return k;diff --git a/sdk/character/src/clips/build.ts b/sdk/character/src/clips/build.tsindex 29b3f81a..729b3a36 100644--- a/sdk/character/src/clips/build.ts+++ b/sdk/character/src/clips/build.ts@@ -83,7 +83,7 @@ export function buildDb(skel: Skeleton, clips: Iterable<BuildClip>, log: (s: strfor (let i = 0; i < NS; i++) S[k * SS + i] = q16((raw[k * C + NF + 5 + i] - stateMean[i]) / stateSd[i]);G[k * 3] = raw[k * C + NF]; G[k * 3 + 1] = raw[k * C + NF + 1]; G[k * 3 + 2] = raw[k * C + NF + 2];}- const ankleRest = skel.joints.find((j) => j.name === B.foot("L"))!.head[1], restHips = skel.joints[0].head[1], hz = bodyScale(skel);+ const ankleRest = skel.joints[joint(skel, B.foot("L"))].head[1], restHips = skel.joints[0].head[1], hz = bodyScale(skel);const hipY = new Float32Array(n0);{ let a = 0; for (const b of rootParts) { hipY.set(b, a); a += b.length; } }const clipBits = metas.map((mt) => { const b: [number, number] = [0, 0]; for (const t of mt.tags) { const i = TAG_INDEX.get(t)!; b[i >> 5] |= 1 << (i & 31); } return b; });diff --git a/sdk/character/src/lint.ts b/sdk/character/src/lint.tsindex 5db65b34..b4516409 100644--- a/sdk/character/src/lint.ts+++ b/sdk/character/src/lint.ts@@ -12,7 +12,7 @@// finding is measured again at every stage of the performance (the clip's frame as chosen, blended in, the feet// planted, the elbows relaxed, the gaze), and the first stage where it shows is the one that made it.import type { Quat } from "raea/character";-import { B, isFinger, sideOf as sideOfJoint, captured, joint, qinv, qmul, qrot, qyaw, type Pose, type Skeleton } from "raea/character";+import { B, SIDES, isFinger, somaName, sideOf as sideOfJoint, captured, joint, qinv, qmul, qrot, qyaw, type Pose, type Skeleton } from "raea/character";import { framePose } from "./clip";import { qlog } from "./effects";import type { MotionLibrary, Performance } from "./matching";@@ -59,6 +59,8 @@ function localTurn(p: Pose, i: number): Quat {const step = (a: Pose, b: Pose, i: number) => qlog(qmul(qinv(localTurn(a, i)), localTurn(b, i)));const DEG = 180 / Math.PI;const watched = (name: string) => !isFinger(name);+/** the joints a foot's plant or the hips' drop can cause a jump on */+const LEGS = new Set([B.pelvis, ...SIDES.flatMap((s) => [B.thigh(s), B.calf(s), B.foot(s), B.ball(s)])]);const refs = new WeakMap<MotionLibrary, { speed: number[]; jerk: number[] }>();/** each joint's 99.5th percentile turn speed and change of speed over the library's frames (degrees a frame) */@@ -110,7 +112,7 @@ export function motionLint(lib: MotionLibrary, perf: Performance, o: { margin?:return kind === "speed" ? Math.max(2, lim.speed[i] * r * m) : Math.max(1.5, lim.jerk[i] * r * r * m * 1.2);};const causes = (t: number, name: string): string[] => {- const out: string[] = [], side = sideOf(name), leg = /^(thigh|calf|foot|ball)_|^pelvis$/.test(name);+ const out: string[] = [], side = sideOf(name), leg = LEGS.has(somaName(name));for (const s of tr.switches) if (Math.abs(s - t) <= 3) out.push(`clip switch @${s}`);if (tr.plant) {for (const e of tr.plant.events) if (Math.abs(e.t - t) <= 3 && leg && (side < 0 || side === e.foot)) out.push(`${e.foot ? "R" : "L"} ${e.what} @${e.t}`);diff --git a/sdk/character/src/retarget.ts b/sdk/character/src/retarget.tsindex 3c6b5b0e..f89c9178 100644--- a/sdk/character/src/retarget.ts+++ b/sdk/character/src/retarget.ts@@ -13,7 +13,7 @@// thumb goes where the source's does (palms down for a source without a thumb). The trunk, neck and head keep their// own build and take the capture's turns from rest. The pelvis travels as the source's hips do, scaled by the hips'// height over the feet.-import { B, SIDES, captured, joint, pose, qaxis, qfromTo, qinv, qmul, qnorm, qrot, slerp, sub, type Quat, type Skeleton } from "raea/character";+import { B, SIDES, captured, oldName, sameJoint, somaName, joint, pose, qaxis, qfromTo, qinv, qmul, qnorm, qrot, slerp, sub, type Quat, type Skeleton } from "raea/character";import type { Vec3 } from "raea/3d";import { clipFrame, type Bvh, type Clip } from "./clip";import { clearOfTrunk, solveFrame, type IkRig } from "./retarget-ik";@@ -70,6 +70,9 @@ function bvhWorld(b: Bvh, f: { root: Vec3; turns: Quat[] }): { rot: Quat[]; pos:}/** The body joint each limb bone aims at (its next joint down the limb), and the bone the hand carries on from. */+/** a body joint's source joint in a BVH map, the map keyed by either naming (bones.ts) */+const mapped = (map: Record<string, string>, name: string): string | undefined => map[name] ?? map[oldName(name)] ?? map[somaName(name)];+const AIM: Record<string, string> = Object.fromEntries(SIDES.flatMap((s) => [[B.clavicle(s), B.upperarm(s)], [B.upperarm(s), B.lowerarm(s)], [B.lowerarm(s), B.hand(s)],[B.thigh(s), B.calf(s)], [B.calf(s), B.foot(s)], [B.foot(s), B.ball(s)],@@ -112,7 +115,7 @@ export function retarget(skel: Skeleton, b: Bvh, o: RetargetOptions): Clip {const fps = o.fps ?? 30, shrug = o.shrug ?? SHRUG;const J = skel.joints.slice(0, captured(skel)), nj = J.length;const srcOf = (name: string) => {- const want = o.map ? o.map[name] : name;+ const want = o.map ? mapped(o.map, name) : name;if (!want) return -1;const i = b.joints.findIndex((x) => x.name === want);if (i < 0 && o.map) throw new Error(`retarget ${o.name}: the map sends ${name} to ${want}, which the BVH hasn't`);@@ -148,14 +151,14 @@ export function retarget(skel: Skeleton, b: Bvh, o: RetargetOptions): Clip {// the rest fix F per jointconst fix: Quat[] = J.map(() => [0, 0, 0, 1] as Quat);const restDir = (i: number): Vec3 => {- const c = J.findIndex((x) => x.parent === i && AIM[J[i].name] === x.name);+ const c = J.findIndex((x) => x.parent === i && AIM[somaName(J[i].name)] === somaName(x.name));return c >= 0 ? sub(J[c].head, J[i].head) : sub(J[i].tail, J[i].head);};J.forEach((j, i) => {- const aim = AIM[j.name];+ const aim = AIM[somaName(j.name)];// (not the clavicles: a capture's shoulder joints sit where its markers put them, ACCAD's sloped 34 degrees and CMU's// nearly level, so a clavicle laid along its source's took that marker set's slope; it moves from the body's own rest)- if (aim !== undefined && src[i] >= 0 && !SIDES.some((s) => j.name === B.clavicle(s))) {+ if (aim !== undefined && src[i] >= 0 && !SIDES.some((s) => sameJoint(j.name, B.clavicle(s)))) {const si = src[joint(skel, aim)];const sd = si >= 0 ? sub(R0[si], R0[src[i]]) : undefined;if (sd && len(sd) > 1e-6) fix[i] = qfromTo(restDir(i), qrot(A, sd));@@ -169,7 +172,7 @@ export function retarget(skel: Skeleton, b: Bvh, o: RetargetOptions): Clip {fix[h] = qfromTo(sub(J[h].tail, J[h].head), sd);}// the forearm and hand twisted about their own length so the thumb goes the source's way (forward if it has none)- const thumbName = o.map?.[B.finger("thumb", 1, s)];+ const thumbName = o.map && mapped(o.map, B.finger("thumb", 1, s));const ti = thumbName ? b.joints.findIndex((x) => x.name === thumbName) : -1;const want: Vec3 = ti >= 0 && b.joints[ti].end ? qrot(A, sub(add3(R0[ti], b.joints[ti].end!), R0[src[h]])) : [0, 0, 1];const thumb0 = sub(skel.joints[joint(skel, B.finger("thumb", 1, s))].head, J[h].head);diff --git a/sdk/raea/conformance/character.test.ts b/sdk/raea/conformance/character.test.tsindex 0cfce7b3..75fd4d4b 100644--- a/sdk/raea/conformance/character.test.ts+++ b/sdk/raea/conformance/character.test.ts@@ -1,9 +1,10 @@// raea/character, clip and matching under plain bun: the skeleton's forward kinematics, the goals landing// where they are sent, clips surviving their file format, routes keeping clear, and a performance being a pure-// function of its inputs. The skeleton is a small stand-in on raea's game_engine joints (stick.ts).+// function of its inputs. The skeleton is a small stand-in on SOMA's joints (stick.ts); the tests name joints the old+// game_engine way in places, which `joint` finds on a SOMA body.import { afterAll, beforeAll, describe, expect, test } from "bun:test";import { BevyApp } from "raea/bevy";-import { captured, flatHand, withFingers, len, lookAt, palmAt, plant, pose, qaxis, qrot, reach, rest, softElbows, sub, twoBone, type Skeleton } from "raea/character";+import { B, captured, joint, oldName, somaName, flatHand, withFingers, len, lookAt, palmAt, plant, pose, qaxis, qrot, reach, rest, softElbows, sub, twoBone, type Skeleton } from "raea/character";import { readBvh, readClips, retarget, writeClips } from "raea/clip";import { before, libraryPose, libraryTable, mirror, motionLibrary, perform, planFloor, route, stateMix, through, walkPlan } from "raea/matching";import { applyEffect, clipMeans, learnEffect, mirrorEffect, mixEffects } from "raea/effects";@@ -16,10 +17,20 @@ import { defineRoom, type LaidRun, type Plan } from "raea/room";import type { Vec3 } from "../src/3d";import { mirrorX, names, skel, stickBvh } from "./stick";-const at = (n: string) => names.indexOf(n);+const at = (n: string) => joint(skel, n);const near = (a: Vec3, b: Vec3, tol: number) => expect(len(sub(a, b))).toBeLessThan(tol);describe("the skeleton", () => {+ test("a joint is found by its SOMA name or its old one, and the two names turn into each other", () => {+ expect(names.indexOf(B.thigh("L"))).toBeGreaterThan(0);+ for (const [old, soma] of [["pelvis", "Hips"], ["spine_03", "Chest"], ["thigh_l", "LeftLeg"], ["calf_r", "RightShin"], ["ball_l", "LeftToeBase"], ["thumb_01_l", "LeftHandThumb1"], ["index_01_r", "RightHandIndex2"], ["pinky_03_l", "LeftHandPinky4"]]) {+ expect(at(old)).toBe(at(soma));+ expect(somaName(old)).toBe(soma);+ expect(oldName(soma)).toBe(old);+ }+ expect(names.length).toBe(captured(skel) + 30);+ expect(() => joint({ ...skel, joints: [{ ...skel.joints[0], name: "LeftUpLeg" }] }, "LeftLeg")).toThrow(/CMU/);+ });test("at rest every joint is at its head", () => {const w = withFingers(skel, pose(skel, rest(skel)));skel.joints.forEach((j, i) => near(w.pos[i], j.head, 1e-9));diff --git a/sdk/raea/conformance/stick.ts b/sdk/raea/conformance/stick.tsindex b93d8aff..d526b357 100644--- a/sdk/raea/conformance/stick.ts+++ b/sdk/raea/conformance/stick.ts@@ -1,19 +1,20 @@-// The conformance tests' stick body, and a BVH of it walking: a small stand-in on raea's game_engine joints-// (docs/skeleton.feature SK0a) in a T-pose, shared by character.test.ts, ragdoll.test.ts and the CharacterPlugin-// program (bench/bevy-ts/programs/character.ts).-import { BODY_JOINTS, FINGER_JOINTS, FINGERS, sub, type Skeleton } from "raea/character";+// The conformance tests' stick body, and a BVH of it walking: a small stand-in on SOMA's joints (raea's skeleton,+// docs/character.feature CH1) in a T-pose, shared by character.test.ts, ragdoll.test.ts and the CharacterPlugin+// program (bench/bevy-ts/programs/character.ts). The tests name its joints the old way in places, which `joint`+// reads on a SOMA body too.+import { B, BODY_JOINTS, FINGER_JOINTS, FINGERS, mirrorName, sub, type Skeleton } from "raea/character";import type { Vec3 } from "../src/3d";export const mirrorX = (v: Vec3): Vec3 => [-v[0], v[1], v[2]];// the left side and the midline: [name, parent, head, tail?]; the right side is the left's mirror imageconst LEFT: [string, string | null, Vec3, Vec3?][] = [- ["pelvis", null, [0, 0.65, 0]], ["spine_01", "pelvis", [0, 0.7, 0]], ["spine_02", "spine_01", [0, 0.8, 0]],- ["spine_03", "spine_02", [0, 0.92, 0]], ["neck_01", "spine_03", [0, 1.04, 0]], ["head", "neck_01", [0, 1.1, 0], [0, 1.2, 0]],- ["clavicle_l", "spine_03", [0.02, 0.99, 0]], ["upperarm_l", "clavicle_l", [0.12, 0.98, 0]], ["lowerarm_l", "upperarm_l", [0.34, 0.98, 0]],- ["hand_l", "lowerarm_l", [0.54, 0.98, 0], [0.6, 0.98, 0]],- ["thigh_l", "pelvis", [0.08, 0.64, 0]], ["calf_l", "thigh_l", [0.09, 0.35, 0.01]], ["foot_l", "calf_l", [0.1, 0.06, 0]],- ["ball_l", "foot_l", [0.1, 0.02, 0.1], [0.1, 0.02, 0.14]],+ ["Hips", null, [0, 0.65, 0]], ["Spine1", "Hips", [0, 0.7, 0]], ["Spine2", "Spine1", [0, 0.8, 0]],+ ["Chest", "Spine2", [0, 0.92, 0]], ["Neck1", "Chest", [0, 1.04, 0]], ["Neck2", "Neck1", [0, 1.07, 0]], ["Head", "Neck2", [0, 1.1, 0], [0, 1.2, 0]],+ ["LeftShoulder", "Chest", [0.02, 0.99, 0]], ["LeftArm", "LeftShoulder", [0.12, 0.98, 0]], ["LeftForeArm", "LeftArm", [0.34, 0.98, 0]],+ ["LeftHand", "LeftForeArm", [0.54, 0.98, 0], [0.6, 0.98, 0]],+ ["LeftLeg", "Hips", [0.08, 0.64, 0]], ["LeftShin", "LeftLeg", [0.09, 0.35, 0.01]], ["LeftFoot", "LeftShin", [0.1, 0.06, 0]],+ ["LeftToeBase", "LeftFoot", [0.1, 0.02, 0.1], [0.1, 0.02, 0.14]],];// each finger's knuckle (z across the hand: the thumb ahead, the pinky behind) and its phalanges' lengthconst KNUCKLE: Record<string, [Vec3, number]> = {@@ -22,22 +23,25 @@ const KNUCKLE: Record<string, [Vec3, number]> = {};for (const f of FINGERS) {const [k, l] = KNUCKLE[f], dir: Vec3 = f === "thumb" ? [0.6, 0, 0.8] : [1, 0, 0];- for (const ph of [1, 2, 3]) {+ for (const ph of [1, 2, 3] as const) {const at = (m: number): Vec3 => [k[0] + dir[0] * l * m, k[1], k[2] + dir[2] * l * m];- LEFT.push([`${f}_0${ph}_l`, ph === 1 ? "hand_l" : `${f}_0${ph - 1}_l`, at(ph - 1), at(ph)]);+ LEFT.push([B.finger(f, ph, "L"), ph === 1 ? B.hand("L") : B.finger(f, (ph - 1) as 1 | 2, "L"), at(ph - 1), at(ph)]);}}const all = new Map<string, [string | null, Vec3, Vec3?]>();for (const [n, p, h, t] of LEFT) {all.set(n, [p, h, t]);- if (n.endsWith("_l")) all.set(n.slice(0, -1) + "r", [p && (p.endsWith("_l") ? p.slice(0, -1) + "r" : p), mirrorX(h), t && mirrorX(t)]);+ if (n.startsWith("Left")) all.set(mirrorName(n), [p && mirrorName(p), mirrorX(h), t && mirrorX(t)]);}+// (a joint's tail is its one child's head, but not a side branch's: the thumb, index, ring and pinky off the hand,+// the thighs off the hips, the shoulders off the chest)+const BRANCH = new Set(["L", "R"].flatMap((s) => [B.finger("thumb", 1, s as "L"), B.finger("index", 1, s as "L"), B.finger("ring", 1, s as "L"), B.finger("pinky", 1, s as "L"), B.thigh(s as "L"), B.clavicle(s as "L")]));export const names = [...BODY_JOINTS, ...FINGER_JOINTS];export const skel: Skeleton = {name: "stick", height: 1.2, landmarks: { eyes: [0, 1.14, 0.08], sitDrop: 0.07 },joints: names.map((n) => {const [p, h, t] = all.get(n)!;- const kid = names.find((c) => all.get(c)![0] === n && !/^(thumb|index|ring|pinky)_01|^thigh|^clavicle/.test(c));+ const kid = names.find((c) => all.get(c)![0] === n && !BRANCH.has(c));return { name: n, parent: p ? names.indexOf(p) : -1, head: h, tail: t ?? (kid ? all.get(kid)![1] : [h[0], h[1] + 0.05, h[2]]) };}),};@@ -67,7 +71,7 @@ export function stickBvh(frames: number, fps = 120, still = false): string {for (const i of order) {const j = skel.joints[i];if (j.parent < 0) row.push(0, 0.65, t * 1.1);- const x = j.name === "thigh_l" ? swing : j.name === "thigh_r" ? -swing : 0;+ const x = j.name === B.thigh("L") ? swing : j.name === B.thigh("R") ? -swing : 0;row.push(0, 0, x);}lines.push(row.join(" "));diff --git a/systems/body/src/rig.rs b/systems/body/src/rig.rsindex 9f02dca0..dace148b 100644--- a/systems/body/src/rig.rs+++ b/systems/body/src/rig.rs@@ -111,8 +111,13 @@ impl Skeleton {/// A joint by its name, or by its role: the roles are spelt as the game_engine rig named its joints ("thigh_l",/// "spine_03", "index_02_r"), and on a SOMA body a role finds SOMA's joint for it (docs/character.feature CH1).+ /// A SOMA name finds the joint on a body named the old way too, as the TypeScript SDK now names joints by SOMA.pub fn joint(&self, name: &str) -> Option<usize> {- self.index.get(name).copied().or_else(|| self.index.get(soma_name(name)?.as_str()).copied())+ self.index+ .get(name)+ .copied()+ .or_else(|| self.index.get(soma_name(name)?.as_str()).copied())+ .or_else(|| self.index.get(rename(name, false)?.as_str()).copied())}fn three(&self, names: [String; 3]) -> Option<[usize; 3]> {