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
Remove obsolete scripts related to fingerspelling and garment probing
nirholas9c5ea277152a
diff --git a/scripts/.scratch/analyze-pose.mjs b/scripts/.scratch/analyze-pose.mjsdeleted file mode 100644index d972b1bb5..000000000--- a/scripts/.scratch/analyze-pose.mjs+++ /dev/null@@ -1,117 +0,0 @@-// Diagnose the signing pose: where do the arm bones actually point on cz.glb?-import fs from 'node:fs';-import { Quaternion, Vector3 } from 'three';-import { canonicalizeBoneName } from '/workspaces/three.ws/src/glb-canonicalize.js';--const file = '/workspaces/three.ws/public/avatars/cz.glb';-const buf = fs.readFileSync(file);-const chunkLen = buf.readUInt32LE(12);-const gltf = JSON.parse(buf.slice(20, 20 + chunkLen).toString('utf8'));-const nodes = gltf.nodes || [];-const parentOf = new Array(nodes.length).fill(-1);-for (let i = 0; i < nodes.length; i++) for (const c of nodes[i]?.children || []) parentOf[c] = i;--const byCanon = new Map();-nodes.forEach((n, i) => {- if (!n?.name) return;- const c = canonicalizeBoneName(n.name);- if (c && !byCanon.has(c)) byCanon.set(c, i);-});--const localQ = (i) => {- const r = nodes[i]?.rotation || [0, 0, 0, 1];- return new Quaternion(r[0], r[1], r[2], r[3]);-};-const localT = (i) => {- const t = nodes[i]?.translation || [0, 0, 0];- return new Vector3(t[0], t[1], t[2]);-};-const worldQ = (i) => {- const q = localQ(i);- for (let p = parentOf[i]; p !== -1; p = parentOf[p]) q.premultiply(localQ(p));- return q;-};-const worldPos = (i) => {- // compose translation + rotation up the chain (no scale on this rig? check)- let p = localT(i);- for (let par = parentOf[i]; par !== -1; par = parentOf[par]) {- p = p.clone().applyQuaternion(localQ(par)).add(localT(par));- }- return p;-};--const show = (name) => {- const i = byCanon.get(name);- if (i === undefined) return console.log(name, 'MISSING');- const wq = worldQ(i);- const wp = worldPos(i);- // child offset direction in world- const kids = nodes[i].children || [];- let dir = null;- if (kids.length) {- const cp = worldPos(kids[0]);- dir = cp.clone().sub(wp).normalize();- }- const ax = (v) => new Vector3(...v).applyQuaternion(wq);- console.log(- name.padEnd(14),- 'node=', nodes[i].name.padEnd(18),- 'pos=', wp.toArray().map((v) => v.toFixed(3)).join(','),- '| childDir=', dir ? dir.toArray().map((v) => v.toFixed(3)).join(',') : '-',- '| localY→', ax([0, 1, 0]).toArray().map((v) => v.toFixed(2)).join(','),- '| localX→', ax([1, 0, 0]).toArray().map((v) => v.toFixed(2)).join(','),- '| localZ→', ax([0, 0, 1]).toArray().map((v) => v.toFixed(2)).join(','),- );-};--console.log('=== cz.glb rest ===');-for (const b of ['Hips', 'Spine', 'Spine1', 'Spine2', 'Neck', 'Head', 'RightShoulder', 'RightArm', 'RightForeArm', 'RightHand', 'RightHandIndex1', 'RightHandIndex2', 'RightHandThumb1', 'LeftShoulder', 'LeftArm', 'LeftForeArm', 'LeftHand'])- show(b);--// ---- now apply the current signingPose locals and see where the arm goes -----const { default: fsMod } = await import('node:fs');-const src = fsMod.readFileSync('/workspaces/three.ws/src/fingerspelling.js', 'utf8');-const mod = await import('/workspaces/three.ws/src/fingerspelling.js');--// Rebuild signingPose via the clip (first keyframe carries RightHand; static bones carry arms)-const clip = mod.buildFingerspellingClip('A');-const poseLocals = {};-for (const t of clip.tracks) {- if (t.type !== 'quaternion') continue;- const bone = t.name.split('.')[0];- poseLocals[bone] = t.values.slice(0, 4);-}--function posedWorld(canon) {- // compose world using posed locals where available, rest otherwise- const chain = [];- let i = byCanon.get(canon);- while (i !== undefined && i !== -1) {- chain.unshift(i);- i = parentOf[i];- }- const q = new Quaternion();- let p = new Vector3();- for (const idx of chain) {- const c = canonicalizeBoneName(nodes[idx].name);- const lq = c && poseLocals[c] ? new Quaternion(...poseLocals[c]) : localQ(idx);- p = p.add(localT(idx).clone().applyQuaternion(q));- q.multiply(lq);- }- return { q, p };-}--console.log('\n=== posed (current signingPose, letter A) ===');-for (const b of ['RightArm', 'RightForeArm', 'RightHand', 'LeftArm', 'LeftForeArm', 'LeftHand']) {- const { q, p } = posedWorld(b);- const i = byCanon.get(b);- const kid = (nodes[i].children || [])[0];- let dir = '-';- if (kid !== undefined) {- // child world pos under posed chain- const childLocal = localT(kid).clone().applyQuaternion(q);- dir = childLocal.clone().normalize().toArray().map((v) => v.toFixed(3)).join(',');- }- const palmNormal = new Vector3(0, 0, 1).applyQuaternion(q);- console.log(b.padEnd(13), 'pos=', p.toArray().map((v) => v.toFixed(3)).join(','), '| boneDir=', dir, '| localZ→', palmNormal.toArray().map((v) => v.toFixed(2)).join(','));-}diff --git a/scripts/.scratch/check-rig.mjs b/scripts/.scratch/check-rig.mjsdeleted file mode 100644index 1d6fa8184..000000000--- a/scripts/.scratch/check-rig.mjs+++ /dev/null@@ -1,37 +0,0 @@-import {- ANCHORS, Pose, boneAxis, boneLength, curlAxis, palmAxis, radialAxis, restDirWorld,- restPalmWorld, restRadialWorld, signPoint, solveArm, splayAxis, vLen, vSub, qRotate, restWorld,-} from '../../src/sign-rig.js';--const f = (v) => (Array.isArray(v) ? v.map((n) => n.toFixed(3)).join(', ') : v.toFixed(3));--console.log('--- derived hand frames ---');-for (const side of ['Right', 'Left']) {- console.log(side, 'palmWorld=', f(restPalmWorld(side)), 'radialWorld=', f(restRadialWorld(side)));-}-console.log('\n--- bone axes (local) / lengths ---');-for (const b of ['RightArm', 'RightForeArm', 'RightHand', 'RightHandIndex1', 'RightHandThumb1', 'LeftArm', 'LeftHand']) {- console.log(b.padEnd(16), 'axis=', f(boneAxis(b)), 'len=', f(boneLength(b)), 'restDir=', f(restDirWorld(b)));-}-console.log('\n--- finger axes ---');-for (const b of ['RightHandIndex1', 'RightHandIndex2', 'LeftHandIndex1', 'RightHandThumb1', 'LeftHandThumb1']) {- console.log(b.padEnd(18), 'palm=', f(palmAxis(b)), 'radial=', f(radialAxis(b)), 'curl=', f(curlAxis(b)), 'splay=', f(splayAxis(b)));-}-console.log('\n--- anchors ---');-for (const k of ['forward', 'shoulderSpan', 'head', 'chin', 'sternum', 'belly']) console.log(k.padEnd(14), f(ANCHORS[k]));-console.log('shoulder R', f(ANCHORS.shoulder.Right));--console.log('\n--- IK: fingerspelling position (right hand beside the chin, palm out) ---');-const target = signPoint('chin', { out: 0.20, up: -0.05, forward: 0.16, side: 'Right' });-const pose = new Pose();-solveArm(pose, 'Right', { wrist: target, fingers: [0, 1, 0], palm: [0, 0, 1] });-const report = (p, side) => {- for (const b of [`${side}Arm`, `${side}ForeArm`, `${side}Hand`, `${side}HandMiddle3`]) {- console.log(b.padEnd(17), 'pos=', f(p.worldPos(b)), 'dir=', f(p.worldDir(b)), 'palm→', f(qRotate(p.worldQuat(b), palmAxis(b.includes('Hand') && !b.endsWith('Arm') ? b : `${side}Hand`))));- }-};-console.log('target wrist ', f(target));-report(pose, 'Right');-console.log('elbow below wrist?', pose.worldPos('RightForeArm')[1] < pose.worldPos('RightHand')[1]);-console.log('hand in front (z>0)?', pose.worldPos('RightHand')[2] > 0);-console.log('wrist error', f(vLen(vSub(pose.worldPos('RightHand'), target))));diff --git a/scripts/.scratch/fingerspelling-old.js b/scripts/.scratch/fingerspelling-old.jsdeleted file mode 100644index 36b094823..000000000--- a/scripts/.scratch/fingerspelling-old.js+++ /dev/null@@ -1,418 +0,0 @@-// ASL fingerspelling clip builder — turn a word into a canonical-skeleton-// animation clip that spells it letter by letter on the dominant (right) hand.-//-// Every handshape is defined parametrically (per-finger curl, splay, a thumb-// preset, optional wrist orientation) and compiled to local joint rotations on-// the canonical bones (RightHandIndex1 … RightHandThumb3 plus the right arm-// chain), emitting the SAME AnimationClip JSON document the animation library-// and the motion-capture lanes produce. That means a spelled word retargets-// onto any rigged avatar through src/animation-retarget.js with zero new-// playback machinery.-//-// Letters with movement (J traces from I, Z traces with the index) carry wrist-// keyframes inside their letter window. Double letters get a small outward-// bounce between the two holds, matching how signers disambiguate them.-//-// Scope note: fingerspelling is the receptive-friendly, deterministic subset-// of sign language — it spells English words; it is not grammatical ASL.-// Lexical sign clips come from the motion-capture lane (video2motion), not-// from this module.--// ── quaternion + vector helpers ([x, y, z, w], matching three.js) ──────────--const IDENT = [0, 0, 0, 1];--function qMul(a, b) {- const [ax, ay, az, aw] = a;- const [bx, by, bz, bw] = b;- return [- aw * bx + ax * bw + ay * bz - az * by,- aw * by - ax * bz + ay * bw + az * bx,- aw * bz + ax * by - ay * bx + az * bw,- aw * bw - ax * bx - ay * by - az * bz,- ];-}--function qConj(q) {- return [-q[0], -q[1], -q[2], q[3]];-}--function qNorm(q) {- const n = Math.hypot(q[0], q[1], q[2], q[3]);- if (n < 1e-8) return [...IDENT];- return [q[0] / n, q[1] / n, q[2] / n, q[3] / n];-}--function qAxisAngle(axis, deg) {- const [x, y, z] = vNorm(axis);- const half = (deg * Math.PI) / 360;- const s = Math.sin(half);- return [x * s, y * s, z * s, Math.cos(half)];-}--function vNorm(v) {- const n = Math.hypot(v[0], v[1], v[2]);- if (n < 1e-8) return [0, 0, 0];- return [v[0] / n, v[1] / n, v[2] / n];-}--function vCross(a, b) {- return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];-}--function vDot(a, b) {- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];-}--function vRot(q, v) {- const p = qMul(qMul(q, [v[0], v[1], v[2], 0]), qConj(q));- return [p[0], p[1], p[2]];-}--function shortestArc(from, to) {- const f = vNorm(from);- const t = vNorm(to);- const d = vDot(f, t);- if (d > 1 - 1e-9) return [...IDENT];- if (d < -1 + 1e-9) {- let axis = vCross(f, [1, 0, 0]);- if (Math.hypot(...axis) < 1e-6) axis = vCross(f, [0, 1, 0]);- const [x, y, z] = vNorm(axis);- return [x, y, z, 0];- }- const axis = vCross(f, t);- return qNorm([axis[0], axis[1], axis[2], 1 + d]);-}--// Orientation carrying rest axes (restDir, restNormal) onto (dir, normal):-// swing to the direction, then a pure twist about it to line up the normal.-function frameQuat(dir, normal, restDir, restNormal) {- const swing = shortestArc(restDir, dir);- const d = vNorm(dir);- let n = vNorm(normal);- n = vNorm([n[0] - d[0] * vDot(n, d), n[1] - d[1] * vDot(n, d), n[2] - d[2] * vDot(n, d)]);- if (Math.hypot(...n) < 1e-5) return swing;- let carried = vRot(swing, restNormal);- carried = vNorm([- carried[0] - d[0] * vDot(carried, d),- carried[1] - d[1] * vDot(carried, d),- carried[2] - d[2] * vDot(carried, d),- ]);- if (Math.hypot(...carried) < 1e-5) return swing;- const twist = shortestArc(carried, n);- const a = vDot([twist[0], twist[1], twist[2]], d);- return qMul(qNorm([d[0] * a, d[1] * a, d[2] * a, twist[3]]), swing);-}--// ── the signing arm pose (right hand raised, palm out, left arm relaxed) ───-//-// Canonical rest is a T-pose (arms along ±X, palms down), so every arm bone-// needs a pose even when "static": zero rotation would leave the avatar-// signing from a T-pose. Locals are derived from target global directions the-// same way the capture solver does it, so they read naturally on any rig.--function chainLocals(side, upperDir, lowerDir, handDir, handNormal) {- const s = side === 'Left' ? 1 : -1;- const rest = [s, 0, 0];- const gUpper = shortestArc(rest, upperDir);- const lowerLocalDir = vRot(qConj(gUpper), lowerDir);- const lowerLocal = shortestArc(rest, lowerLocalDir);- const gLower = qMul(gUpper, lowerLocal);- const gHand = frameQuat(handDir, handNormal, rest, [0, 1, 0]);- const handLocal = qMul(qConj(gLower), gHand);- return {- [`${side}Arm`]: qNorm(gUpper),- [`${side}ForeArm`]: qNorm(lowerLocal),- [`${side}Hand`]: qNorm(handLocal),- [`__g${side}Hand`]: gHand,- [`__g${side}Lower`]: gLower,- };-}--// Right hand up in signing space beside the shoulder: fingers up, palm to the-// viewer (+Z), elbow dropped. The left arm hangs relaxed at the side using-// locals sampled from the baked idle clip's first frame (the library's own-// convention), which reads naturally after the retargeter's bind correction-// where a geometrically-derived "down" did not.-function signingPose() {- const right = chainLocals('Right', vNorm([-0.25, -0.9, 0.3]), vNorm([-0.22, 0.38, 0.9]), [0, 1, 0], [0, 0, -1]);- return {- ...right,- LeftArm: qNorm([0.5402, 0.1202, -0.0234, 0.8326]),- LeftForeArm: qNorm([0.0199, 0.0244, 0.1378, 0.99]),- LeftHand: qNorm([-0.0098, -0.0091, -0.029, 0.9995]),- };-}--// ── handshape model ────────────────────────────────────────────────────────--const FINGERS = ['Index', 'Middle', 'Ring', 'Pinky'];--// Per-joint shares of a full curl (proximal knuckles carry most of it).-const CURL_WEIGHTS = [85, 100, 65];--// Thumb presets, as [joint1, joint2, joint3] rotations composed from curl-// about the thumb hinge and swing toward/away from the palm. Tuned for the-// right hand and mirrored for the left via axis sign.-const THUMB_PRESETS = {- // resting against the index side, pointing along the fingers- side: { adduct: 22, curl: [8, 10, 5] },- // extended away from the palm (L / Y / thumbs-out shapes)- out: { adduct: -55, curl: [0, 0, 0] },- // folded across the palm, under or over the curled fingers- across: { adduct: 55, curl: [30, 45, 30] },- // opposing the fingertips (O / F / D circles)- oppose: { adduct: 40, curl: [18, 30, 22] },- // tip pinned between index and middle (T) / at the middle knuckle (K)- between: { adduct: 38, curl: [22, 30, 15] },-};--// A handshape: curl 0..1 per finger (or [j1,j2,j3] explicit degrees), splay-// in degrees (+ toward the thumb), a thumb preset, an optional wrist offset-// {pitch,yaw,roll} in degrees applied on top of the signing pose, and an-// optional motion ('J' | 'Z') traced inside the letter's time window.-export const LETTER_SHAPES = {- A: { curl: { Index: 1, Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'side' },- B: { curl: {}, thumb: 'across' },- C: { curl: { Index: 0.45, Middle: 0.45, Ring: 0.45, Pinky: 0.45 }, thumb: 'oppose' },- D: { curl: { Middle: 0.7, Ring: 0.7, Pinky: 0.7 }, thumb: 'oppose' },- E: { curl: { Index: 0.85, Middle: 0.85, Ring: 0.85, Pinky: 0.85 }, thumb: 'across' },- F: { curl: { Index: 0.55 }, splay: { Middle: 6, Ring: 0, Pinky: -8 }, thumb: 'oppose' },- G: { curl: { Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'side', wrist: { local: [0, 1, 0], deg: 85 } },- H: { curl: { Ring: 1, Pinky: 1 }, thumb: 'side', wrist: { local: [0, 1, 0], deg: 85 } },- I: { curl: { Index: 1, Middle: 1, Ring: 1 }, thumb: 'across' },- J: { curl: { Index: 1, Middle: 1, Ring: 1 }, thumb: 'across', motion: 'J' },- K: { curl: { Middle: [40, 15, 10], Ring: 1, Pinky: 1 }, thumb: 'between' },- L: { curl: { Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'out' },- M: { curl: { Index: 0.75, Middle: 0.75, Ring: 0.75, Pinky: 0.95 }, thumb: 'across' },- N: { curl: { Index: 0.75, Middle: 0.75, Ring: 0.95, Pinky: 0.95 }, thumb: 'across' },- O: { curl: { Index: 0.55, Middle: 0.55, Ring: 0.55, Pinky: 0.55 }, thumb: 'oppose' },- P: { curl: { Middle: [40, 15, 10], Ring: 1, Pinky: 1 }, thumb: 'between', wrist: { dir: [0.15, -0.85, 0.5], normal: [0, 1, 0.2] } },- Q: { curl: { Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'side', wrist: { dir: [0.15, -0.85, 0.5], normal: [0, 1, 0.2] } },- R: { curl: { Ring: 1, Pinky: 1 }, splay: { Index: -6, Middle: 8 }, thumb: 'across' },- S: { curl: { Index: 1, Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'across' },- T: { curl: { Index: 0.9, Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'between' },- U: { curl: { Ring: 1, Pinky: 1 }, thumb: 'across' },- V: { curl: { Ring: 1, Pinky: 1 }, splay: { Index: 9, Middle: -9 }, thumb: 'across' },- W: { curl: { Pinky: 1 }, splay: { Index: 10, Middle: 0, Ring: -10 }, thumb: 'across' },- X: { curl: { Index: [15, 95, 80], Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'side' },- Y: { curl: { Index: 1, Middle: 1, Ring: 1 }, thumb: 'out' },- Z: { curl: { Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'side', motion: 'Z' },- // ASL number handshapes 0–9 (static). 6–9 touch the thumb to one- // fingertip; the touched finger half-curls to meet the opposing thumb.- 0: { curl: { Index: 0.55, Middle: 0.55, Ring: 0.55, Pinky: 0.55 }, thumb: 'oppose' },- 1: { curl: { Middle: 1, Ring: 1, Pinky: 1 }, thumb: 'across' },- 2: { curl: { Ring: 1, Pinky: 1 }, splay: { Index: 9, Middle: -9 }, thumb: 'across' },- 3: { curl: { Ring: 1, Pinky: 1 }, splay: { Index: 9, Middle: -9 }, thumb: 'out' },- 4: { curl: {}, splay: { Index: 10, Middle: 3, Ring: -4, Pinky: -12 }, thumb: 'across' },- 5: { curl: {}, splay: { Index: 10, Middle: 3, Ring: -4, Pinky: -12 }, thumb: 'out' },- 6: { curl: { Pinky: 0.55 }, splay: { Index: 9, Middle: 0, Ring: -8 }, thumb: 'oppose' },- 7: { curl: { Ring: 0.55 }, splay: { Index: 9, Middle: 0, Pinky: -10 }, thumb: 'oppose' },- 8: { curl: { Middle: 0.55 }, splay: { Index: 9, Ring: -6, Pinky: -12 }, thumb: 'oppose' },- 9: { curl: { Index: 0.55 }, splay: { Middle: 4, Ring: -4, Pinky: -12 }, thumb: 'oppose' },-};--// Wrist paths for the traced letters, keyed 0..1 across the letter window —-// absolute {dir, normal} orientations like every other wrist spec. J dips and-// supinates so the pinky draws the hook; Z jabs the index through the zigzag.-const MOTIONS = {- J: [- { at: 0.0, wrist: { dir: [0, 1, 0], normal: [0, 0, -1] } },- { at: 0.45, wrist: { dir: [0.15, 0.5, 0.85], normal: [0, -0.8, 0.2] } },- { at: 1.0, wrist: { dir: [0.55, 0.6, 0.55], normal: [-0.8, 0, 0.2] } },- ],- Z: [- { at: 0.0, wrist: { dir: [0.35, 1, 0.1], normal: [0, 0, -1] } },- { at: 0.3, wrist: { dir: [-0.35, 1, 0.1], normal: [0, 0, -1] } },- { at: 0.7, wrist: { dir: [0.45, 0.65, 0.45], normal: [0, 0, -1] } },- { at: 1.0, wrist: { dir: [-0.3, 0.6, 0.45], normal: [0, 0, -1] } },- ],-};--function fingerJointDegrees(spec) {- if (Array.isArray(spec)) return spec;- const amount = typeof spec === 'number' ? spec : 0;- return CURL_WEIGHTS.map((w) => w * amount);-}--// Compile one handshape into finger-bone local quats for one side.-export function handshapeLocals(letter, side = 'Right') {- const shape = LETTER_SHAPES[letter];- if (!shape) throw new Error(`no handshape for letter "${letter}"`);- const s = side === 'Left' ? 1 : -1;- const curlAxis = [0, 0, -s]; // hinge toward the palm (palms-down rest)- const splayAxis = [0, 1, 0];- const locals = {};- for (const finger of FINGERS) {- const deg = fingerJointDegrees(shape.curl?.[finger] ?? 0);- const splay = shape.splay?.[finger] ?? 0;- for (let j = 0; j < 3; j++) {- let q = qAxisAngle(curlAxis, deg[j]);- if (j === 0 && splay) q = qMul(q, qAxisAngle(splayAxis, splay * -s));- locals[`${side}Hand${finger}${j + 1}`] = qNorm(q);- }- }- const preset = THUMB_PRESETS[shape.thumb ?? 'side'];- // Thumb rest points ~45° between the fingers and the palm-forward axis;- // adduction swings it about the palm normal (toward/away from the palm- // centre), curl bends its hinge toward the palm. Axes are side-mirrored.- const thumbHinge = vNorm([-s * 0.5, 0, -0.85]);- for (let j = 0; j < 3; j++) {- let q = qAxisAngle(thumbHinge, preset.curl[j]);- if (j === 0) q = qMul(qAxisAngle([0, 1, 0], preset.adduct * -s), q);- locals[`${side}HandThumb${j + 1}`] = qNorm(q);- }- return locals;-}--// Hand local for an ABSOLUTE authored orientation: fingers toward `dir`, back-// of hand toward `normal`, in the same authoring frame as the signing pose-// (avatar faces +Z, up +Y, the right side of the body toward -X). Relative-// deltas on the base wrist do not survive the retargeter's per-rig bind-// correction, but absolute orientations built like the base pose do — the base-// pose itself is the proof.-function wristLocal(spec, gLower, restHand) {- // Escape hatch for orientations that degenerate under absolute authoring- // (a target direction near the bone's rest axis collapses to a pure twist,- // which the bind correction scrambles): a plain local pre-rotation on the- // base wrist, tuned against the live renderer (G / H use it).- if (spec.local) return qNorm(qMul(restHand, qAxisAngle(spec.local, spec.deg)));- const gHand = frameQuat(vNorm(spec.dir), vNorm(spec.normal), [-1, 0, 0], [0, 1, 0]);- return qNorm(qMul(qConj(gLower), gHand));-}--// ── clip assembly ──────────────────────────────────────────────────────────--export const DEFAULT_TIMING = Object.freeze({- holdSeconds: 0.5,- transitionSeconds: 0.22,- motionSeconds: 0.9,- leadSeconds: 0.35,- tailSeconds: 0.4,-});--export function normalizeWord(word) {- const cleaned = String(word ?? '')- .toUpperCase()- .replace(/[^A-Z0-9 ]+/g, '')- .replace(/ +/g, ' ')- .trim();- return cleaned;-}--const NORMAL_BLEND_MODE = 2500;--function stableUuid(seed) {- // FNV-1a over the seed, expanded to uuid shape — deterministic like the- // capture lanes, so identical words produce identical documents.- let h1 = 0x811c9dc5;- let h2 = 0x01000193;- for (let i = 0; i < seed.length; i++) {- h1 = Math.imul(h1 ^ seed.charCodeAt(i), 0x01000193) >>> 0;- h2 = Math.imul((h2 + seed.charCodeAt(i)) ^ (h1 >>> 5), 0x85ebca6b) >>> 0;- }- const hex = (n) => n.toString(16).padStart(8, '0');- const full = hex(h1) + hex(h2) + hex((h1 ^ 0x9e3779b9) >>> 0) + hex((h2 ^ 0x7f4a7c15) >>> 0);- return `${full.slice(0, 8)}-${full.slice(8, 12)}-${full.slice(12, 16)}-${full.slice(16, 20)}-${full.slice(20, 32)}`.toUpperCase();-}--/**- * Build an AnimationClip JSON document that fingerspells `word` on the right- * hand. Letters A–Z, digits 0–9, and spaces survive normalization; anything- * else is dropped.- * Returns the same document shape the animation library serves, ready for- * THREE.AnimationClip.parse + the platform retarget engine.- */-export function buildFingerspellingClip(word, opts = {}) {- const timing = { ...DEFAULT_TIMING, ...opts };- const letters = normalizeWord(word);- if (!letters) throw new Error('word has no spellable characters (A-Z, 0-9)');-- const pose = signingPose();- const restHand = pose.RightHand;- const gLower = pose.__gRightLower;- const neutralFingers = {};- for (const finger of [...FINGERS, 'Thumb']) {- for (let j = 1; j <= 3; j++) neutralFingers[`RightHand${finger}${j}`] = qAxisAngle([0, 0, 1], finger === 'Thumb' ? 4 : 12);- }-- // Build the keyframe timeline: {time, locals} snapshots. Every snapshot- // carries the full right-hand bone set so tracks stay aligned.- const keys = [];- const pushKey = (time, fingers, wristSpec) => {- const locals = { ...fingers };- locals.RightHand = wristSpec ? wristLocal(wristSpec, gLower, restHand) : restHand;- keys.push({ time, locals });- };-- let t = 0;- pushKey(0, neutralFingers, null);- t = timing.leadSeconds;- let prevLetter = null;- for (const ch of letters) {- if (ch === ' ') {- pushKey(t + timing.transitionSeconds, neutralFingers, null);- t += timing.transitionSeconds + timing.holdSeconds * 0.6;- prevLetter = null;- continue;- }- const shape = LETTER_SHAPES[ch];- const fingers = handshapeLocals(ch, 'Right');- const isDouble = prevLetter === ch;- if (isDouble) {- // Small outward bounce between repeated letters.- pushKey(t + timing.transitionSeconds * 0.6, { ...fingers }, { dir: [-0.3, 1, 0.1], normal: [0, 0, -1] });- t += timing.transitionSeconds * 0.6;- }- const wristBase = shape.wrist ?? null;- if (shape.motion && MOTIONS[shape.motion]) {- const start = t + timing.transitionSeconds;- for (const step of MOTIONS[shape.motion]) {- pushKey(start + step.at * timing.motionSeconds, fingers, step.wrist);- }- t = start + timing.motionSeconds;- } else {- pushKey(t + timing.transitionSeconds, fingers, wristBase);- pushKey(t + timing.transitionSeconds + timing.holdSeconds, fingers, wristBase);- t += timing.transitionSeconds + timing.holdSeconds;- }- prevLetter = ch;- }- pushKey(t + timing.tailSeconds, neutralFingers, null);-- // Static body pose: keep the whole figure composed while the hand spells.- const staticBones = {- RightArm: pose.RightArm,- RightForeArm: pose.RightForeArm,- LeftArm: pose.LeftArm,- LeftForeArm: pose.LeftForeArm,- LeftHand: pose.LeftHand,- Hips: [...IDENT],- Spine: qAxisAngle([1, 0, 0], 2),- Spine1: [...IDENT],- Spine2: [...IDENT],- Neck: qAxisAngle([1, 0, 0], -3),- Head: [...IDENT],- };-- const duration = keys[keys.length - 1].time;- const trackBones = Object.keys(keys[0].locals);- const tracks = [];- for (const bone of trackBones) {- const times = keys.map((k) => k.time);- const values = keys.flatMap((k) => k.locals[bone] ?? [...IDENT]);- tracks.push({ type: 'quaternion', name: `${bone}.quaternion`, times, values });- }- for (const [bone, q] of Object.entries(staticBones)) {- tracks.push({ type: 'quaternion', name: `${bone}.quaternion`, times: [0, duration], values: [...q, ...q] });- }- tracks.push({ type: 'vector', name: 'Hips.position', times: [0], values: [0, 0, 0] });-- return {- name: opts.name ?? `fingerspell-${letters.toLowerCase().replace(/ /g, '-')}`,- duration,- tracks,- uuid: stableUuid(`fingerspell:${letters}:${timing.holdSeconds}:${timing.transitionSeconds}`),- blendMode: NORMAL_BLEND_MODE,- };-}diff --git a/scripts/.scratch/garment-probe.mjs b/scripts/.scratch/garment-probe.mjsdeleted file mode 100644index 9ca9f022b..000000000--- a/scripts/.scratch/garment-probe.mjs+++ /dev/null@@ -1,36 +0,0 @@-// Probe a GLB's skeleton: bone names, joint world positions, mesh bounds, skinning.-import { NodeIO } from '@gltf-transform/core';--const path = process.argv[2];-const doc = await new NodeIO().read(path);-const root = doc.getRoot();--for (const mesh of root.listMeshes()) {- const prims = mesh.listPrimitives();- const hasSkin = prims.some((p) => p.getAttribute('JOINTS_0'));- let min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];- for (const p of prims) {- const pos = p.getAttribute('POSITION');- if (!pos) continue;- const mn = pos.getMin([]), mx = pos.getMax([]);- for (let i = 0; i < 3; i++) { min[i] = Math.min(min[i], mn[i]); max[i] = Math.max(max[i], mx[i]); }- }- console.log(`mesh "${mesh.getName()}" prims=${prims.length} skinned=${hasSkin}`,- 'bounds', min.map(v => v.toFixed(3)), '->', max.map(v => v.toFixed(3)));-}--for (const skin of root.listSkins()) {- const joints = skin.listJoints();- console.log(`skin joints=${joints.length}`);- // world positions via parent chain- const worldOf = (node) => {- let m = node.getMatrix?.() ? null : null;- // compose translation only from getWorldMatrix if available- const wm = node.getWorldMatrix ? node.getWorldMatrix() : null;- return wm ? [wm[12], wm[13], wm[14]] : null;- };- for (const j of joints) {- const w = worldOf(j);- console.log(' joint', j.getName(), w ? w.map(v => +v.toFixed(3)) : '');- }-}diff --git a/scripts/.scratch/page-check.mjs b/scripts/.scratch/page-check.mjsdeleted file mode 100644index 7c3194261..000000000--- a/scripts/.scratch/page-check.mjs+++ /dev/null@@ -1,28 +0,0 @@-// Load the real /sign-language page, let the hero sign, screenshot, report console errors.-import { chromium } from 'playwright';--const browser = await chromium.launch({- args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'],-});-const page = await browser.newPage({ viewport: { width: 1440, height: 950 } });-const msgs = [];-page.on('console', (m) => { if (m.type() === 'error' || m.type() === 'warning') msgs.push(`[${m.type()}] ${m.text()}`); });-page.on('pageerror', (e) => msgs.push(`[pageerror] ${e}`));-await page.goto('http://localhost:3000/sign-language', { waitUntil: 'load' });-await page.waitForTimeout(9000);-await page.screenshot({ path: '/tmp/claude-1000/-workspaces-three-ws/07298a69-ffef-4726-8a81-87336d28fc86/scratchpad/page-hero.png' });--// Vocabulary chips rendered?-const chips = await page.$$eval('.sl-vocab-chip', (els) => els.map((e) => e.textContent));-console.log('vocab chips:', chips.length, chips.slice(0, 8).join(', '));--// Type a mixed sentence and watch the status.-await page.fill('#sl-spell-input', 'happy to meet you');-await page.click('#sl-spell-btn');-await page.waitForTimeout(2500);-await page.screenshot({ path: '/tmp/claude-1000/-workspaces-three-ws/07298a69-ffef-4726-8a81-87336d28fc86/scratchpad/page-sign.png' });-await page.waitForTimeout(6000);-console.log('status:', await page.textContent('#sl-status'));--console.log(msgs.length ? 'CONSOLE:\n' + msgs.join('\n') : 'no console errors/warnings');-await browser.close();diff --git a/scripts/.scratch/probe.mjs b/scripts/.scratch/probe.mjsdeleted file mode 100644index c334a7d63..000000000--- a/scripts/.scratch/probe.mjs+++ /dev/null@@ -1,7 +0,0 @@-import { chromium } from 'playwright';-const b = await chromium.launch({ args: ['--use-gl=angle','--use-angle=swiftshader','--enable-unsafe-swiftshader'] });-const p = await b.newPage();-p.on('response', (r) => { if (r.status() >= 400) console.log(r.status(), r.url()); });-await p.goto('http://localhost:3000/scripts/.scratch/sign-preview.html?mod=old&word=AB&cols=2', { waitUntil: 'networkidle' });-console.log('title', await p.title());-await b.close();diff --git a/scripts/.scratch/shoot.mjs b/scripts/.scratch/shoot.mjsdeleted file mode 100644index a86cf19cd..000000000--- a/scripts/.scratch/shoot.mjs+++ /dev/null@@ -1,26 +0,0 @@-// Screenshot the sign-preview contact sheet.-// usage: node scripts/.scratch/shoot.mjs "<query>" <outfile>-import { chromium } from 'playwright';--const query = process.argv[2] || '';-const out = process.argv[3] || '/tmp/sign.png';-const browser = await chromium.launch({- args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'],-});-const page = await browser.newPage({ viewport: { width: 1400, height: 1200 } });-const errors = [];-page.on('console', (m) => errors.push(`[${m.type()}] ${m.text()}`));-page.on('pageerror', (e) => errors.push(String(e)));-await page.goto(`http://localhost:3000/scripts/.scratch/sign-preview.html?${query}`, { waitUntil: 'load' });-try {- await page.waitForFunction(() => document.title === 'ready', null, { timeout: 45000 });-} catch {- console.error('TIMEOUT waiting for render');-}-await page.waitForTimeout(400);-const canvas = await page.$('canvas');-const box = canvas ? await canvas.boundingBox() : null;-await page.screenshot({ path: out, clip: box ? { x: 0, y: 0, width: box.width, height: box.height } : undefined });-if (errors.length) console.error('page errors:\n' + errors.join('\n'));-console.log('wrote', out);-await browser.close();diff --git a/scripts/.scratch/sign-preview.html b/scripts/.scratch/sign-preview.htmldeleted file mode 100644index fc63c1ba6..000000000--- a/scripts/.scratch/sign-preview.html+++ /dev/null@@ -1,169 +0,0 @@-<!doctype html>-<html>- <head>- <meta charset="utf-8" />- <title>sign preview</title>- <style>- html, body { margin: 0; background: #2f5bb7; }- canvas { display: block; }- #labels { position: fixed; inset: 0; pointer-events: none; font: 700 22px system-ui; color: #ffe600; }- #labels div { position: absolute; }- </style>- </head>- <body>- <div id="labels"></div>- <script type="module">- import * as THREE from 'three';- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';- import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';- import { AnimationManager } from '/src/animation-manager.js';-- const params = new URLSearchParams(location.search);- const which = params.get('mod') || 'new';- const word = params.get('word') || 'ABCDEFGHIJKL';- const cols = +(params.get('cols') || 4);- const cellW = +(params.get('w') || 300);- const cellH = +(params.get('h') || 340);- const mode = params.get('mode') || 'letters'; // letters | frames | sign- const camY = +(params.get('camy') || 0.62);-- const mod = which === 'old'- ? await import('/scripts/.scratch/fingerspelling-old.js')- : await import('/src/fingerspelling.js');- const dictUrl = '/src/sign-' + 'dictionary.js';- const dict = (mode === 'sign' || mode === 'vocab') ? await import(/* @vite-ignore */ dictUrl) : null;-- // Build the clip + the times to sample.- let clip, samples;- if (mode === 'vocab') {- // One cell per sign, at the moment its last phase lands.- const words = (params.get('words') || Object.keys(dict.SIGNS).join(',')).split(',');- window.__vocab = words.map((w) => ({ word: w, clip: dict.buildSignClip(w) }));- clip = window.__vocab[0].clip;- samples = window.__vocab.map((v) => ({ t: v.clip.duration - 0.42, label: v.word, word: v.word }));- } else if (mode === 'sign' && dict) {- clip = dict.buildSignClip(word);- const n = +(params.get('n') || 8);- samples = Array.from({ length: n }, (_, i) => ({- t: (clip.duration * (i + 0.5)) / n,- label: `${(clip.duration * (i + 0.5) / n).toFixed(2)}s`,- }));- } else if (mode === 'frames') {- clip = mod.buildFingerspellingClip(word);- const n = +(params.get('n') || 12);- samples = Array.from({ length: n }, (_, i) => ({ t: (clip.duration * i) / (n - 1), label: `${((clip.duration * i) / (n - 1)).toFixed(2)}s` }));- } else {- // One cell per letter, sampled in the middle of that letter's hold.- const letters = [...word.toUpperCase().replace(/[^A-Z0-9]/g, '')];- clip = mod.buildFingerspellingClip(letters.join(''));- const T = mod.DEFAULT_TIMING;- let t = T.leadSeconds;- samples = letters.map((ch) => {- if (ch === 'J' || ch === 'Z') {- const mid = t + T.transitionSeconds + T.motionSeconds * 0.85;- t = t + T.transitionSeconds + T.motionSeconds;- return { t: mid, label: ch };- }- const mid = t + T.transitionSeconds + T.holdSeconds * 0.6;- t = t + T.transitionSeconds + T.holdSeconds;- return { t: mid, label: ch };- });- }-- const rows = Math.ceil(samples.length / cols);- const W = cols * cellW;- const H = rows * cellH;-- const renderer = new THREE.WebGLRenderer({ antialias: true });- renderer.setPixelRatio(1);- renderer.setSize(W, H);- renderer.outputColorSpace = THREE.SRGBColorSpace;- renderer.toneMapping = THREE.ACESFilmicToneMapping;- renderer.autoClear = false;- renderer.setScissorTest(true);- document.body.appendChild(renderer.domElement);-- const scene = new THREE.Scene();- scene.background = new THREE.Color(0x2f5bb7);- const pmrem = new THREE.PMREMGenerator(renderer);- scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;- scene.add(new THREE.HemisphereLight(0xffffff, 0x39404d, 1.0));- const key = new THREE.DirectionalLight(0xffffff, 1.6);- key.position.set(1.5, 2.5, 3);- scene.add(key, new THREE.AmbientLight(0xffffff, 0.4));-- const { getMeshoptDecoder } = await import('/src/viewer/internal.js');- const loader = new GLTFLoader();- loader.setMeshoptDecoder(await getMeshoptDecoder());- const gltf = await loader.loadAsync('/avatars/cz.glb');- const model = gltf.scene;- model.traverse((n) => { if (n.isMesh) n.frustumCulled = false; });- scene.add(model);-- const anim = new AnimationManager();- anim.attach(model);- const actions = new Map();- if (mode === 'vocab') {- for (const v of window.__vocab) {- anim.injectClip(v.word, v.clip, { loop: false });- const a = anim.actions.get(v.word);- if (!a) throw new Error('clip did not bind: ' + v.word);- actions.set(v.word, a);- }- } else {- anim.injectClip('sign', clip, { loop: false });- const a = anim.actions.get('sign');- if (!a) throw new Error('clip did not bind');- actions.set('sign', a);- }- const action = actions.values().next().value;- action.play();- action.paused = true;-- const camera = new THREE.PerspectiveCamera(30, cellW / cellH, 0.05, 50);-- const labels = document.getElementById('labels');- samples.forEach((s, i) => {- const col = i % cols;- const row = (i / cols) | 0;- const el = document.createElement('div');- el.textContent = s.label;- el.style.left = `${col * cellW + 12}px`;- el.style.top = `${row * cellH + 10}px`;- labels.appendChild(el);- });-- renderer.clear();- samples.forEach((s, i) => {- // A fresh mixer per cell: swapping actions on one mixer leaves stale- // accumulator state that silently blends toward the bind pose.- const src = s.word ? actions.get(s.word) : action;- const m = new THREE.AnimationMixer(model);- const act = m.clipAction(src.getClip());- act.play();- act.paused = true;- act.time = Math.max(0, s.t);- m.update(0);- model.updateWorldMatrix(true, true);-- const col = i % cols;- const row = (i / cols) | 0;- const x = col * cellW;- const y = H - (row + 1) * cellH;- renderer.setViewport(x, y, cellW, cellH);- renderer.setScissor(x, y, cellW, cellH);- // Track the head so a clip that moves the root still frames the signing.- let head = null;- model.traverse((n) => { if (!head && /head$/i.test(n.name)) head = n; });- const hp = new THREE.Vector3();- head.getWorldPosition(hp);- const focus = new THREE.Vector3(0, hp.y - 0.36, 0);- camera.position.set(0, focus.y + 0.18, 2.0);- camera.lookAt(focus);- camera.updateProjectionMatrix();- renderer.render(scene, camera);- });- document.title = 'ready';- </script>- </body>-</html>