Code-first video & image, rendered natively on WebGPU.
chore: shelve DNA human building
okanasl2a1abf357b92
diff --git a/.changeset/dna-body-correctives.md b/.changeset/dna-body-correctives.mddeleted file mode 100644index 020d7a94..00000000--- a/.changeset/dna-body-correctives.md+++ /dev/null@@ -1,5 +0,0 @@-----"framefields": minor------`RigEvaluator` evaluates DNA body correctives: RBF solvers (additive and interpolative, every distance method and kernel) turn joint rotations into corrective pose controls, and twist/swing spreads a joint's rotation over helper joints, matching Epic's RigLogic. The DNA reader reads the RBF, twist/swing and joint metadata layers.diff --git a/.changeset/dna-reader.md b/.changeset/dna-reader.mddeleted file mode 100644index bce0a091..00000000--- a/.changeset/dna-reader.md+++ /dev/null@@ -1,5 +0,0 @@-----"framefields": minor------`framefields/dna`: read DNA character files (the rig format MetaHuman characters export to; file versions 2.1 to 2.8) and write them as GLB files: joints at their neutral pose with rest orientations, the meshes of a LOD with skin weights and blend shapes as named morph targets, axes and units converted to glTF. Based on OpenRigLogic (MIT, Epic Games). Forge skeletons take rest orientations (`orient`).diff --git a/.changeset/dna-rig-evaluator.md b/.changeset/dna-rig-evaluator.mddeleted file mode 100644index 324a33e5..00000000--- a/.changeset/dna-rig-evaluator.md+++ /dev/null@@ -1,5 +0,0 @@-----"framefields": minor------`RigEvaluator` in `framefields/dna` evaluates a DNA character's rig: GUI and raw controls, pose-space combinations, joint deltas per LOD, blend shape weights and wrinkle-map (animated map) weights, matching Epic's RigLogic. `human()` and the MakeHuman assets are removed: realistic humans come from DNA files.diff --git a/.changeset/sparse-morphs-eight-influences.md b/.changeset/sparse-morphs-eight-influences.mdindex f9208d10..5a4da6ae 100644--- a/.changeset/sparse-morphs-eight-influences.md+++ b/.changeset/sparse-morphs-eight-influences.md@@ -2,4 +2,4 @@"framefields": minor----Sparse morph targets stay sparse from the glTF file to the GPU: the morph pass gathers each vertex's deltas from entries that exist, so meshes with hundreds of corrective shapes fit in memory. Skins take up to eight influences per vertex (glTF `JOINTS_1` / `WEIGHTS_1`), in the forge writer, the loader and the renderer. DNA characters keep eight influences, get a material per mesh role (skin, teeth, eyes, eye shell, lashes, …), and `dnaMaterials` finds an export folder's textures.+Sparse morph targets stay sparse from the glTF file to the GPU: the morph pass gathers each vertex's deltas from entries that exist, so meshes with hundreds of corrective shapes fit in memory. Skins take up to eight influences per vertex (glTF `JOINTS_1` / `WEIGHTS_1`), in the forge writer, the loader and the renderer.diff --git a/CLAUDE.md b/CLAUDE.mdindex a09fd636..28e2b23a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -20,8 +20,7 @@ Code-first video engine on native WebGPU (Dawn) in Node, no browser. pnpm + turb- `packages/renderer`: headless Node renderer (Dawn, WebCodecs/mediabunny).- `packages/vision-sam`: SAM 2.1 Tiny/Small and SAM 3 trackers (Apache-2.0 code; SAM 3 weights need runtime SAM License acceptance), private; `framefields` bundles it as a lazy chunk (`clip-vision.ts` imports it dynamically for `comp.vision(..., { sam2 | sam3 })`; `index.ts` re-exports types only) and exposes the trackers as `framefields/sam`. No weights ship; `packages/framefields/NOTICE.md` covers their licenses. Pins in `src/models/registry.ts`.- `packages/storage`: content-addressed assets on any S3-compatible bucket (R2 first): manifest format, SigV4 client (aws4fetch), verified downloads, and the locator the preview uses to redirect missing pinned files to their bucket. Shared by the CLI (`framefields/storage`), the preview and the render worker, which fetches pinned assets after LFS.-- `packages/forge`: rigged characters built in code (`framefields/forge`): `GltfDocument` GLB writer (materials + KHR extensions, skins, named morphs, clips), `Skeleton` / `humanoidSkeleton` (Mixamo names), `boneGizmo`, `sculpt` (SDF parts bound to joints → narrow-band manifold Surface Nets → QEM simplification → border cuts → skin weights from the field), `subdivide` (Loop, carrying blend shapes and weights). Realistic humans come from DNA files (`packages/dna`), not from the forge. Pure TypeScript, no GPU; tests validate output with the Khronos validator and read it back through the engine loader. Plan: `specs/character-forge.md`.-- `packages/dna`: DNA character files (the MetaHuman rig format) read in TypeScript (`readDna`, file versions 2.1–2.8) and written as GLB through the forge (`dnaToGlb`: neutral pose with rest orientations, LOD meshes, skin, blend shapes), exposed as `framefields/dna`. Ported from OpenRigLogic (MIT, notice in `packages/framefields/NOTICE.md`); no DNA files ship. Parity fixtures in `packages/dna/fixtures` come from Epic's reader (`oracle.cpp` rebuilds them). Plan: `specs/dna-face-rig.md`.+- `packages/forge`: rigged characters built in code (`framefields/forge`): `GltfDocument` GLB writer (materials + KHR extensions, skins, named morphs, clips), `Skeleton` / `humanoidSkeleton` (Mixamo names), `boneGizmo`, `sculpt` (SDF parts bound to joints → narrow-band manifold Surface Nets → QEM simplification → border cuts → skin weights from the field), `subdivide` (Loop, carrying blend shapes and weights). Pure TypeScript, no GPU; tests validate output with the Khronos validator and read it back through the engine loader. Plan: `specs/character-forge.md`.- `packages/core`: shared types, `Effect` base, signals, `emojiPresentation` (the one UTS #51 rule used by layout, preload and lint).- Others: `renderers`, `media`, `node-sdk`, `server-utils`, `client-utils`, `tensor-webgpu`, `vision`, `tsconfig`.- `nodes/node-*`: one VFX/audio/layout node each (`src/shared/`, `src/renderers/`, `src/index.ts`). Only `node-compositor` has a `SKILL.md`; update it when Compositor behavior changes (guarded by `skillmd-check.test.ts`). Effect renderers declare `reach` and `maxPixelScale` (node-sdk) when they can: without `maxPixelScale` a scaled-up leaf using the effect stays at layout resolution.diff --git a/packages/dna/fixtures/oracle-eval.json b/packages/dna/fixtures/oracle-eval.jsondeleted file mode 100644index 0882c68f..00000000--- a/packages/dna/fixtures/oracle-eval.json+++ /dev/null@@ -1,1167 +0,0 @@-[- {- "lod": 0,- "gui": [0.286536962, 1.09619188],- "quats": [- 0.155305982, 0.58949095, -0.622180045, 0.491194993, -0.173879862,- -0.558974743, -0.539365113, 0.605308473- ],- "rawControls": [- 0.286536962, 0, 0, 0.155305982, 0.58949095, -0.622180045, 0.491194993,- -0.173879862, -0.558974743, -0.539365113, 0.605308473- ],- "psdControls": [0],- "rbfControls": [0, 0, 0, 0.0454799123, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83.8458176,- 60.5716476, 132.889954, 0, 0, 0, 0, 0, 0.214902729, -16.0271492, 0, 0,- -0.143268481, 3.43844366, 0, 0.136439741, 0.0113699781, 0, -24.0407257, 0,- 0, 0, 0, 0- ],- "blendShapes": [0.286536962, 0],- "animatedMaps": [0.286536962, 0.100000001]- },- {- "lod": 1,- "raw": [- 1.16736603, 0.637500942, 0.542229116, 0.657407224, 0.726043165,- 0.932900786, 0.935774863, 0.501692832, 0.568929613, 1.02257216, 0.4349567- ],- "quats": [- -0.0316861905, -0.69918412, 0.426881522, 0.572634041, -0.201020792,- -0.454995811, 0.682546198, -0.535443902- ],- "rawControls": [- 1.16736603, 0.637500942, 0.542229116, -0.0316861905, -0.69918412,- 0.426881522, 0.572634041, -0.201020792, -0.454995811, 0.682546198,- -0.535443902- ],- "psdControls": [0.518507361],- "rbfControls": [0.0998030528, 0, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.5943956, 0, 0, 0, 0, 0, 0, 0, 0,- 100.369339, -61.1224213, -124.076668, 0, 0, 0, 0, 0, 0, 20.5775585, 0, 0,- -0.583683014, 14.0083923, 0, 0.199606106, 0, 0, 30.866333, 0, 0, 0, 0, 0- ],- "blendShapes": [1.16736603, 0],- "animatedMaps": [0, 0.610000789]- },- {- "lod": 0,- "gui": [0.545733511, 0.54758817],- "quats": [- -0.626201987, -0.61658895, 0.194248274, 0.435840249, -0.640756726,- 0.162814975, 0.657550991, -0.361315459- ],- "rawControls": [- 0.545733511, 0.54758817, 0.523794055, -0.626201987, -0.61658895,- 0.194248274, 0.435840249, -0.640756726, 0.162814975, 0.657550991,- -0.361315459- ],- "psdControls": [0.430235147],- "rbfControls": [0.0440073535, 0.137581393, 0, 0.11302723, 0.164333671],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.535691142, 0, 0, 9.62349796, 3.06798506, 0,- 0, 0, 0, 0, 0, 0, 123.772263, -36.5325279, -94.7798615, 0, 0, 0, 0, 0,- 0.301741362, 60.5818405, 0, 0, -0.272866756, 6.54880238, 0.0430235155,- 0.289515018, 0.234628886, 0, 90.8727646, 0, 0, 0, 0, 0- ],- "blendShapes": [0.545733511, 0.430235147],- "animatedMaps": [0.545733511, 0.53807056]- },- {- "lod": 1,- "raw": [- 0.708614469, 0.423286229, 0.375314444, 0.614958465, 0.854025304,- 0.371708125, 0.189836174, 1.04896402, 0.750691414, 0.45517689, 1.19562638- ],- "quats": [- -0.0264224168, -0.550800979, -0.421497434, 0.719902813, 0.25629884,- -0.0210500807, -0.947027504, -0.192371219- ],- "rawControls": [- 0.708614469, 0.423286229, 0.375314444, -0.0264224168, -0.550800979,- -0.421497434, 0.719902813, 0.25629884, -0.0210500807, -0.947027504,- -0.192371219- ],- "psdControls": [0.238298163],- "rbfControls": [0.0181994643, 0.00392340543, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.30404711, 0, 0, 0, 0, 0, 0, 0, 0,- -44.2599602, -62.7881622, 71.0734558, 0, 0, 0, 0, 0, 0, -53.1090698, 0, 0,- -0.354307234, 8.5033741, 0, 0.0324755237, 0, 0, -79.6636124, 0, 0, 0, 0, 0- ],- "blendShapes": [0.708614469, 0],- "animatedMaps": [0.708614469, 0.438629001]- },- {- "lod": 0,- "gui": [0.214277178, 0.00245361333],- "quats": [- 0.397490501, 0.539358795, -0.736972511, 0.0892457291, 0.504015565,- 0.797666788, -0.268076807, -0.194501176- ],- "rawControls": [- 0.214277178, 0.00245361333, 0.251226813, 0.397490501, 0.539358795,- -0.736972511, 0.0892457291, 0.504015565, 0.797666788, -0.268076807,- -0.194501176- ],- "psdControls": [0.000924620195],- "rbfControls": [0.0192825682, 0, 0, 0.032572791, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.126840219, 0, 0, -1.20428789, 1.88235176, 0,- 0, 0, 0, 0, 0, 0, 113.218323, 32.1768913, -157.834793, 0, 0, 0, 0, 0,- 0.160476729, -68.8982315, 0, 0, -0.107138589, 2.57132626, 9.24620181e-5,- 0.136283517, 0.00814319775, 0, -103.347351, 0, 0, 0, 0, 0- ],- "blendShapes": [0.214277178, 0.000924620195],- "animatedMaps": [0.214277178, 0.101962894]- },- {- "lod": 1,- "raw": [- 0.766041636, 0.994339347, 0.60434413, 0.578179002, 0.942848921,- 1.14863193, 0.389326662, 1.06179845, 0.248553097, 0.332749128, 1.13962126- ],- "quats": [- 0.35132587, -0.476139843, -0.73228538, -0.33707425, 0.642174244,- 0.512193978, -0.57003063, 0.0182906892- ],- "rawControls": [- 0.766041636, 0.994339347, 0.60434413, 0.35132587, -0.476139843,- -0.73228538, -0.33707425, 0.642174244, 0.512193978, -0.57003063,- 0.0182906892- ],- "psdControls": [0.901384711],- "rbfControls": [0.0685454533, 0.0271599144, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19.5692215, 0, 0, 0, 0, 0, 0, 0, 0,- -86.2212143, 61.7964172, -159.83252, 0, 0, 0, 0, 0, 0, 88.3685074, 0, 0,- -0.383020818, 9.19249916, 0, 0.109930992, 0, 0, 132.552765, 0, 0, 0, 0, 0- ],- "blendShapes": [0.766041636, 0],- "animatedMaps": [0.766041636, 0]- },- {- "lod": 0,- "gui": [0.907661557, 0.500799477],- "quats": [- -0.324434906, -0.281723261, -0.561551332, 0.707130969, -0.732510388,- 0.443331569, 0.495017797, -0.147793889- ],- "rawControls": [- 0.907661557, 0.500799477, 0.500399709, -0.324434906, -0.281723261,- -0.561551332, 0.707130969, -0.732510388, 0.443331569, 0.495017797,- -0.147793889- ],- "psdControls": [0.375899881],- "rbfControls": [0.00489025842, 0.137661785, 0, 0.182358652, 0.150062293],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.500599623, 0, 0, 8.64169025, 3.00119805, 0,- 0, 0, 0, 0, 0, 0, 10.1153889, -46.7038841, 48.928051, 0, 0, 0, 0, 0,- 0.58677125, 78.5929489, 0, 0, -0.453830779, 10.8919392, 0.0375899896,- 0.419194698, 0.252082348, 0, 117.889435, 0, 0, 0, 0, 0- ],- "blendShapes": [0.907661557, 0.375899881],- "animatedMaps": [0.907661557, 0.500639617]- },- {- "lod": 1,- "raw": [- 0.32230404, 0.62865144, 0.404157698, 0.120603137, 0.463143408,- 0.559077322, 0.900692701, 1.0337584, 0.928557456, 0.277921796, 0.822685421- ],- "quats": [- 0.143725887, -0.716614068, 0.409901679, 0.545699418, 0.101181448,- 0.567303836, -0.71388793, 0.39786014- ],- "rawControls": [- 0.32230404, 0.62865144, 0.404157698, 0.143725887, -0.716614068,- 0.409901679, 0.545699418, 0.101181448, 0.567303836, -0.71388793,- 0.39786014- ],- "psdControls": [0.381111503],- "rbfControls": [0.0884865969, 0, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.6955748, 0, 0, 0, 0, 0, 0, 0, 0,- 117.102295, -68.6698456, -150.067596, 0, 0, 0, 0, 0, 0, 14.2686481, 0, 0,- -0.16115202, 3.8676486, 0, 0.176973194, 0, 0, 21.4029713, 0, 0, 0, 0, 0- ],- "blendShapes": [0.32230404, 0],- "animatedMaps": [0.32230404, 0.602921188]- },- {- "lod": 0,- "gui": [0.5228315, 1.19410551],- "quats": [- 0.627173841, -0.46322301, -0.332741678, 0.530434132, 0.358151555,- 0.556825399, 0.519271016, -0.540398538- ],- "rawControls": [- 0.5228315, 0, 0, 0.627173841, -0.46322301, -0.332741678, 0.530434132,- 0.358151555, 0.556825399, 0.519271016, -0.540398538- ],- "psdControls": [0],- "rbfControls": [0.0182286389, 0, 0, 0.106531441, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,- -93.7444077, -29.3210812, 73.1963959, 0, 0, 0, 0, 0, 0.39212364,- -33.5346146, 0, 0, -0.26141575, 6.27397823, 0, 0.356051594, 0.0266328603,- 0, -50.301918, 0, 0, 0, 0, 0- ],- "blendShapes": [0.5228315, 0],- "animatedMaps": [0.5228315, 0.100000001]- },- {- "lod": 1,- "raw": [- 1.06041634, 0.286010742, 1.17670476, 0.289105654, 1.10928118, 1.0008992,- 0.777425647, 0.674816787, 0.446305305, 0.223177031, 0.0322937258- ],- "quats": [- -0.625832319, -0.46601969, 0.337557495, -0.52651155, -0.223594785,- -0.0145392865, 0.823986232, -0.520423651- ],- "rawControls": [- 1.06041634, 0.286010742, 1.17670476, -0.625832319, -0.46601969,- 0.337557495, -0.52651155, -0.223594785, -0.0145392865, 0.823986232,- -0.520423651- ],- "psdControls": [0.429016113],- "rbfControls": [0.00744396122, 0.0811383352, 0, 0, 0.0325497538],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.12373924, 0, 0, 0, 0, 0, 0, 0, 0,- -101.738312, 71.658493, -40.3711586, 0, 0, 0, 0, 0, 0, 23.2502937, 0, 0,- -0.53020817, 12.7249966, 0, -0.0662504137, 0, 0, 34.8754387, 0, 0, 0, 0, 0- ],- "blendShapes": [1.06041634, 0],- "animatedMaps": [0, 0.328808606]- },- {- "lod": 0,- "gui": [0.66446358, 0.608002722],- "quats": [- -0.189275682, 0.0786052868, -0.908566117, 0.364010185, -0.544580042,- -0.1190698, -0.656698585, 0.507938921- ],- "rawControls": [- 0.66446358, 0.391997278, 0.554001331, -0.189275682, 0.0786052868,- -0.908566117, 0.364010185, -0.544580042, -0.1190698, -0.656698585,- 0.507938921- ],- "psdControls": [0.3257505],- "rbfControls": [- 0.0139222313, 0.181590691, 0.165715367, 0.143913075, 0.0672216937- ],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.472999305, 0, 0, 6.04719067, 3.50350928, 0,- 0, 0, 0, 0, 0, 0, 23.8532639, -1.80385303, 95.0979385, 0, 0, 0, 0, 0,- 0.416910082, -46.9938278, 0, 0, -0.33223179, 7.97356319, 0.0325750522,- 0.360850662, -0.105924085, 0, -70.4907455, 0, 0, 0, 0, 0- ],- "blendShapes": [0.66446358, 0.3257505],- "animatedMaps": [0.66446358, 0.413597822]- },- {- "lod": 1,- "raw": [- 0.8982023, 0.517810345, 0.140155733, 1.09451759, 0.101782039, 0.704133034,- 0.182986677, 1.01401341, 0.447885871, 0.76731962, 0.554896355- ],- "quats": [- -0.596046925, -0.405836225, 0.470150948, -0.508903861, -0.842667699,- 0.498122633, 0.107582264, 0.173813418- ],- "rawControls": [- 0.8982023, 0.517810345, 0.140155733, -0.596046925, -0.405836225,- 0.470150948, -0.508903861, -0.842667699, 0.498122633, 0.107582264,- 0.173813418- ],- "psdControls": [0.108861133],- "rbfControls": [0.00209879153, 0.0589315817, 0, 0, 0.145004734],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.9820118, 0, 0, 0, 0, 0, 0, 0, 0,- -70.376709, 76.9427795, -1.2642287, 0, 0, 0, 0, 0, 0, -78.3452835, 0, 0,- -0.44910115, 10.7784271, 0, -0.0547339991, 0, 0, -117.517944, 0, 0, 0, 0,- 0- ],- "blendShapes": [0.8982023, 0],- "animatedMaps": [0.8982023, 0.514248312]- },- {- "lod": 0,- "gui": [0.915960968, 0.638820827],- "quats": [- -0.325357735, -0.453569382, 0.698282421, 0.448128283, -0.704924107,- -0.261014462, 0.0273289736, -0.658943474- ],- "rawControls": [- 0.915960968, 0.361179173, 0.569410443, -0.325357735, -0.453569382,- 0.698282421, 0.448128283, -0.704924107, -0.261014462, 0.0273289736,- -0.658943474- ],- "psdControls": [0.308488816],- "rbfControls": [0.100990541, 0.214604929, 0, 0.183108702, 0.0192055926],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.465294808, 0, 0, 5.30199766, 3.65360069, 0,- 0, 0, 0, 0, 0, 0, 76.9105988, -24.2817745, -104.129913, 0, 0, 0, 0, 0,- 0.609848499, 46.9309082, 0, 0, -0.457980484, 10.9915314, 0.0308488812,- 0.536702275, 0.367684573, 0, 70.396347, 0, 0, 0, 0, 0- ],- "blendShapes": [0.915960968, 0.308488816],- "animatedMaps": [0.915960968, 0.388943344]- },- {- "lod": 1,- "raw": [- 0.629078686, 1.09186184, 0.512747824, 1.10433149, 0.00912380219,- 1.18707812, 0.294231117, 0.516803741, 1.12357461, 0.29589045, 0.163111508- ],- "quats": [- 0.586118579, -0.478032351, -0.222267359, -0.615261972, 0.0737782493,- -0.56766516, 0.322422475, 0.753894329- ],- "rawControls": [- 0.629078686, 1.09186184, 0.512747824, 0.586118579, -0.478032351,- -0.222267359, -0.615261972, 0.0737782493, -0.56766516, 0.322422475,- 0.753894329- ],- "psdControls": [0.769121766],- "rbfControls": [0.0627372935, 0.0632931814, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21.580862, 0, 0, 0, 0, 0, 0, 0, 0,- 84.6681747, 64.848114, 34.1552887, 0, 0, 0, 0, 0, 0, 5.5893302, 0, 0,- -0.314539343, 7.54894447, 0, 0.0621814057, 0, 0, 8.38399506, 0, 0, 0, 0, 0- ],- "blendShapes": [0.629078686, 0],- "animatedMaps": [0.629078686, 0]- },- {- "lod": 0,- "gui": [0.523932338, 0.0708033144],- "quats": [- 0.607108474, -0.076044105, -0.790616751, 0.0236986242, 0.705974162,- -0.60922277, -0.300756305, 0.19998455- ],- "rawControls": [- 0.523932338, 0.0708033144, 0.285401642, 0.607108474, -0.076044105,- -0.790616751, 0.0236986242, 0.705974162, -0.60922277, -0.300756305,- 0.19998455- ],- "psdControls": [0.0303110741],- "rbfControls": [0.0279700253, 0, 0, 0.106845394, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.178102478, 0, 0, 0.0799913555, 2.07989001, 0,- 0, 0, 0, 0, 0, 0, -91.0799103, 35.3068123, 119.433769, 0, 0, 0, 0, 0,- 0.385371476, 74.1839218, 0, 0, -0.261966169, 6.28718805, 0.00303110736,- 0.376476258, 0.0267113484, 0, 111.275887, 0, 0, 0, 0, 0- ],- "blendShapes": [0.523932338, 0.0303110741],- "animatedMaps": [0.523932338, 0.15664266]- },- {- "lod": 1,- "raw": [- 1.0337981, 1.16979349, 0.746870995, 0.130010247, 0.0133060459,- 0.237080753, 1.1277591, 0.698950768, 0.971901417, 0.83060199, 0.879659891- ],- "quats": [- -0.528544247, 0.243979365, -0.426339477, -0.692350864, 0.717462599,- 0.097225368, -0.232831657, 0.649295151- ],- "rawControls": [- 1.0337981, 1.16979349, 0.746870995, -0.528544247, 0.243979365,- -0.426339477, -0.692350864, 0.717462599, 0.097225368, -0.232831657,- 0.649295151- ],- "psdControls": [1],- "rbfControls": [0.153400153, 0.0101931002, 0, 0, 0.272682667],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22.6615143, 0, 0, 0, 0, 0, 0, 0, 0,- -40.4905128, -45.5788536, -24.3355713, 0, 0, 0, 0, 0, 0, 47.8552742, 0, 0,- -0.516899049, 12.4055767, 0, 0.296607196, 0, 0, 71.7829285, 0, 0, 0, 0, 0- ],- "blendShapes": [1.0337981, 0],- "animatedMaps": [0, 0]- },- {- "lod": 0,- "gui": [0.99269861, 0.678209186],- "quats": [- -0.678951383, -0.124429591, 0.454263985, 0.563193142, 0.367896676,- -0.275205255, 0.612026155, -0.643690944- ],- "rawControls": [- 0.99269861, 0.321790814, 0.589104593, -0.678951383, -0.124429591,- 0.454263985, 0.563193142, 0.367896676, -0.275205255, 0.612026155,- -0.643690944- ],- "psdControls": [0.28435266],- "rbfControls": [0.0974207669, 0.24707599, 0, 0.188780755, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.455447704, 0, 0, 4.34335136, 3.8495791, 0, 0,- 0, 0, 0, 0, 0, 65.6084518, 5.54234362, -44.9247551, 0, 0, 0, 0, 0,- 0.673435807, -29.7497978, 0, 0, -0.496349305, 11.9123831, 0.0284352656,- 0.514107764, 0.417809188, 0, -44.6246948, 0, 0, 0, 0, 0- ],- "blendShapes": [0.99269861, 0.28435266],- "animatedMaps": [0.99269861, 0.357432663]- },- {- "lod": 1,- "raw": [- 1.17467237, 0.281937957, 0.633712053, 1.04779029, 0.497223914,- 0.772749841, 0.872576535, 1.01760364, 0.579327047, 0.314725488,- 0.313414216- ],- "quats": [- -0.270672619, -0.25298351, 0.495458663, 0.785656691, -0.199693978,- -0.829624057, 0.488439858, -0.182408616- ],- "rawControls": [- 1.17467237, 0.281937957, 0.633712053, -0.270672619, -0.25298351,- 0.495458663, 0.785656691, -0.199693978, -0.829624057, 0.488439858,- -0.182408616- ],- "psdControls": [0.268001229],- "rbfControls": [0.2955935, 0, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.27420259, 0, 0, 0, 0, 0, 0, 0, 0,- 35.1526566, -20.2817822, -51.2350578, 0, 0, 0, 0, 0, 0, 47.5901527, 0, 0,- -0.587336183, 14.0960684, 0, 0.591187, 0, 0, 71.385231, 0, 0, 0, 0, 0- ],- "blendShapes": [1.17467237, 0],- "animatedMaps": [0, 0.325550377]- },- {- "lod": 0,- "gui": [0.792193949, 0.966062903],- "quats": [- -0.572604537, 0.673827112, 0.462832808, -0.0621844232, -0.170099616,- -0.337652683, -0.837698042, -0.394105107- ],- "rawControls": [- 0.792193949, 0.0339370966, 0.733031452, -0.572604537, 0.673827112,- 0.462832808, -0.0621844232, -0.170099616, -0.337652683, -0.837698042,- -0.394105107- ],- "psdControls": [0.0373154394],- "rbfControls": [0.0123773757, 0.275000006, 0, 0.16842562, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.383484274, 0, 0, -2.87446904, 5.42310524, 0,- 0, 0, 0, 0, 0, 0, -139.619324, 9.48774719, 129.371765, 0, 0, 0, 0, 0,- 0.584816635, 23.3455009, 0, 0, -0.396096975, 9.50632763, 0.0037315439,- 0.255031615, 0.454606414, 0, 35.0182495, 0, 0, 0, 0, 0- ],- "blendShapes": [0.792193949, 0.0373154394],- "animatedMaps": [0.792193949, 0.127149686]- },- {- "lod": 1,- "raw": [- 0.535584867, 0.274879456, 0.833551586, 0.0823237225, 1.00544846,- 1.16988003, 0.848474741, 0.0393512994, 0.729727149, 1.03993201, 0.21076034- ],- "quats": [- 0.577298582, -0.286117524, -0.299319267, -0.703754961, 0.513447762,- -0.228567705, -0.815013111, -0.141002834- ],- "rawControls": [- 0.535584867, 0.274879456, 0.833551586, 0.577298582, -0.286117524,- -0.299319267, -0.703754961, 0.513447762, -0.228567705, -0.815013111,- -0.141002834- ],- "psdControls": [0.343689322],- "rbfControls": [0.110457748, 0.0475647934, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.36089897, 0, 0, 0, 0, 0, 0, 0, 0,- 52.015274, 46.452198, -6.41780949, 0, 0, 0, 0, 0, 0, -74.6440201, 0, 0,- -0.267792434, 6.42701817, 0, 0.173350707, 0, 0, -111.966034, 0, 0, 0, 0, 0- ],- "blendShapes": [0.535584867, 0],- "animatedMaps": [0.535584867, 0.319903582]- },- {- "lod": 0,- "gui": [0.485489279, 0.58809036],- "quats": [- 0.555862248, -0.30701527, 0.336890191, -0.695171714, 0.181046605,- -0.0740219429, 0.298284113, -0.934221327- ],- "rawControls": [- 0.485489279, 0.58809036, 0.54404521, 0.555862248, -0.30701527,- 0.336890191, -0.695171714, 0.181046605, -0.0740219429, 0.298284113,- -0.934221327- ],- "psdControls": [0.479921609],- "rbfControls": [- 0.010005394, 0.122308783, 0.190307498, 0.095845364, 0.194189891- ],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.566067815, 0, 0, 10.4813461, 3.1204958, 0, 0,- 0, 0, 0, 0, 0, 63.3141937, 21.832119, 47.5996933, 0, 0, 0, 0, 0,- 0.244136572, -10.9676313, 0, 0, -0.24274464, 5.82587147, 0.0479921624,- 0.280391842, -0.268344253, 0, -16.4514484, 0, 0, 0, 0, 0- ],- "blendShapes": [0.485489279, 0.479921609],- "animatedMaps": [0.485489279, 0.5704723]- },- {- "lod": 1,- "raw": [- 0.282050312, 0.528056681, 1.08861589, 1.04112875, 0.349136859,- 0.523416996, 0.218545184, 0.299785286, 0.819173217, 1.02076375, 1.025033- ],- "quats": [- 0.394191056, 0.693019271, -0.536169887, 0.277235568, 0.47437185,- -0.295133859, -0.655474186, 0.508154333- ],- "rawControls": [- 0.282050312, 0.528056681, 1.08861589, 0.394191056, 0.693019271,- -0.536169887, 0.277235568, 0.47437185, -0.295133859, -0.655474186,- 0.508154333- ],- "psdControls": [0.792085052],- "rbfControls": [0.0040988992, 0.0145295262, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.49430895, 0, 0, 0, 0, 0, 0, 0, 0,- 136.903687, 48.8280945, -161.070969, 0, 0, 0, 0, 0, 0, 43.0307617, 0, 0,- -0.141025156, 3.38460374, 0, -0.00633172784, 0, 0, 64.5461349, 0, 0, 0, 0,- 0- ],- "blendShapes": [0.282050312, 0],- "animatedMaps": [0.282050312, 0.522445381]- },- {- "lod": 0,- "gui": [1.12232447, 0.209558278],- "quats": [- -0.0268620197, -0.486047626, -0.175867364, -0.855632424, -0.242713526,- -0.336580127, 0.632377386, -0.654142797- ],- "rawControls": [- 0, 0.209558278, 0.354779124, -0.0268620197, -0.486047626, -0.175867364,- -0.855632424, -0.242713526, -0.336580127, 0.632377386, -0.654142797- ],- "psdControls": [0.111520357],- "rbfControls": [0.107618883, 0, 0.36835739, 0.0107843745, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.282168686, 0, 0, 2.75183082, 2.43780255, 0,- 0, 0, 0, 0, 0, 0, -16.4791965, 57.2346001, -25.3212299, 0, 0, 0, 0, 0,- -0.0278800894, 20.3568916, 0, 0, 0, 0, 0.0111520356, 0.43176958,- -0.918197393, 0, 30.5353413, 0, 0, 0, 0, 0- ],- "blendShapes": [0, 0.111520357],- "animatedMaps": [0, 0.267646641]- },- {- "lod": 1,- "raw": [- 0.352558583, 0.929839492, 0.570264399, 0.465752602, 0.717927039,- 0.941281796, 0.224707261, 0.752101719, 0.871831596, 0.625475585,- 0.0377511978- ],- "quats": [- -0.518909335, 0.601738513, 0.321437299, -0.515094161, -0.155003443,- -0.417876273, 0.642677486, 0.623152435- ],- "rawControls": [- 0.352558583, 0.929839492, 0.570264399, -0.518909335, 0.601738513,- 0.321437299, -0.515094161, -0.155003443, -0.417876273, 0.642677486,- 0.623152435- ],- "psdControls": [0.795381486],- "rbfControls": [0.0189302657, 0.00155700557, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18.1316128, 0, 0, 0, 0, 0, 0, 0, 0,- -105.598938, -38.1298218, 92.6411133, 0, 0, 0, 0, 0, 0, -13.9683218, 0, 0,- -0.176279292, 4.23070288, 0, 0.0363035277, 0, 0, -20.9524784, 0, 0, 0, 0,- 0- ],- "blendShapes": [0.352558583, 0],- "animatedMaps": [0.352558583, 0]- },- {- "lod": 0,- "gui": [0.0221036207, 0.313445807],- "quats": [- -0.365932077, 0.770541549, -0.411624342, -0.32081902, -0.25233829,- -0.901133597, 0.227621511, 0.269206256- ],- "rawControls": [- 0.0221036207, 0.313445807, 0.406722903, -0.365932077, 0.770541549,- -0.411624342, -0.32081902, -0.25233829, -0.901133597, 0.227621511,- 0.269206256- ],- "psdControls": [0.19122839],- "rbfControls": [0.0453514457, 0, 0, 0.0121519389, 0.277525812],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.360084355, 0, 0, 4.80898666, 2.66796494, 0,- 0, 0, 0, 0, 0, 0, 151.152344, -48.9700775, 158.773972, 0, 0, 0, 0, 0,- -0.0312293824, -43.1475601, 0, 0, -0.0110518103, 0.265243441, 0.019122839,- 0.127158701, 0.00303798472, 0, -64.7213364, 0, 0, 0, 0, 0- ],- "blendShapes": [0.0221036207, 0.19122839],- "animatedMaps": [0.0221036207, 0.350756645]- },- {- "lod": 1,- "raw": [- 0.565777063, 1.16704941, 0.470529139, 0.239060715, 0.530492127,- 0.0332113281, 1.03505325, 1.04030275, 0.572963476, 0.369279325,- 0.187240943- ],- "quats": [- 0.722105563, 0.577569366, -0.380352199, -0.0175933354, 0.789051235,- -0.565129995, -0.0524965338, 0.235096171- ],- "rawControls": [- 0.565777063, 1.16704941, 0.470529139, 0.722105563, 0.577569366,- -0.380352199, -0.0175933354, 0.789051235, -0.565129995, -0.0524965338,- 0.235096171- ],- "psdControls": [0.705793738],- "rbfControls": [0.0170884728, 0.0100488458, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23.1057243, 0, 0, 0, 0, 0, 0, 0, 0,- 150.056519, 16.20961, -114.466537, 0, 0, 0, 0, 0, 0, 73.408699, 0, 0,- -0.282888532, 6.78932476, 0, 0.0241280999, 0, 0, 110.113037, 0, 0, 0, 0, 0- ],- "blendShapes": [0.565777063, 0],- "animatedMaps": [0.565777063, 0]- },- {- "lod": 0,- "gui": [0.614694118, 1.19522023],- "quats": [- -0.442441791, -0.453041881, 0.319483906, 0.704931498, -0.595601797,- 0.323709697, -0.0251828618, -0.734735608- ],- "rawControls": [- 0.614694118, 0, 0, -0.442441791, -0.453041881, 0.319483906, 0.704931498,- -0.595601797, 0.323709697, -0.0251828618, -0.734735608- ],- "psdControls": [0],- "rbfControls": [0.130431116, 0, 0, 0.131723925, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67.2628708,- -38.4828033, -59.2865067, 0, 0, 0, 0, 0, 0.461020589, 39.0294075, 0, 0,- -0.307347059, 7.37632942, 0, 0.656033993, 0.0329309814, 0, 58.5441055, 0,- 0, 0, 0, 0- ],- "blendShapes": [0.614694118, 0],- "animatedMaps": [0.614694118, 0.100000001]- },- {- "lod": 1,- "raw": [- 0.57409066, 0.998165965, 0.413446933, 0.239330083, 0.0320722125,- 0.886126935, 0.676848888, 0.151182115, 0.749809325, 1.11295033,- 0.219158441- ],- "quats": [- 0.777543664, -0.228355139, -0.551674604, -0.197319239, 0.179191187,- 0.0596133657, 0.361157477, -0.913182378- ],- "rawControls": [- 0.57409066, 0.998165965, 0.413446933, 0.777543664, -0.228355139,- -0.551674604, -0.197319239, 0.179191187, 0.0596133657, 0.361157477,- -0.913182378- ],- "psdControls": [0.619032979],- "rbfControls": [0.0364302397, 0.0096512856, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19.7531853, 0, 0, 0, 0, 0, 0, 0, 0,- 159.934921, 74.184082, 59.1778526, 0, 0, 0, 0, 0, 0, -11.1019287, 0, 0,- -0.28704533, 6.88908768, 0, 0.063209191, 0, 0, -16.6528912, 0, 0, 0, 0, 0- ],- "blendShapes": [0.57409066, 0],- "animatedMaps": [0.57409066, 0]- },- {- "lod": 0,- "gui": [0.238228023, 0.452801973],- "quats": [- 0.345724195, -0.551958084, 0.753310978, -0.0913210437, -0.873508275,- 0.0127660604, -0.168671772, 0.456475735- ],- "rawControls": [- 0.238228023, 0.452801973, 0.476400971, 0.345724195, -0.551958084,- 0.753310978, -0.0913210437, -0.873508275, 0.0127660604, -0.168671772,- 0.456475735- ],- "psdControls": [0.323572963],- "rbfControls": [0.0197672267, 0.117984578, 0, 0.0364897847, 0.156988204],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.464601457, 0, 0, 7.64475393, 2.92586136, 0,- 0, 0, 0, 0, 0, 0, 108.07637, -6.26936913, 146.517563, 0, 0, 0, 0, 0,- 0.0977777764, -62.4094467, 0, 0, -0.119114012, 2.85873628, 0.0323572978,- 0.0310192257, 0.186099306, 0, -93.6141739, 0, 0, 0, 0, 0- ],- "blendShapes": [0.238228023, 0.323572963],- "animatedMaps": [0.238228023, 0.46224159]- },- {- "lod": 1,- "raw": [- 0.302244902, 0.579596043, 0.438697487, 0.381438106, 0.811811745,- 0.810112834, 0.133219674, 0.964008987, 0.104614235, 0.18130374,- 0.516860843- ],- "quats": [- -0.528503418, -0.531722546, -0.451012135, -0.484296709, 0.745521069,- 0.457634151, -0.458491236, 0.156700656- ],- "rawControls": [- 0.302244902, 0.579596043, 0.438697487, -0.528503418, -0.531722546,- -0.451012135, -0.484296709, 0.745521069, 0.457634151, -0.458491236,- 0.156700656- ],- "psdControls": [0.381401002],- "rbfControls": [0.0663388222, 0.0202966165, 0.137086436, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10.5426369, 0, 0, 0, 0, 0, 0, 0, 0,- -97.1804733, 28.3893337, -91.7897491, 0, 0, 0, 0, 0, 0, 78.1298141, 0, 0,- -0.151122451, 3.62693882, 0, 0.180924237, 0, 0, 117.19474, 0, 0, 0, 0, 0- ],- "blendShapes": [0.302244902, 0],- "animatedMaps": [0.302244902, 0.563676834]- },- {- "lod": 0,- "gui": [1.12270081, 0.232559264],- "quats": [- -0.476657331, 0.208571389, -0.590149283, -0.617267847, 0.53519702,- 0.144579634, -0.580529273, 0.596361041- ],- "rawControls": [- 0, 0.232559264, 0.366279632, -0.476657331, 0.208571389, -0.590149283,- -0.617267847, 0.53519702, 0.144579634, -0.580529273, 0.596361041- ],- "psdControls": [0.127772585],- "rbfControls": [0.155830637, 0, 0, 0.0107843745, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.299419463, 0, 0, 3.20310473, 2.49155211, 0,- 0, 0, 0, 0, 0, 0, -28.0444489, -46.5372581, -46.6893768, 0, 0, 0, 0, 0,- -0.0319431461, 41.9060059, 0, 0, 0, 0, 0.0127772586, 0.344014406,- 0.00269609364, 0, 62.8590088, 0, 0, 0, 0, 0- ],- "blendShapes": [0, 0.127772585],- "animatedMaps": [0, 0.286047429]- },- {- "lod": 1,- "raw": [- 0.415757298, 1.06687713, 0.977570474, 0.370096505, 0.804642797,- 0.722216427, 0.809880435, 1.00457406, 1.19876897, 0.848178208, 0.897381186- ],- "quats": [- -0.117718451, -0.544309914, -0.650398076, -0.516576588, 0.669899225,- 0.644288242, 0.367981195, -0.0267855544- ],- "rawControls": [- 0.415757298, 1.06687713, 0.977570474, -0.117718451, -0.544309914,- -0.650398076, -0.516576588, 0.669899225, 0.644288242, 0.367981195,- -0.0267855544- ],- "psdControls": [1],- "rbfControls": [0.10721793, 0.029896345, 0.258403599, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19.4496918, 0, 0, 0, 0, 0, 0, 0, 0,- -75.7788696, 43.0236702, -110.798668, 0, 0, 0, 0, 0, 0, -87.7102737, 0, 0,- -0.207878649, 4.98908758, 0, 0.313741326, 0, 0, -131.565414, 0, 0, 0, 0, 0- ],- "blendShapes": [0.415757298, 0],- "animatedMaps": [0.415757298, 0]- },- {- "lod": 0,- "gui": [1.07662237, 0.683598399],- "quats": [- -0.172688037, -0.68929714, -0.158204779, -0.685579777, 0.415348262,- 0.378221482, 0.584556937, 0.58542937- ],- "rawControls": [- 0, 0.316401601, 0.5917992, -0.172688037, -0.68929714, -0.158204779,- -0.685579777, 0.415348262, 0.378221482, 0.584556937, 0.58542937- ],- "psdControls": [0.280869335],- "rbfControls": [0.0508965924, 0.250712276, 0.224623784, 0.0107843745, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.4541004, 0, 0, 4.21164417, 3.87675548, 0, 0,- 0, 0, 0, 0, 0, -91.3467865, 71.0534592, -90.5099487, 0, 0, 0, 0, 0,- -0.0702173337, 35.3547974, 0, 0, 0, 0, 0.0280869342, -0.0042540729,- -0.182794929, 0, 53.0321999, 0, 0, 0, 0, 0- ],- "blendShapes": [0, 0.280869335],- "animatedMaps": [0, 0.353121281]- },- {- "lod": 1,- "raw": [- 1.14752614, 0.624254644, 0.486314774, 0.604373872, 0.904123783,- 0.122125126, 0.71428746, 0.36995244, 1.05122459, 0.216595471, 0.844763219- ],- "quats": [- 0.55306977, -0.311887205, -0.725122988, 0.266527474, 0.864047945,- 0.365271211, 0.303129762, -0.167661726- ],- "rawControls": [- 1.14752614, 0.624254644, 0.486314774, 0.55306977, -0.311887205,- -0.725122988, 0.266527474, 0.864047945, 0.365271211, 0.303129762,- -0.167661726- ],- "psdControls": [0.455376357],- "rbfControls": [0.0129767573, 0.0104779219, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11.4196482, 0, 0, 0, 0, 0, 0, 0, 0,- -86.4480286, 1.37088728, 102.2509, 0, 0, 0, 0, 0, 0, -79.0186768, 0, 0,- -0.573763072, 13.7703133, 0, 0.0154755926, 0, 0, -118.528, 0, 0, 0, 0, 0- ],- "blendShapes": [1.14752614, 0],- "animatedMaps": [0, 0.599403739]- },- {- "lod": 0,- "gui": [0.465601891, 0.729495943],- "quats": [- -0.642190814, -0.0749957487, -0.374752164, -0.664475322, -0.584925175,- -0.403516352, -0.530655444, 0.461997688- ],- "rawControls": [- 0.465601891, 0.270504057, 0.614748001, -0.642190814, -0.0749957487,- -0.374752164, -0.664475322, -0.584925175, -0.403516352, -0.530655444,- 0.461997688- ],- "psdControls": [0.249437749],- "rbfControls": [0.118004501, 0.275000006, 0, 0.0901774541, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.442626029, 0, 0, 3.08465409, 4.11173439, 0,- 0, 0, 0, 0, 0, 0, -58.099556, -6.45400286, -33.6901665, 0, 0, 0, 0, 0,- 0.286841989, -51.696888, 0, 0, -0.232800946, 5.58722258, 0.0249437746,- 0.231541365, 0.435044378, 0, -77.5453415, 0, 0, 0, 0, 0- ],- "blendShapes": [0.465601891, 0.249437749],- "animatedMaps": [0.465601891, 0.31640324]- },- {- "lod": 1,- "raw": [- 0.274133086, 0.477973729, 0.792906463, 0.0188220982, 0.634179354,- 0.0882995427, 1.0872879, 0.936182201, 0.495520175, 0.385159433, 0.6549685- ],- "quats": [- 0.477913618, 0.719715297, -0.193864673, 0.464784801, -0.717810869,- 0.442561597, 0.344826877, 0.412287652- ],- "rawControls": [- 0.274133086, 0.477973729, 0.792906463, 0.477913618, 0.719715297,- -0.193864673, 0.464784801, -0.717810869, 0.442561597, 0.344826877,- 0.412287652- ],- "psdControls": [0.568482697],- "rbfControls": [0.00871269684, 0.0262422413, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7.30039072, 0, 0, 0, 0, 0, 0, 0, 0,- -164.163254, 61.8857765, -122.996315, 0, 0, 0, 0, 0, 0, -60.128315, 0, 0,- -0.137066543, 3.28959703, 0, -0.00881684758, 0, 0, -90.1924591, 0, 0, 0,- 0, 0- ],- "blendShapes": [0.274133086, 0],- "animatedMaps": [0.274133086, 0.482378989]- },- {- "lod": 0,- "gui": [0.33959043, 0.621266484],- "quats": [- 0.118679516, -0.600758433, 0.561587572, -0.556438565, 0.247279972,- -0.51948595, -0.14484641, 0.804988444- ],- "rawControls": [- 0.33959043, 0.378733516, 0.560633242, 0.118679516, -0.600758433,- 0.561587572, -0.556438565, 0.247279972, -0.51948595, -0.14484641,- 0.804988444- ],- "psdControls": [0.318495899],- "rbfControls": [0, 0.19456701, 0.233232126, 0.0570291094, 0.0480792597],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.469683379, 0, 0, 5.72699213, 3.56775737, 0,- 0, 0, 0, 0, 0, 0, 81.7310181, 49.0823631, 109.703293, 0, 0, 0, 0, 0,- 0.175068855, 17.0761433, 0, 0, -0.169795215, 4.07508516, 0.0318495892,- 0.0931363776, -0.276972502, 0, 25.6142159, 0, 0, 0, 0, 0- ],- "blendShapes": [0.33959043, 0.318495899],- "animatedMaps": [0.33959043, 0.402986825]- },- {- "lod": 1,- "raw": [- 0.644818008, 0.00183112628, 0.255848706, 0.0601723231, 0.687196195,- 1.16314745, 1.11071718, 0.767554998, 1.11877823, 0.147848874, 0.0715970322- ],- "quats": [- 0.681821465, -0.665093601, -0.144768998, 0.267977566, 0.400752217,- 0.222363055, 0.405628741, -0.790833533- ],- "rawControls": [- 0.644818008, 0.00183112628, 0.255848706, 0.681821465, -0.665093601,- -0.144768998, 0.267977566, 0.400752217, 0.222363055, 0.405628741,- -0.790833533- ],- "psdControls": [0.000702736899],- "rbfControls": [0.0160494987, 0.00157584436, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1.24051273, 0, 0, 0, 0, 0, 0, 0, 0,- -147.465988, -23.7500439, 108.394386, 0, 0, 0, 0, 0, 0, -26.8734589, 0, 0,- -0.322409004, 7.73781586, 0, 0.030523153, 0, 0, -40.3101768, 0, 0, 0, 0, 0- ],- "blendShapes": [0.644818008, 0],- "animatedMaps": [0.644818008, 0.101464905]- },- {- "lod": 0,- "gui": [0.632575512, 0.439296067],- "quats": [- 0.440924883, 0.514741063, 0.0530072376, 0.733360112, -0.495465606,- -0.468901277, 0.43251431, 0.589556515- ],- "rawControls": [- 0.632575512, 0.439296067, 0.469648033, 0.440924883, 0.514741063,- 0.0530072376, 0.733360112, -0.495465606, -0.468901277, 0.43251431,- 0.589556515- ],- "psdControls": [0.309471816],- "rbfControls": [- 0.0506628677, 0.10865701, 0.0957591534, 0.136253461, 0.162904739- ],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.454472065, 0, 0, 7.3660965, 2.90341663, 0, 0,- 0, 0, 0, 0, 0, -68.5013046, 55.3314362, -44.8613243, 0, 0, 0, 0, 0,- 0.397063673, -40.0438194, 0, 0, -0.316287756, 7.59090614, 0.0309471823,- 0.449308664, -0.0423489995, 0, -60.065731, 0, 0, 0, 0, 0- ],- "blendShapes": [0.632575512, 0.309471816],- "animatedMaps": [0.632575512, 0.451436847]- },- {- "lod": 1,- "raw": [- 0.298351288, 0.680984139, 0.278056473, 0.645792723, 0.0537923835,- 1.07883203, 0.753628552, 0.638346374, 0.170050412, 1.07003736, 0.558121681- ],- "quats": [- -0.534918189, -0.188765988, -0.685039282, 0.457111716, -0.498876929,- 0.596137345, -0.591838896, 0.213234276- ],- "rawControls": [- 0.298351288, 0.680984139, 0.278056473, -0.534918189, -0.188765988,- -0.685039282, 0.457111716, -0.498876929, 0.596137345, -0.591838896,- 0.213234276- ],- "psdControls": [0.284028083],- "rbfControls": [0.00213075127, 0.00575428829, 0.108532667, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13.0814838, 0, 0, 0, 0, 0, 0, 0, 0,- 28.1854057, -55.6091537, 60.441124, 0, 0, 0, 0, 0, 0, -66.8567429, 0, 0,- -0.149175644, 3.58021545, 0, 0.0527735464, 0, 0, -100.28511, 0, 0, 0, 0, 0- ],- "blendShapes": [0.298351288, 0],- "animatedMaps": [0.298351288, 0.644787312]- },- {- "lod": 0,- "gui": [1.18924832, 0.665288627],- "quats": [- 0.719889641, 0.688139677, -0.0644612536, -0.0637770966, 0.793470025,- 0.0922877789, -0.241503999, -0.550966442- ],- "rawControls": [- 0, 0.334711373, 0.582644343, 0.719889641, 0.688139677, -0.0644612536,- -0.0637770966, 0.793470025, 0.0922877789, -0.241503999, -0.550966442- ],- "psdControls": [0.292526543],- "rbfControls": [0.011556847, 0.238477573, 0, 0.0107843745, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.458677858, 0, 0, 4.65858507, 3.78477955, 0,- 0, 0, 0, 0, 0, 0, 170.558228, -4.58949089, -114.80899, 0, 0, 0, 0, 0,- -0.0731316358, -55.2248306, 0, 0, 0, 0, 0.0292526539, -0.183010757,- 0.360412449, 0, -82.8372421, 0, 0, 0, 0, 0- ],- "blendShapes": [0, 0.292526543],- "animatedMaps": [0, 0.367769092]- },- {- "lod": 1,- "raw": [- 0.0999491289, 0.195158675, 0.812806726, 1.01261973, 0.420577466,- 0.0359534025, 0.477812588, 0.135317162, 0.323836416, 0.123398073,- 0.352078497- ],- "quats": [- 0.508971572, -0.453364044, 0.197989345, 0.704421103, -0.0258567538,- -0.178523421, 0.670926154, -0.719248891- ],- "rawControls": [- 0.0999491289, 0.195158675, 0.812806726, 0.508971572, -0.453364044,- 0.197989345, 0.704421103, -0.0258567538, -0.178523421, 0.670926154,- -0.719248891- ],- "psdControls": [0.237939432],- "rbfControls": [0.100113079, 0.000205698016, 0, 0, 0.138007492],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.55295825, 0, 0, 0, 0, 0, 0, 0, 0,- -60.9636002, -60.9133224, 17.2739563, 0, 0, 0, 0, 0, 0, 2.05887771, 0, 0,- -0.0499745645, 1.19938958, 0, 0.200020462, 0, 0, 3.08831596, 0, 0, 0, 0, 0- ],- "blendShapes": [0.0999491289, 0],- "animatedMaps": [0.0999491289, 0.25612694]- },- {- "lod": 0,- "gui": [0.853938341, 0.783671558],- "quats": [- -0.516591191, 0.526201606, -0.63989079, -0.21629864, -0.499890089,- 0.34348163, -0.340654552, 0.718390346- ],- "rawControls": [- 0.853938341, 0.216328442, 0.641835809, -0.516591191, 0.526201606,- -0.63989079, -0.21629864, -0.499890089, 0.34348163, -0.340654552,- 0.718390346- ],- "psdControls": [0.208271012],- "rbfControls": [0.0461922921, 0.275000006, 0, 0.176739439, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.429082125, 0, 0, 1.74220276, 4.39722633, 0,- 0, 0, 0, 0, 0, 0, 126.723114, -54.156311, 151.617157, 0, 0, 0, 0, 0,- 0.588385999, -34.8320236, 0, 0, -0.426969171, 10.2472601, 0.0208271015,- 0.347602874, 0.456684887, 0, -52.2480469, 0, 0, 0, 0, 0- ],- "blendShapes": [0.853938341, 0.208271012],- "animatedMaps": [0.853938341, 0.273062766]- },- {- "lod": 1,- "raw": [- 0.57740432, 0.218265235, 1.10395658, 1.15887392, 0.0642027855,- 0.280145019, 0.691052556, 0.228877693, 0.536454082, 1.10606325,- 0.118817575- ],- "quats": [- 0.24430351, -0.222009882, 0.610368133, -0.720054269, -0.378102511,- 0.363692522, -0.603951395, 0.600007415- ],- "rawControls": [- 0.57740432, 0.218265235, 1.10395658, 0.24430351, -0.222009882,- 0.610368133, -0.720054269, -0.378102511, 0.363692522, -0.603951395,- 0.600007415- ],- "psdControls": [0.327397853],- "rbfControls": [0, 0.0548306927, 0.23031728, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.172284484, 0, 0, 0, 0, 0, 0, 0, 0,- 33.4616089, 15.829524, 60.9474983, 0, 0, 0, 0, 0, 0, -32.2176132, 0, 0,- -0.28870216, 6.92885208, 0, 0.0603279471, 0, 0, -48.3264198, 0, 0, 0, 0, 0- ],- "blendShapes": [0.57740432, 0],- "animatedMaps": [0.57740432, 0.274612188]- },- {- "lod": 0,- "gui": [0.289680362, 0.180432275],- "quats": [- 0.257647395, 0.277939737, -0.621192038, -0.685921192, 0.0158271473,- -0.445251465, -0.854672492, -0.26652509- ],- "rawControls": [- 0.289680362, 0.180432275, 0.34021613, 0.257647395, 0.277939737,- -0.621192038, -0.685921192, 0.0158271473, -0.445251465, -0.854672492,- -0.26652509- ],- "psdControls": [0.0920789614],- "rbfControls": [0.22998625, 0, 0, 0.0461158715, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.26032421, 0, 0, 2.18380165, 2.36746311, 0, 0,- 0, 0, 0, 0, 0, 40.1255341, -20.7301922, -66.6432343, 0, 0, 0, 0, 0,- 0.194240525, -3.39842319, 0, 0, -0.144840181, 3.47616434, 0.00920789596,- 0.598320127, 0.0115289679, 0, -5.09763575, 0, 0, 0, 0, 0- ],- "blendShapes": [0.289680362, 0.0920789614],- "animatedMaps": [0.289680362, 0.244345829]- },- {- "lod": 1,- "raw": [- 1.02489662, 0.708650351, 0.119691759, 0.275359094, 0.0428633466,- 0.247738421, 0.301843643, 0.984621346, 0.779608846, 1.02246809,- 0.0855234191- ],- "quats": [- -0.44027102, 0.170514673, -0.677932203, -0.563466191, -0.610268295,- -0.738997936, -0.153629676, -0.240525961- ],- "rawControls": [- 1.02489662, 0.708650351, 0.119691759, -0.44027102, 0.170514673,- -0.677932203, -0.563466191, -0.610268295, -0.738997936, -0.153629676,- -0.240525961- ],- "psdControls": [0.127229407],- "rbfControls": [0.147179693, 0.00707534002, 0.104691677, 0, 0.186262116],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13.9562368, 0, 0, 0, 0, 0, 0, 0, 0,- -21.835041, -43.5574226, -59.5043678, 0, 0, 0, 0, 0, 0, 68.4890442, 0, 0,- -0.512448311, 12.2987595, 0, 0.339629889, 0, 0, 102.733566, 0, 0, 0, 0, 0- ],- "blendShapes": [1.02489662, 0],- "animatedMaps": [0, 0]- },- {- "lod": 0,- "gui": [0.691620588, 0.054342486],- "quats": [- 0.660790563, 0.733216643, 0.139903426, 0.0785884634, -0.364146441,- -0.664562345, 0.259824008, -0.598536372- ],- "rawControls": [- 0.691620588, 0.054342486, 0.277171254, 0.660790563, 0.733216643,- 0.139903426, 0.0785884634, -0.364146441, -0.664562345, 0.259824008,- -0.598536372- ],- "psdControls": [0.0225932635],- "rbfControls": [0.0118719656, 0, 0, 0.149973482, 0.300000012],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.165756866, 0, 0, -0.231226787, 2.03359795, 0,- 0, 0, 0, 0, 0, 0, -164.471069, 3.4416914, -120.844093, 0, 0, 0, 0, 0,- 0.513067126, 31.3161278, 0, 0, -0.345810294, 8.29944706, 0.0022593264,- 0.473664373, 0.0374933705, 0, 46.9741707, 0, 0, 0, 0, 0- ],- "blendShapes": [0.691620588, 0.0225932635],- "animatedMaps": [0.691620588, 0.143473998]- },- {- "lod": 1,- "raw": [- 0.852707267, 1.19184208, 0.308484584, 0.597555697, 0.350150526,- 0.593521714, 0.846252084, 0.0517903119, 0.957521856, 0.909278333,- 0.0268733036- ],- "quats": [- -0.251632333, 0.960732102, 0.108770929, 0.0429397449, 0.340674251,- -0.701071739, 0.329677999, 0.532683611- ],- "rawControls": [- 0.852707267, 1.19184208, 0.308484584, -0.251632333, 0.960732102,- 0.108770929, 0.0429397449, 0.340674251, -0.701071739, 0.329677999,- 0.532683611- ],- "psdControls": [0.462726891],- "rbfControls": [0.00873098522, 0.0320259482, 0, 0, 0],- "joints": [- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23.6825981, 0, 0, 0, 0, 0, 0, 0, 0,- -172.207733, 6.49180126, 159.935989, 0, 0, 0, 0, 0, 0, 32.6006699, 0, 0,- -0.426353633, 10.2324867, 0, -0.0145639777, 0, 0, 48.9010048, 0, 0, 0, 0,- 0- ],- "blendShapes": [0.852707267, 0],- "animatedMaps": [0.852707267, 0]- }-]diff --git a/packages/dna/fixtures/oracle.cpp b/packages/dna/fixtures/oracle.cppdeleted file mode 100644index 2f96e753..00000000--- a/packages/dna/fixtures/oracle.cpp+++ /dev/null@@ -1,751 +0,0 @@-// Test oracle for framefields' DNA reader, built against OpenRigLogic 5.8-// (https://github.com/EpicGames/openriglogic, commit d3d329bbd6992ac38adc1c1b24203ceb998f75c0).-// oracle write <out.dna> writes a small synthetic character with Epic's DNA writer-// oracle dump <in.dna> prints what Epic's DNA reader reads, as JSON-// oracle eval <in.dna> <seed> <n> prints RigLogic's outputs for n seeded random control sets-// (GUI and raw controls alternately, cycling the LODs), as JSON-// It regenerates oracle.dna and oracle.json, which dna-oracle.test.ts compares readDna against:-// git clone --branch 5.8 https://github.com/EpicGames/openriglogic && cd openriglogic-// cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build --target riglogic4-// clang++ -std=c++17 -Iinclude <this file> build/libriglogic4*.a -o oracle-// ./oracle write oracle.dna && ./oracle dump oracle.dna > oracle.json && ./oracle eval oracle.dna 7 48 > oracle-eval.json-#include <dna/BinaryStreamReader.h>-#include <dna/BinaryStreamWriter.h>-#include <dna/layers/Geometry.h>-#include <dna/types/Vector3.h>-#include <riglogic/RigLogic.h>-#include <pma/ScopedPtr.h>-#include <trio/streams/FileStream.h>--#include <cstdio>-#include <cmath>-#include <cstdlib>-#include <cstring>-#include <string>-#include <vector>--using namespace dna;--static void writeDna(const char* path) {- auto stream = pma::makeScoped<trio::FileStream>(path, trio::FileStream::AccessMode::Write, trio::FileStream::OpenMode::Binary);- auto w = pma::makeScoped<BinaryStreamWriter>(stream.get());-- w->setName("Oracle");- w->setArchetype(Archetype::other);- w->setGender(Gender::female);- w->setAge(42);- w->setMetaData("made by", "oracle");- w->setMetaData("purpose", "parity");- w->setTranslationUnit(TranslationUnit::cm);- w->setRotationUnit(RotationUnit::degrees);- w->setCoordinateSystem({Direction::right, Direction::up, Direction::front});- w->setRotationSequence(RotationSequence::zyx);- w->setRotationSign({RotationDirection::positive, RotationDirection::negative, RotationDirection::positive});- w->setFaceWindingOrder(FaceWindingOrder::ccw);- w->setLODCount(2);- w->setDBMaxLOD(0);- w->setDBComplexity("Oracle");- w->setDBName("OracleDB");-- const char* gui[] = {"CTRL_jaw", "CTRL_smile"};- for (std::uint16_t i = 0; i < 2; ++i) w->setGUIControlName(i, gui[i]);- // Raw controls: three face controls, then the arm's and forearm's rotations- // as quaternions (the host fills them from the animated skeleton).- const char* raw[] = {"jawOpen", "smileL", "smileR", "arm.qx", "arm.qy", "arm.qz", "arm.qw",- "forearm.qx", "forearm.qy", "forearm.qz", "forearm.qw"};- for (std::uint16_t i = 0; i < 11; ++i) w->setRawControlName(i, raw[i]);- const char* joints[] = {"root", "neck", "head", "jaw", "eyeL"};- for (std::uint16_t i = 0; i < 5; ++i) w->setJointName(i, joints[i]);- std::uint16_t lod0Joints[] = {0, 1, 2, 3, 4};- std::uint16_t lod1Joints[] = {0, 1, 2};- w->setJointIndices(0, lod0Joints, 5);- w->setJointIndices(1, lod1Joints, 3);- w->setLODJointMapping(0, 0);- w->setLODJointMapping(1, 1);- const char* channels[] = {"jawOpen", "smile_corrective"};- for (std::uint16_t i = 0; i < 2; ++i) w->setBlendShapeChannelName(i, channels[i]);- std::uint16_t bs0[] = {0, 1};- std::uint16_t bs1[] = {0};- w->setBlendShapeChannelIndices(0, bs0, 2);- w->setBlendShapeChannelIndices(1, bs1, 1);- w->setLODBlendShapeChannelMapping(0, 0);- w->setLODBlendShapeChannelMapping(1, 1);- const char* maps[] = {"head_wm1_forehead", "head_wm2_cheek"};- for (std::uint16_t i = 0; i < 2; ++i) w->setAnimatedMapName(i, maps[i]);- std::uint16_t am0[] = {0, 1};- w->setAnimatedMapIndices(0, am0, 2);- w->setLODAnimatedMapMapping(0, 0);- w->setLODAnimatedMapMapping(1, 0);- const char* meshes[] = {"head_lod0_mesh", "head_lod1_mesh"};- for (std::uint16_t i = 0; i < 2; ++i) w->setMeshName(i, meshes[i]);- std::uint16_t m0[] = {0};- std::uint16_t m1[] = {1};- w->setMeshIndices(0, m0, 1);- w->setMeshIndices(1, m1, 1);- w->setLODMeshMapping(0, 0);- w->setLODMeshMapping(1, 1);- w->setMeshBlendShapeChannelMapping(0, 0, 0);- w->setMeshBlendShapeChannelMapping(1, 0, 1);- w->setMeshBlendShapeChannelMapping(2, 1, 0);- std::uint16_t hierarchy[] = {0, 0, 1, 2, 2};- w->setJointHierarchy(hierarchy, 5);- Vector3 t[] = {{0.0f, 0.0f, 0.0f}, {0.0f, 150.0f, -2.0f}, {0.0f, 12.5f, 1.0f}, {0.0f, -3.0f, 4.5f}, {3.2f, 4.0f, 8.0f}};- Vector3 r[] = {{0.0f, 0.0f, 0.0f}, {-10.0f, 0.0f, 0.0f}, {12.0f, 5.0f, -3.0f}, {0.0f, 90.0f, 25.0f}, {1.5f, -2.5f, 3.5f}};- w->setNeutralJointTranslations(t, 5);- w->setNeutralJointRotations(r, 5);-- // CTRL_smile drives smileL through two overlapping intervals: where both- // match (0.4 … 0.6) only the first counts.- std::uint16_t gIn[] = {0, 1, 1, 1};- std::uint16_t gOut[] = {0, 1, 1, 2};- float gFrom[] = {0.0f, 0.0f, 0.4f, 0.0f};- float gTo[] = {1.0f, 0.6f, 1.0f, 1.0f};- float gSlope[] = {1.0f, 1.0f, -1.0f, 0.5f};- float gCut[] = {0.0f, 0.0f, 1.0f, 0.25f};- w->setGUIToRawInputIndices(gIn, 4);- w->setGUIToRawOutputIndices(gOut, 4);- w->setGUIToRawFromValues(gFrom, 4);- w->setGUIToRawToValues(gTo, 4);- w->setGUIToRawSlopeValues(gSlope, 4);- w->setGUIToRawCutValues(gCut, 4);- w->setPSDCount(1);- std::uint16_t psdRows[] = {11, 11};- std::uint16_t psdCols[] = {1, 2};- float psdValues[] = {1.5f, 1.0f}; // a weight above 1: the PSD caps at 1- w->setPSDRowIndices(psdRows, 2);- w->setPSDColumnIndices(psdCols, 2);- w->setPSDValues(psdValues, 2);- w->setJointRowCount(45);- w->setJointColumnCount(4);- std::uint16_t jgLods[] = {4, 2};- std::uint16_t jgIn[] = {0, 11};- std::uint16_t jgOut[] = {33, 34, 35, 29};- float jgValues[] = {-0.5f, 0.0f, 12.0f, 0.0f, 0.0f, 0.1f, 0.75f, -0.25f};- std::uint16_t jgJoints[] = {3};- w->setJointGroupLODs(0, jgLods, 2);- w->setJointGroupInputIndices(0, jgIn, 2);- w->setJointGroupOutputIndices(0, jgOut, 4);- w->setJointGroupValues(0, jgValues, 8);- w->setJointGroupJointIndices(0, jgJoints, 1);- // Group 1: the neck's rotation and translation from smileL, smileR and the PSD.- std::uint16_t jg1Lods[] = {3, 1};- std::uint16_t jg1In[] = {1, 2, 11};- std::uint16_t jg1Out[] = {12, 13, 9};- float jg1Values[] = {20.0f, -5.0f, 3.0f, 0.0f, 7.5f, -2.0f, 0.5f, 0.5f, 0.0f};- std::uint16_t jg1Joints[] = {1};- w->setJointGroupLODs(1, jg1Lods, 2);- w->setJointGroupInputIndices(1, jg1In, 3);- w->setJointGroupOutputIndices(1, jg1Out, 3);- w->setJointGroupValues(1, jg1Values, 9);- w->setJointGroupJointIndices(1, jg1Joints, 1);- // Group 2: the eye joint's translation from the RBF pose controls (12 … 16).- std::uint16_t jg2Lods[] = {2, 1};- std::uint16_t jg2In[] = {12, 13, 14, 15};- std::uint16_t jg2Out[] = {36, 37};- float jg2Values[] = {2.0f, -1.0f, 0.5f, 3.0f, 0.0f, 1.5f, -2.5f, 0.25f};- std::uint16_t jg2Joints[] = {4};- w->setJointGroupLODs(2, jg2Lods, 2);- w->setJointGroupInputIndices(2, jg2In, 4);- w->setJointGroupOutputIndices(2, jg2Out, 2);- w->setJointGroupValues(2, jg2Values, 8);- w->setJointGroupJointIndices(2, jg2Joints, 1);-- // RBF: solver 0 reads the arm's quaternion (interpolative, quaternion- // distance, Gaussian); solver 1 the forearm's twist (additive, twist angle,- // linear, automatic radius). Their poses write controls 12 … 16.- const float s45 = 0.38268343f, c45 = 0.92387953f;- // The arm's fourth pose sits close to its second, so interpolation overshoots- // and clamps; the forearm has four poses, so the automatic radius averages- // six distances.- const float s30 = 0.5f, c30 = 0.8660254f;- float armTargets[] = {0, 0, 0, 1, 0, 0, s45, c45, 0, s45, 0, c45, 0, 0, s30, c30};- float forearmTargets[] = {0, 0, 0, 1, s45, 0, 0, c45, 0.70710677f, 0, 0, 0.70710677f, c45, 0, 0, s45};- std::uint16_t armRaw[] = {3, 4, 5, 6};- std::uint16_t forearmRaw[] = {7, 8, 9, 10};- std::uint16_t armPoses[] = {0, 1, 2, 6};- std::uint16_t forearmPoses[] = {3, 4, 5, 7};- w->setRBFSolverName(0, "arm_rbf");- w->setRBFSolverRawControlIndices(0, armRaw, 4);- w->setRBFSolverPoseIndices(0, armPoses, 4);- w->setRBFSolverRawControlValues(0, armTargets, 16);- w->setRBFSolverType(0, RBFSolverType::Interpolative);- w->setRBFSolverRadius(0, 50.0f);- w->setRBFSolverAutomaticRadius(0, AutomaticRadius::Off);- w->setRBFSolverWeightThreshold(0, 0.001f);- w->setRBFSolverDistanceMethod(0, RBFDistanceMethod::Quaternion);- w->setRBFSolverNormalizeMethod(0, RBFNormalizeMethod::OnlyNormalizeAboveOne);- w->setRBFSolverFunctionType(0, RBFFunctionType::Gaussian);- w->setRBFSolverTwistAxis(0, TwistAxis::X);- w->setRBFSolverName(1, "forearm_twist");- w->setRBFSolverRawControlIndices(1, forearmRaw, 4);- w->setRBFSolverPoseIndices(1, forearmPoses, 4);- w->setRBFSolverRawControlValues(1, forearmTargets, 16);- w->setRBFSolverType(1, RBFSolverType::Additive);- w->setRBFSolverRadius(1, 0.0f);- w->setRBFSolverAutomaticRadius(1, AutomaticRadius::On);- w->setRBFSolverWeightThreshold(1, 0.0f);- w->setRBFSolverDistanceMethod(1, RBFDistanceMethod::TwistAngle);- w->setRBFSolverNormalizeMethod(1, RBFNormalizeMethod::AlwaysNormalize);- w->setRBFSolverFunctionType(1, RBFFunctionType::Linear);- w->setRBFSolverTwistAxis(1, TwistAxis::X);- // Solver 2: the arm's swing about z (additive, swing angle, cubic).- float swingTargets[] = {0, 0, 0, 1, s45, 0, 0, c45, 0, s45, 0, c45};- std::uint16_t swingPoses[] = {8, 9, 10};- w->setRBFSolverName(2, "arm_swing");- w->setRBFSolverRawControlIndices(2, armRaw, 4);- w->setRBFSolverPoseIndices(2, swingPoses, 3);- w->setRBFSolverRawControlValues(2, swingTargets, 12);- w->setRBFSolverType(2, RBFSolverType::Additive);- w->setRBFSolverRadius(2, 60.0f);- w->setRBFSolverAutomaticRadius(2, AutomaticRadius::Off);- w->setRBFSolverWeightThreshold(2, 0.0f);- w->setRBFSolverDistanceMethod(2, RBFDistanceMethod::SwingAngle);- w->setRBFSolverNormalizeMethod(2, RBFNormalizeMethod::OnlyNormalizeAboveOne);- w->setRBFSolverFunctionType(2, RBFFunctionType::Cubic);- w->setRBFSolverTwistAxis(2, TwistAxis::Z);- // Solver 3: both smiles together (interpolative, Euclidean, quintic, automatic radius).- std::uint16_t smileRaw[] = {1, 2};- float smileTargets[] = {0, 0, 1, 0, 0, 1, 1, 1};- std::uint16_t smilePoses[] = {11, 12, 13, 14};- w->setRBFSolverName(3, "smiles");- w->setRBFSolverRawControlIndices(3, smileRaw, 2);- w->setRBFSolverPoseIndices(3, smilePoses, 4);- w->setRBFSolverRawControlValues(3, smileTargets, 8);- w->setRBFSolverType(3, RBFSolverType::Interpolative);- w->setRBFSolverRadius(3, 0.0f);- w->setRBFSolverAutomaticRadius(3, AutomaticRadius::On);- w->setRBFSolverWeightThreshold(3, 0.01f);- w->setRBFSolverDistanceMethod(3, RBFDistanceMethod::Euclidean);- w->setRBFSolverNormalizeMethod(3, RBFNormalizeMethod::OnlyNormalizeAboveOne);- w->setRBFSolverFunctionType(3, RBFFunctionType::Quintic);- w->setRBFSolverTwistAxis(3, TwistAxis::X);- // Solver 4: the jaw (additive, Euclidean, exponential; radius in degrees like every RBF radius).- std::uint16_t jawRaw[] = {0};- float jawTargets[] = {0, 1};- std::uint16_t jawPoses[] = {15, 16};- w->setRBFSolverName(4, "jaw");- w->setRBFSolverRawControlIndices(4, jawRaw, 1);- w->setRBFSolverPoseIndices(4, jawPoses, 2);- w->setRBFSolverRawControlValues(4, jawTargets, 2);- w->setRBFSolverType(4, RBFSolverType::Additive);- w->setRBFSolverRadius(4, 40.0f);- w->setRBFSolverAutomaticRadius(4, AutomaticRadius::Off);- w->setRBFSolverWeightThreshold(4, 0.0f);- w->setRBFSolverDistanceMethod(4, RBFDistanceMethod::Euclidean);- w->setRBFSolverNormalizeMethod(4, RBFNormalizeMethod::AlwaysNormalize);- w->setRBFSolverFunctionType(4, RBFFunctionType::Exponential);- w->setRBFSolverTwistAxis(4, TwistAxis::X);- std::uint16_t rbfLod0[] = {0, 1, 2, 3, 4};- std::uint16_t rbfLod1[] = {0, 2};- w->setRBFSolverIndices(0, rbfLod0, 5);- w->setRBFSolverIndices(1, rbfLod1, 2);- w->setLODRBFSolverMapping(0, 0);- w->setLODRBFSolverMapping(1, 1);- const char* poses[] = {"arm_rest", "arm_up", "arm_forward", "forearm_rest", "forearm_twist45", "forearm_twist90",- "arm_up30", "forearm_twist135", "swing_rest", "swing_x", "swing_y", "smiles_none", "smiles_left",- "smiles_right", "smiles_both", "jaw_closed", "jaw_open"};- float poseScales[] = {1.0f, 1.0f, 0.8f, 1.0f, 1.0f, 1.2f, 0.9f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.1f, 1.0f, 1.0f};- for (std::uint16_t i = 0; i < 17; ++i) {- w->setRBFPoseName(i, poses[i]);- w->setRBFPoseScale(i, poseScales[i]);- }- const char* poseControls[] = {"arm_up_pc", "arm_forward_pc", "forearm_twist45_pc", "forearm_twist90_pc", "arm_up_half_pc"};- for (std::uint16_t i = 0; i < 5; ++i) w->setRBFPoseControlName(i, poseControls[i]);- std::uint16_t none[] = {0};- std::uint16_t up[] = {12, 16};- float upWeights[] = {1.0f, 0.5f};- std::uint16_t forward[] = {13};- float one[] = {1.0f};- std::uint16_t gate[] = {0}; // arm_forward only counts as far as jawOpen allows- std::uint16_t twist45[] = {14};- std::uint16_t twist90[] = {15};- for (std::uint16_t i : {0, 3}) {- w->setRBFPoseInputControlIndices(i, none, 0);- w->setRBFPoseOutputControlIndices(i, none, 0);- w->setRBFPoseOutputControlWeights(i, one, 0);- }- w->setRBFPoseInputControlIndices(1, none, 0);- w->setRBFPoseOutputControlIndices(1, up, 2);- w->setRBFPoseOutputControlWeights(1, upWeights, 2);- w->setRBFPoseInputControlIndices(2, gate, 1);- w->setRBFPoseOutputControlIndices(2, forward, 1);- w->setRBFPoseOutputControlWeights(2, one, 1);- w->setRBFPoseInputControlIndices(4, none, 0);- w->setRBFPoseOutputControlIndices(4, twist45, 1);- w->setRBFPoseOutputControlWeights(4, one, 1);- w->setRBFPoseInputControlIndices(5, none, 0);- w->setRBFPoseOutputControlIndices(5, twist90, 1);- w->setRBFPoseOutputControlWeights(5, one, 1);- std::uint16_t up30[] = {12};- float up30Weight[] = {0.7f};- w->setRBFPoseInputControlIndices(6, none, 0);- w->setRBFPoseOutputControlIndices(6, up30, 1);- w->setRBFPoseOutputControlWeights(6, up30Weight, 1);- w->setRBFPoseInputControlIndices(7, none, 0);- w->setRBFPoseOutputControlIndices(7, twist90, 1);- w->setRBFPoseOutputControlWeights(7, one, 1);- // New poses: each writes one control with its own weight, or nothing.- struct PoseOut {- std::uint16_t pose;- std::uint16_t control;- float weight;- };- const PoseOut outs[] = {{9, 16, 0.3f}, {10, 14, 0.4f}, {14, 13, 0.5f}, {12, 16, 0.6f}, {16, 15, 0.2f}};- for (std::uint16_t pose : {8, 11, 13, 15}) {- w->setRBFPoseInputControlIndices(pose, none, 0);- w->setRBFPoseOutputControlIndices(pose, none, 0);- w->setRBFPoseOutputControlWeights(pose, one, 0);- }- for (const auto& o : outs) {- w->setRBFPoseInputControlIndices(o.pose, none, 0);- w->setRBFPoseOutputControlIndices(o.pose, &o.control, 1);- w->setRBFPoseOutputControlWeights(o.pose, &o.weight, 1);- }-- // Twist and swing: the forearm's twist spreads to the jaw and eye joints- // (half and a quarter); the arm's swing turns the head by 0.3.- std::uint16_t twistOut[] = {3, 4};- float twistWeights[] = {0.5f, 0.25f};- w->setTwistSetupTwistAxis(0, TwistAxis::X);- w->setTwistInputControlIndices(0, forearmRaw, 4);- w->setTwistOutputJointIndices(0, twistOut, 2);- w->setTwistBlendWeights(0, twistWeights, 2);- std::uint16_t swingOut[] = {2};- float swingWeights[] = {0.3f};- w->setSwingSetupTwistAxis(0, TwistAxis::Y);- w->setSwingInputControlIndices(0, armRaw, 4);- w->setSwingOutputJointIndices(0, swingOut, 1);- w->setSwingBlendWeights(0, swingWeights, 1);- std::uint16_t bsLods[] = {2, 1};- std::uint16_t bsIn[] = {0, 11};- std::uint16_t bsOut[] = {0, 1};- w->setBlendShapeChannelLODs(bsLods, 2);- w->setBlendShapeChannelInputIndices(bsIn, 2);- w->setBlendShapeChannelOutputIndices(bsOut, 2);- // The cheek map rises then falls back over two overlapping intervals; LOD 1 keeps the first two rows.- std::uint16_t amLods[] = {3, 2};- std::uint16_t amIn[] = {0, 1, 1};- std::uint16_t amOut[] = {0, 1, 1};- float amFrom[] = {0.0f, 0.0f, 0.5f};- float amTo[] = {1.0f, 0.7f, 1.0f};- float amSlope[] = {1.0f, 0.8f, -0.5f};- float amCut[] = {0.0f, 0.1f, 0.9f};- w->setAnimatedMapLODs(amLods, 2);- w->setAnimatedMapInputIndices(amIn, 3);- w->setAnimatedMapOutputIndices(amOut, 3);- w->setAnimatedMapFromValues(amFrom, 3);- w->setAnimatedMapToValues(amTo, 3);- w->setAnimatedMapSlopeValues(amSlope, 3);- w->setAnimatedMapCutValues(amCut, 3);-- // Mesh 0: a quad and a triangle; mesh 1: one triangle.- Position p0[] = {{-5.0f, 150.0f, 9.0f}, {5.0f, 150.0f, 9.0f}, {5.0f, 165.0f, 8.0f}, {-5.0f, 165.0f, 8.0f}, {0.0f, 170.0f, 7.5f}};- TextureCoordinate uv0[] = {{0.1f, 0.2f}, {0.9f, 0.2f}, {0.9f, 0.8f}, {0.1f, 0.8f}, {0.5f, 0.95f}, {0.55f, 0.95f}};- Normal n0[] = {{0.0f, 0.0f, 1.0f}, {0.0f, 0.6f, 0.8f}};- VertexLayout l0[] = {{0, 0, 0}, {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 1}, {4, 5, 1}};- w->setVertexPositions(0, p0, 5);- w->setVertexTextureCoordinates(0, uv0, 6);- w->setVertexNormals(0, n0, 2);- w->setVertexLayouts(0, l0, 6);- std::uint32_t f0[] = {0, 1, 2, 3};- std::uint32_t f1[] = {3, 2, 4};- w->setFaceVertexLayoutIndices(0, 0, f0, 4);- w->setFaceVertexLayoutIndices(0, 1, f1, 3);- w->setMaximumInfluencePerVertex(0, 6);- float sw0[] = {1.0f};- std::uint16_t sj0[] = {1};- float sw1[] = {0.5f, 0.5f};- std::uint16_t sj1[] = {1, 2};- float sw2[] = {0.3f, 0.2f, 0.15f, 0.15f, 0.1f, 0.1f};- std::uint16_t sj2[] = {2, 3, 4, 1, 0, 3};- w->setSkinWeightsValues(0, 0, sw0, 1);- w->setSkinWeightsJointIndices(0, 0, sj0, 1);- w->setSkinWeightsValues(0, 1, sw1, 2);- w->setSkinWeightsJointIndices(0, 1, sj1, 2);- w->setSkinWeightsValues(0, 2, sw2, 6);- w->setSkinWeightsJointIndices(0, 2, sj2, 6);- w->setSkinWeightsValues(0, 3, sw0, 1);- w->setSkinWeightsJointIndices(0, 3, sj0, 1);- w->setSkinWeightsValues(0, 4, sw1, 2);- w->setSkinWeightsJointIndices(0, 4, sj1, 2);- Delta d0[] = {{0.0f, -1.5f, 0.2f}, {0.0f, -1.5f, 0.2f}};- std::uint32_t v0[] = {0, 1};- Delta d1[] = {{0.3f, 0.4f, -0.1f}};- std::uint32_t v1[] = {2};- w->setBlendShapeChannelIndex(0, 0, 0);- w->setBlendShapeTargetDeltas(0, 0, d0, 2);- w->setBlendShapeTargetVertexIndices(0, 0, v0, 2);- w->setBlendShapeChannelIndex(0, 1, 1);- w->setBlendShapeTargetDeltas(0, 1, d1, 1);- w->setBlendShapeTargetVertexIndices(0, 1, v1, 1);-- Position p1[] = {{-5.0f, 150.0f, 9.0f}, {5.0f, 150.0f, 9.0f}, {0.0f, 170.0f, 7.5f}};- TextureCoordinate uv1[] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.5f, 1.0f}};- Normal n1[] = {{0.0f, 0.0f, 1.0f}};- VertexLayout l1[] = {{0, 0, 0}, {1, 1, 0}, {2, 2, 0}};- w->setVertexPositions(1, p1, 3);- w->setVertexTextureCoordinates(1, uv1, 3);- w->setVertexNormals(1, n1, 1);- w->setVertexLayouts(1, l1, 3);- std::uint32_t f2[] = {0, 1, 2};- w->setFaceVertexLayoutIndices(1, 0, f2, 3);- w->setMaximumInfluencePerVertex(1, 1);- for (std::uint32_t v = 0; v < 3; ++v) {- w->setSkinWeightsValues(1, v, sw0, 1);- w->setSkinWeightsJointIndices(1, v, sj0, 1);- }- Delta d2[] = {{0.0f, -1.0f, 0.0f}};- std::uint32_t v2[] = {0};- w->setBlendShapeChannelIndex(1, 0, 0);- w->setBlendShapeTargetDeltas(1, 0, d2, 1);- w->setBlendShapeTargetVertexIndices(1, 0, v2, 1);-- w->write();- if (!Status::isOk()) {- std::fprintf(stderr, "write failed: %s\n", Status::get().message);- std::exit(1);- }-}--static void printString(StringView s) {- std::putchar('"');- for (std::size_t i = 0; i < s.size(); ++i) {- const char c = s[i];- if (c == '"' || c == '\\') std::putchar('\\');- std::putchar(c);- }- std::putchar('"');-}--template<typename V>-static void printArray(const V& a) {- std::putchar('[');- for (std::size_t i = 0; i < a.size(); ++i) {- if (i) std::putchar(',');- std::printf("%.9g", static_cast<double>(a[i]));- }- std::putchar(']');-}--static void dumpDna(const char* path) {- auto stream = pma::makeScoped<trio::FileStream>(path, trio::FileStream::AccessMode::Read, trio::FileStream::OpenMode::Binary);- auto r = pma::makeScoped<BinaryStreamReader>(stream.get(), DataLayer::All);- r->read();- if (!Status::isOk()) {- std::fprintf(stderr, "read failed: %s\n", Status::get().message);- std::exit(1);- }- std::printf("{\"version\":[%u,%u]", r->getFileFormatGeneration(), r->getFileFormatVersion());- std::printf(",\"name\":");- printString(r->getName());- std::printf(",\"archetype\":%d,\"gender\":%d,\"age\":%u", static_cast<int>(r->getArchetype()), static_cast<int>(r->getGender()), r->getAge());- std::printf(",\"metadata\":[");- for (std::uint32_t i = 0; i < r->getMetaDataCount(); ++i) {- if (i) std::putchar(',');- const auto key = r->getMetaDataKey(i);- std::putchar('[');- printString(key);- std::putchar(',');- printString(r->getMetaDataValue(std::string(key.data(), key.size()).c_str()));- std::putchar(']');- }- std::printf("]");- const auto cs = r->getCoordinateSystem();- const auto sign = r->getRotationSign();- std::printf(",\"translationUnit\":%d,\"rotationUnit\":%d,\"coordinateSystem\":[%d,%d,%d]", static_cast<int>(r->getTranslationUnit()),- static_cast<int>(r->getRotationUnit()), static_cast<int>(cs.x), static_cast<int>(cs.y), static_cast<int>(cs.z));- std::printf(",\"rotationSequence\":%d,\"rotationSign\":[%d,%d,%d],\"faceWindingOrder\":%d", static_cast<int>(r->getRotationSequence()),- static_cast<int>(sign.x), static_cast<int>(sign.y), static_cast<int>(sign.z), static_cast<int>(r->getFaceWindingOrder()));- std::printf(",\"lodCount\":%u,\"maxLOD\":%u,\"complexity\":", r->getLODCount(), r->getDBMaxLOD());- printString(r->getDBComplexity());- std::printf(",\"dbName\":");- printString(r->getDBName());-- auto names = [&](const char* key, std::uint16_t count, auto get) {- std::printf(",\"%s\":[", key);- for (std::uint16_t i = 0; i < count; ++i) {- if (i) std::putchar(',');- printString(get(i));- }- std::printf("]");- };- names("guiControlNames", r->getGUIControlCount(), [&](std::uint16_t i) { return r->getGUIControlName(i); });- names("rawControlNames", r->getRawControlCount(), [&](std::uint16_t i) { return r->getRawControlName(i); });- names("jointNames", r->getJointCount(), [&](std::uint16_t i) { return r->getJointName(i); });- names("blendShapeChannelNames", r->getBlendShapeChannelCount(), [&](std::uint16_t i) { return r->getBlendShapeChannelName(i); });- names("animatedMapNames", r->getAnimatedMapCount(), [&](std::uint16_t i) { return r->getAnimatedMapName(i); });- names("meshNames", r->getMeshCount(), [&](std::uint16_t i) { return r->getMeshName(i); });- auto perLod = [&](const char* key, auto get) {- std::printf(",\"%s\":[", key);- for (std::uint16_t lod = 0; lod < r->getLODCount(); ++lod) {- if (lod) std::putchar(',');- printArray(get(lod));- }- std::printf("]");- };- perLod("jointsPerLod", [&](std::uint16_t l) { return r->getJointIndicesForLOD(l); });- perLod("blendShapesPerLod", [&](std::uint16_t l) { return r->getBlendShapeChannelIndicesForLOD(l); });- perLod("animatedMapsPerLod", [&](std::uint16_t l) { return r->getAnimatedMapIndicesForLOD(l); });- perLod("meshesPerLod", [&](std::uint16_t l) { return r->getMeshIndicesForLOD(l); });- std::printf(",\"meshBlendShapeChannelMapping\":[");- for (std::uint16_t i = 0; i < r->getMeshBlendShapeChannelMappingCount(); ++i) {- const auto m = r->getMeshBlendShapeChannelMapping(i);- std::printf("%s[%u,%u]", i ? "," : "", m.meshIndex, m.blendShapeChannelIndex);- }- std::printf("],\"parents\":[");- for (std::uint16_t i = 0; i < r->getJointCount(); ++i) std::printf("%s%u", i ? "," : "", r->getJointParentIndex(i));- std::printf("]");- std::printf(",\"neutralTranslations\":[");- printArray(r->getNeutralJointTranslationXs());- std::putchar(',');- printArray(r->getNeutralJointTranslationYs());- std::putchar(',');- printArray(r->getNeutralJointTranslationZs());- std::printf("],\"neutralRotations\":[");- printArray(r->getNeutralJointRotationXs());- std::putchar(',');- printArray(r->getNeutralJointRotationYs());- std::putchar(',');- printArray(r->getNeutralJointRotationZs());- std::printf("]");-- auto arr = [&](const char* key, auto view) {- std::printf(",\"%s\":", key);- printArray(view);- };- arr("guiToRawInput", r->getGUIToRawInputIndices());- arr("guiToRawOutput", r->getGUIToRawOutputIndices());- arr("guiToRawFrom", r->getGUIToRawFromValues());- arr("guiToRawTo", r->getGUIToRawToValues());- arr("guiToRawSlope", r->getGUIToRawSlopeValues());- arr("guiToRawCut", r->getGUIToRawCutValues());- std::printf(",\"psdCount\":%u", r->getPSDCount());- arr("psdRows", r->getPSDRowIndices());- arr("psdColumns", r->getPSDColumnIndices());- arr("psdValues", r->getPSDValues());- std::printf(",\"jointRowCount\":%u,\"jointColumnCount\":%u,\"jointGroups\":[", r->getJointRowCount(), r->getJointColumnCount());- for (std::uint16_t g = 0; g < r->getJointGroupCount(); ++g) {- std::printf("%s{\"lods\":", g ? "," : "");- printArray(r->getJointGroupLODs(g));- std::printf(",\"inputs\":");- printArray(r->getJointGroupInputIndices(g));- std::printf(",\"outputs\":");- printArray(r->getJointGroupOutputIndices(g));- std::printf(",\"values\":");- printArray(r->getJointGroupValues(g));- std::printf(",\"joints\":");- printArray(r->getJointGroupJointIndices(g));- std::printf("}");- }- std::printf("]");- arr("blendShapeLods", r->getBlendShapeChannelLODs());- arr("blendShapeInputs", r->getBlendShapeChannelInputIndices());- arr("blendShapeOutputs", r->getBlendShapeChannelOutputIndices());- arr("animatedMapLods", r->getAnimatedMapLODs());- arr("animatedMapInputs", r->getAnimatedMapInputIndices());- arr("animatedMapOutputs", r->getAnimatedMapOutputIndices());- arr("animatedMapFrom", r->getAnimatedMapFromValues());- arr("animatedMapTo", r->getAnimatedMapToValues());- arr("animatedMapSlope", r->getAnimatedMapSlopeValues());- arr("animatedMapCut", r->getAnimatedMapCutValues());-- std::printf(",\"mlControlCount\":%u,\"rbfSolversPerLod\":[", r->getMLControlCount());- for (std::uint16_t lod = 0; lod < r->getLODCount(); ++lod) {- if (lod) std::putchar(',');- printArray(r->getRBFSolverIndicesForLOD(lod));- }- std::printf("],\"rbfSolvers\":[");- for (std::uint16_t i = 0; i < r->getRBFSolverCount(); ++i) {- std::printf("%s{\"name\":", i ? "," : "");- printString(r->getRBFSolverName(i));- std::printf(",\"rawControlIndices\":");- printArray(r->getRBFSolverRawControlIndices(i));- std::printf(",\"poseIndices\":");- printArray(r->getRBFSolverPoseIndices(i));- std::printf(",\"rawControlValues\":");- printArray(r->getRBFSolverRawControlValues(i));- std::printf(",\"radius\":%.9g,\"weightThreshold\":%.9g,\"solverType\":%d,\"automaticRadius\":%d,\"distanceMethod\":%d,"- "\"normalizeMethod\":%d,\"functionType\":%d,\"twistAxis\":%d}",- static_cast<double>(r->getRBFSolverRadius(i)), static_cast<double>(r->getRBFSolverWeightThreshold(i)),- static_cast<int>(r->getRBFSolverType(i)), static_cast<int>(r->getRBFSolverAutomaticRadius(i)),- static_cast<int>(r->getRBFSolverDistanceMethod(i)), static_cast<int>(r->getRBFSolverNormalizeMethod(i)),- static_cast<int>(r->getRBFSolverFunctionType(i)), static_cast<int>(r->getRBFSolverTwistAxis(i)));- }- std::printf("],\"rbfPoses\":[");- for (std::uint16_t i = 0; i < r->getRBFPoseCount(); ++i) {- std::printf("%s{\"name\":", i ? "," : "");- printString(r->getRBFPoseName(i));- std::printf(",\"scale\":%.9g,\"inputs\":", static_cast<double>(r->getRBFPoseScale(i)));- printArray(r->getRBFPoseInputControlIndices(i));- std::printf(",\"outputs\":");- printArray(r->getRBFPoseOutputControlIndices(i));- std::printf(",\"weights\":");- printArray(r->getRBFPoseOutputControlWeights(i));- std::printf("}");- }- std::printf("]");- names("rbfPoseControlNames", r->getRBFPoseControlCount(), [&](std::uint16_t i) { return r->getRBFPoseControlName(i); });- auto setups = [&](const char* key, std::uint16_t count, auto axis, auto inputs, auto outputs, auto weights) {- std::printf(",\"%s\":[", key);- for (std::uint16_t i = 0; i < count; ++i) {- std::printf("%s{\"twistAxis\":%d,\"inputs\":", i ? "," : "", static_cast<int>(axis(i)));- printArray(inputs(i));- std::printf(",\"outputs\":");- printArray(outputs(i));- std::printf(",\"weights\":");- printArray(weights(i));- std::printf("}");- }- std::printf("]");- };- setups(- "twists", r->getTwistCount(), [&](std::uint16_t i) { return r->getTwistSetupTwistAxis(i); },- [&](std::uint16_t i) { return r->getTwistInputControlIndices(i); }, [&](std::uint16_t i) { return r->getTwistOutputJointIndices(i); },- [&](std::uint16_t i) { return r->getTwistBlendWeights(i); });- setups(- "swings", r->getSwingCount(), [&](std::uint16_t i) { return r->getSwingSetupTwistAxis(i); },- [&](std::uint16_t i) { return r->getSwingInputControlIndices(i); }, [&](std::uint16_t i) { return r->getSwingOutputJointIndices(i); },- [&](std::uint16_t i) { return r->getSwingBlendWeights(i); });- std::printf(",\"rotationRepresentations\":[");- for (std::uint16_t i = 0; i < r->getJointCount(); ++i)- std::printf("%s%d", i ? "," : "", static_cast<int>(r->getJointRotationRepresentation(i)));- std::printf("]");-- std::printf(",\"meshes\":[");- for (std::uint16_t m = 0; m < r->getMeshCount(); ++m) {- std::printf("%s{\"positions\":[", m ? "," : "");- printArray(r->getVertexPositionXs(m));- std::putchar(',');- printArray(r->getVertexPositionYs(m));- std::putchar(',');- printArray(r->getVertexPositionZs(m));- std::printf("],\"uvs\":[");- printArray(r->getVertexTextureCoordinateUs(m));- std::putchar(',');- printArray(r->getVertexTextureCoordinateVs(m));- std::printf("],\"normals\":[");- printArray(r->getVertexNormalXs(m));- std::putchar(',');- printArray(r->getVertexNormalYs(m));- std::putchar(',');- printArray(r->getVertexNormalZs(m));- std::printf("],\"layouts\":[");- printArray(r->getVertexLayoutPositionIndices(m));- std::putchar(',');- printArray(r->getVertexLayoutTextureCoordinateIndices(m));- std::putchar(',');- printArray(r->getVertexLayoutNormalIndices(m));- std::printf("],\"faces\":[");- for (std::uint32_t f = 0; f < r->getFaceCount(m); ++f) {- if (f) std::putchar(',');- printArray(r->getFaceVertexLayoutIndices(m, f));- }- std::printf("],\"maxInfluence\":%u,\"skin\":[", r->getMaximumInfluencePerVertex(m));- for (std::uint32_t v = 0; v < r->getSkinWeightsCount(m); ++v) {- std::printf("%s[", v ? "," : "");- printArray(r->getSkinWeightsValues(m, v));- std::putchar(',');- printArray(r->getSkinWeightsJointIndices(m, v));- std::printf("]");- }- std::printf("],\"targets\":[");- for (std::uint16_t t = 0; t < r->getBlendShapeTargetCount(m); ++t) {- std::printf("%s{\"channel\":%u,\"deltas\":[", t ? "," : "", r->getBlendShapeChannelIndex(m, t));- printArray(r->getBlendShapeTargetDeltaXs(m, t));- std::putchar(',');- printArray(r->getBlendShapeTargetDeltaYs(m, t));- std::putchar(',');- printArray(r->getBlendShapeTargetDeltaZs(m, t));- std::printf("],\"vertices\":");- printArray(r->getBlendShapeTargetVertexIndices(m, t));- std::printf("}");- }- std::printf("]}");- }- std::printf("]}\n");-}--// Seeded random controls in 0 … 1.2 (past the top, to exercise clamping).-static float nextRandom(std::uint32_t& state) {- state = state * 1664525u + 1013904223u;- return static_cast<float>(state >> 8) / static_cast<float>(1u << 24) * 1.2f;-}--static void evalDna(const char* path, std::uint32_t seed, int count) {- auto stream = pma::makeScoped<trio::FileStream>(path, trio::FileStream::AccessMode::Read, trio::FileStream::OpenMode::Binary);- auto reader = pma::makeScoped<BinaryStreamReader>(stream.get(), DataLayer::All);- reader->read();- if (!Status::isOk()) {- std::fprintf(stderr, "read failed: %s\n", Status::get().message);- std::exit(1);- }- rl4::Configuration config;- config.calculationType = rl4::CalculationType::Scalar;- config.floatingPointType = rl4::FloatingPointType::Float;- auto rig = pma::makeScoped<rl4::RigLogic>(reader.get(), config);- auto instance = pma::makeScoped<rl4::RigInstance>(rig.get());- std::uint32_t state = seed;- std::printf("[");- for (int n = 0; n < count; ++n) {- const bool gui = (n % 2) == 0;- const std::uint16_t lod = static_cast<std::uint16_t>(n % reader->getLODCount());- instance->setLOD(lod);- std::vector<float> controls;- const std::uint16_t controlCount = gui ? instance->getGUIControlCount() : instance->getRawControlCount();- for (std::uint16_t i = 0; i < controlCount; ++i) controls.push_back(nextRandom(state));- // Joint rotations come in as unit quaternions, set after any GUI- // mapping (which writes every raw control), as a host does.- std::vector<float> quats;- const bool body = instance->getRawControlCount() >= 11;- if (body) {- for (int q = 0; q < 2; ++q) {- float v[4];- float len = 0.0f;- for (float& c : v) {- c = nextRandom(state) - 0.6f;- len += c * c;- }- len = std::sqrt(len);- for (float c : v) quats.push_back(c / len);- }- }- if (gui) {- for (std::uint16_t i = 0; i < controlCount; ++i) instance->setGUIControl(i, controls[i]);- rig->mapGUIToRawControls(instance.get());- } else {- for (std::uint16_t i = 0; i < controlCount; ++i) instance->setRawControl(i, controls[i]);- }- for (std::size_t k = 0; k < quats.size(); ++k) instance->setRawControl(static_cast<std::uint16_t>(3 + k), quats[k]);- rig->calculate(instance.get());- std::printf("%s{\"lod\":%u,\"%s\":", n ? "," : "", lod, gui ? "gui" : "raw");- printArray(controls);- std::printf(",\"quats\":");- printArray(quats);- std::printf(",\"rawControls\":");- printArray(instance->getRawControlValues());- std::printf(",\"psdControls\":");- printArray(instance->getPSDControlValues());- std::printf(",\"rbfControls\":");- printArray(instance->getRBFControlValues());- std::printf(",\"joints\":");- printArray(instance->getJointOutputs());- std::printf(",\"blendShapes\":");- printArray(instance->getBlendShapeOutputs());- std::printf(",\"animatedMaps\":");- printArray(instance->getAnimatedMapOutputs());- std::printf("}");- }- std::printf("]\n");-}--int main(int argc, char** argv) {- if (argc == 3 && std::strcmp(argv[1], "write") == 0) writeDna(argv[2]);- else if (argc == 3 && std::strcmp(argv[1], "dump") == 0) dumpDna(argv[2]);- else if (argc == 5 && std::strcmp(argv[1], "eval") == 0)- evalDna(argv[2], static_cast<std::uint32_t>(std::strtoul(argv[3], nullptr, 10)), std::atoi(argv[4]));- else {- std::fprintf(stderr, "usage: oracle write <out.dna> | oracle dump <in.dna>\n");- return 2;- }- return 0;-}diff --git a/packages/dna/fixtures/oracle.dna b/packages/dna/fixtures/oracle.dnadeleted file mode 100644index 15f30d06..00000000Binary files a/packages/dna/fixtures/oracle.dna and /dev/null differdiff --git a/packages/dna/fixtures/oracle.json b/packages/dna/fixtures/oracle.jsondeleted file mode 100644index 2f2a5480..00000000--- a/packages/dna/fixtures/oracle.json+++ /dev/null@@ -1,386 +0,0 @@-{- "version": [2, 8],- "name": "Oracle",- "archetype": 5,- "gender": 1,- "age": 42,- "metadata": [["made by", "oracle"], ["purpose", "parity"]],- "translationUnit": 0,- "rotationUnit": 0,- "coordinateSystem": [1, 2, 4],- "rotationSequence": 5,- "rotationSign": [1, -1, 1],- "faceWindingOrder": 0,- "lodCount": 2,- "maxLOD": 0,- "complexity": "Oracle",- "dbName": "OracleDB",- "guiControlNames": ["CTRL_jaw", "CTRL_smile"],- "rawControlNames": [- "jawOpen",- "smileL",- "smileR",- "arm.qx",- "arm.qy",- "arm.qz",- "arm.qw",- "forearm.qx",- "forearm.qy",- "forearm.qz",- "forearm.qw"- ],- "jointNames": ["root", "neck", "head", "jaw", "eyeL"],- "blendShapeChannelNames": ["jawOpen", "smile_corrective"],- "animatedMapNames": ["head_wm1_forehead", "head_wm2_cheek"],- "meshNames": ["head_lod0_mesh", "head_lod1_mesh"],- "jointsPerLod": [[0, 1, 2, 3, 4], [0, 1, 2]],- "blendShapesPerLod": [[0, 1], [0]],- "animatedMapsPerLod": [[0, 1], [0, 1]],- "meshesPerLod": [[0], [1]],- "meshBlendShapeChannelMapping": [[0, 0], [0, 1], [1, 0]],- "parents": [0, 0, 1, 2, 2],- "neutralTranslations": [- [0, 0, 0, 0, 3.20000005],- [0, 150, 12.5, -3, 4],- [0, -2, 1, 4.5, 8]- ],- "neutralRotations": [- [0, -10, 12, 0, 1.5],- [0, 0, 5, 90, -2.5],- [0, 0, -3, 25, 3.5]- ],- "guiToRawInput": [0, 1, 1, 1],- "guiToRawOutput": [0, 1, 1, 2],- "guiToRawFrom": [0, 0, 0.400000006, 0],- "guiToRawTo": [1, 0.600000024, 1, 1],- "guiToRawSlope": [1, 1, -1, 0.5],- "guiToRawCut": [0, 0, 1, 0.25],- "psdCount": 1,- "psdRows": [11, 11],- "psdColumns": [1, 2],- "psdValues": [1.5, 1],- "jointRowCount": 45,- "jointColumnCount": 4,- "jointGroups": [- {- "lods": [4, 2],- "inputs": [0, 11],- "outputs": [33, 34, 35, 29],- "values": [-0.5, 0, 12, 0, 0, 0.100000001, 0.75, -0.25],- "joints": [3]- },- {- "lods": [3, 1],- "inputs": [1, 2, 11],- "outputs": [12, 13, 9],- "values": [20, -5, 3, 0, 7.5, -2, 0.5, 0.5, 0],- "joints": [1]- },- {- "lods": [2, 1],- "inputs": [12, 13, 14, 15],- "outputs": [36, 37],- "values": [2, -1, 0.5, 3, 0, 1.5, -2.5, 0.25],- "joints": [4]- }- ],- "blendShapeLods": [2, 1],- "blendShapeInputs": [0, 11],- "blendShapeOutputs": [0, 1],- "animatedMapLods": [3, 2],- "animatedMapInputs": [0, 1, 1],- "animatedMapOutputs": [0, 1, 1],- "animatedMapFrom": [0, 0, 0.5],- "animatedMapTo": [1, 0.699999988, 1],- "animatedMapSlope": [1, 0.800000012, -0.5],- "animatedMapCut": [0, 0.100000001, 0.899999976],- "mlControlCount": 0,- "rbfSolversPerLod": [[0, 1, 2, 3, 4], [0, 2]],- "rbfSolvers": [- {- "name": "arm_rbf",- "rawControlIndices": [3, 4, 5, 6],- "poseIndices": [0, 1, 2, 6],- "rawControlValues": [- 0, 0, 0, 1, 0, 0, 0.382683426, 0.923879504, 0, 0.382683426, 0,- 0.923879504, 0, 0, 0.5, 0.866025388- ],- "radius": 50,- "weightThreshold": 0.00100000005,- "solverType": 1,- "automaticRadius": 1,- "distanceMethod": 1,- "normalizeMethod": 0,- "functionType": 0,- "twistAxis": 0- },- {- "name": "forearm_twist",- "rawControlIndices": [7, 8, 9, 10],- "poseIndices": [3, 4, 5, 7],- "rawControlValues": [- 0, 0, 0, 1, 0.382683426, 0, 0, 0.923879504, 0.707106769, 0, 0,- 0.707106769, 0.923879504, 0, 0, 0.382683426- ],- "radius": 0,- "weightThreshold": 0,- "solverType": 0,- "automaticRadius": 0,- "distanceMethod": 3,- "normalizeMethod": 1,- "functionType": 2,- "twistAxis": 0- },- {- "name": "arm_swing",- "rawControlIndices": [3, 4, 5, 6],- "poseIndices": [8, 9, 10],- "rawControlValues": [- 0, 0, 0, 1, 0.382683426, 0, 0, 0.923879504, 0, 0.382683426, 0,- 0.923879504- ],- "radius": 60,- "weightThreshold": 0,- "solverType": 0,- "automaticRadius": 1,- "distanceMethod": 2,- "normalizeMethod": 0,- "functionType": 3,- "twistAxis": 2- },- {- "name": "smiles",- "rawControlIndices": [1, 2],- "poseIndices": [11, 12, 13, 14],- "rawControlValues": [0, 0, 1, 0, 0, 1, 1, 1],- "radius": 0,- "weightThreshold": 0.00999999978,- "solverType": 1,- "automaticRadius": 0,- "distanceMethod": 0,- "normalizeMethod": 0,- "functionType": 4,- "twistAxis": 0- },- {- "name": "jaw",- "rawControlIndices": [0],- "poseIndices": [15, 16],- "rawControlValues": [0, 1],- "radius": 40,- "weightThreshold": 0,- "solverType": 0,- "automaticRadius": 1,- "distanceMethod": 0,- "normalizeMethod": 1,- "functionType": 1,- "twistAxis": 0- }- ],- "rbfPoses": [- {- "name": "arm_rest",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "arm_up",- "scale": 1,- "inputs": [],- "outputs": [12, 16],- "weights": [1, 0.5]- },- {- "name": "arm_forward",- "scale": 0.800000012,- "inputs": [0],- "outputs": [13],- "weights": [1]- },- {- "name": "forearm_rest",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "forearm_twist45",- "scale": 1,- "inputs": [],- "outputs": [14],- "weights": [1]- },- {- "name": "forearm_twist90",- "scale": 1.20000005,- "inputs": [],- "outputs": [15],- "weights": [1]- },- {- "name": "arm_up30",- "scale": 0.899999976,- "inputs": [],- "outputs": [12],- "weights": [0.699999988]- },- {- "name": "forearm_twist135",- "scale": 1,- "inputs": [],- "outputs": [15],- "weights": [1]- },- {- "name": "swing_rest",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "swing_x",- "scale": 1,- "inputs": [],- "outputs": [16],- "weights": [0.300000012]- },- {- "name": "swing_y",- "scale": 1,- "inputs": [],- "outputs": [14],- "weights": [0.400000006]- },- {- "name": "smiles_none",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "smiles_left",- "scale": 1,- "inputs": [],- "outputs": [16],- "weights": [0.600000024]- },- {- "name": "smiles_right",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "smiles_both",- "scale": 1.10000002,- "inputs": [],- "outputs": [13],- "weights": [0.5]- },- {- "name": "jaw_closed",- "scale": 1,- "inputs": [],- "outputs": [],- "weights": []- },- {- "name": "jaw_open",- "scale": 1,- "inputs": [],- "outputs": [15],- "weights": [0.200000003]- }- ],- "rbfPoseControlNames": [- "arm_up_pc",- "arm_forward_pc",- "forearm_twist45_pc",- "forearm_twist90_pc",- "arm_up_half_pc"- ],- "twists": [- {- "twistAxis": 0,- "inputs": [7, 8, 9, 10],- "outputs": [3, 4],- "weights": [0.5, 0.25]- }- ],- "swings": [- {- "twistAxis": 1,- "inputs": [3, 4, 5, 6],- "outputs": [2],- "weights": [0.300000012]- }- ],- "rotationRepresentations": [0, 0, 0, 0, 0],- "meshes": [- {- "positions": [- [-5, 5, 5, -5, 0],- [150, 150, 165, 165, 170],- [9, 9, 8, 8, 7.5]- ],- "uvs": [- [0.100000001, 0.899999976, 0.899999976, 0.100000001, 0.5, 0.550000012],- [- 0.200000003, 0.200000003, 0.800000012, 0.800000012, 0.949999988,- 0.949999988- ]- ],- "normals": [[0, 0], [0, 0.600000024], [1, 0.800000012]],- "layouts": [[0, 1, 2, 3, 4, 4], [0, 1, 2, 3, 4, 5], [0, 0, 0, 0, 1, 1]],- "faces": [[0, 1, 2, 3], [3, 2, 4]],- "maxInfluence": 6,- "skin": [- [[1], [1]],- [[0.5, 0.5], [1, 2]],- [- [- 0.300000012, 0.200000003, 0.150000006, 0.150000006, 0.100000001,- 0.100000001- ],- [2, 3, 4, 1, 0, 3]- ],- [[1], [1]],- [[0.5, 0.5], [1, 2]]- ],- "targets": [- {- "channel": 0,- "deltas": [[0, 0], [-1.5, -1.5], [0.200000003, 0.200000003]],- "vertices": [0, 1]- },- {- "channel": 1,- "deltas": [[0.300000012], [0.400000006], [-0.100000001]],- "vertices": [2]- }- ]- },- {- "positions": [[-5, 5, 0], [150, 150, 170], [9, 9, 7.5]],- "uvs": [[0, 1, 0.5], [0, 0, 1]],- "normals": [[0], [0], [1]],- "layouts": [[0, 1, 2], [0, 1, 2], [0, 0, 0]],- "faces": [[0, 1, 2]],- "maxInfluence": 1,- "skin": [[[1], [1]], [[1], [1]], [[1], [1]]],- "targets": [- {- "channel": 0,- "deltas": [[0], [-1], [0]],- "vertices": [0]- }- ]- }- ]-}diff --git a/packages/dna/fixtures/v21.dna b/packages/dna/fixtures/v21.dnadeleted file mode 100644index 32398e72..00000000Binary files a/packages/dna/fixtures/v21.dna and /dev/null differdiff --git a/packages/dna/fixtures/v21.json b/packages/dna/fixtures/v21.jsondeleted file mode 100644index c1b2e967..00000000--- a/packages/dna/fixtures/v21.json+++ /dev/null@@ -1,166 +0,0 @@-{- "version": [2, 1],- "name": "Oracle",- "archetype": 5,- "gender": 1,- "age": 42,- "metadata": [["made by", "oracle"], ["purpose", "parity"]],- "translationUnit": 0,- "rotationUnit": 0,- "coordinateSystem": [1, 2, 4],- "rotationSequence": 0,- "rotationSign": [1, 1, 1],- "faceWindingOrder": 0,- "lodCount": 2,- "maxLOD": 0,- "complexity": "Oracle",- "dbName": "OracleDB",- "guiControlNames": ["CTRL_jaw", "CTRL_smile"],- "rawControlNames": [- "jawOpen",- "smileL",- "smileR",- "arm.qx",- "arm.qy",- "arm.qz",- "arm.qw",- "forearm.qx",- "forearm.qy",- "forearm.qz",- "forearm.qw"- ],- "jointNames": ["root", "neck", "head", "jaw", "eyeL"],- "blendShapeChannelNames": ["jawOpen", "smile_corrective"],- "animatedMapNames": ["head_wm1_forehead", "head_wm2_cheek"],- "meshNames": ["head_lod0_mesh", "head_lod1_mesh"],- "jointsPerLod": [[0, 1, 2, 3, 4], [0, 1, 2]],- "blendShapesPerLod": [[0, 1], [0]],- "animatedMapsPerLod": [[0, 1], [0, 1]],- "meshesPerLod": [[0], [1]],- "meshBlendShapeChannelMapping": [[0, 0], [0, 1], [1, 0]],- "parents": [0, 0, 1, 2, 2],- "neutralTranslations": [- [0, 0, 0, 0, 3.20000005],- [0, 150, 12.5, -3, 4],- [0, -2, 1, 4.5, 8]- ],- "neutralRotations": [- [0, -10, 12, 0, 1.5],- [0, 0, 5, 90, -2.5],- [0, 0, -3, 25, 3.5]- ],- "guiToRawInput": [0, 1, 1, 1],- "guiToRawOutput": [0, 1, 1, 2],- "guiToRawFrom": [0, 0, 0.400000006, 0],- "guiToRawTo": [1, 0.600000024, 1, 1],- "guiToRawSlope": [1, 1, -1, 0.5],- "guiToRawCut": [0, 0, 1, 0.25],- "psdCount": 1,- "psdRows": [11, 11],- "psdColumns": [1, 2],- "psdValues": [1.5, 1],- "jointRowCount": 45,- "jointColumnCount": 4,- "jointGroups": [- {- "lods": [4, 2],- "inputs": [0, 11],- "outputs": [33, 34, 35, 29],- "values": [-0.5, 0, 12, 0, 0, 0.100000001, 0.75, -0.25],- "joints": [3]- },- {- "lods": [3, 1],- "inputs": [1, 2, 11],- "outputs": [12, 13, 9],- "values": [20, -5, 3, 0, 7.5, -2, 0.5, 0.5, 0],- "joints": [1]- },- {- "lods": [2, 1],- "inputs": [12, 13, 14, 15],- "outputs": [36, 37],- "values": [2, -1, 0.5, 3, 0, 1.5, -2.5, 0.25],- "joints": [4]- }- ],- "blendShapeLods": [2, 1],- "blendShapeInputs": [0, 11],- "blendShapeOutputs": [0, 1],- "animatedMapLods": [3, 2],- "animatedMapInputs": [0, 1, 1],- "animatedMapOutputs": [0, 1, 1],- "animatedMapFrom": [0, 0, 0.5],- "animatedMapTo": [1, 0.699999988, 1],- "animatedMapSlope": [1, 0.800000012, -0.5],- "animatedMapCut": [0, 0.100000001, 0.899999976],- "mlControlCount": 0,- "rbfSolversPerLod": [[], []],- "rbfSolvers": [],- "rbfPoses": [],- "rbfPoseControlNames": [],- "twists": [],- "swings": [],- "rotationRepresentations": [0, 0, 0, 0, 0],- "meshes": [- {- "positions": [- [-5, 5, 5, -5, 0],- [150, 150, 165, 165, 170],- [9, 9, 8, 8, 7.5]- ],- "uvs": [- [0.100000001, 0.899999976, 0.899999976, 0.100000001, 0.5, 0.550000012],- [- 0.200000003, 0.200000003, 0.800000012, 0.800000012, 0.949999988,- 0.949999988- ]- ],- "normals": [[0, 0], [0, 0.600000024], [1, 0.800000012]],- "layouts": [[0, 1, 2, 3, 4, 4], [0, 1, 2, 3, 4, 5], [0, 0, 0, 0, 1, 1]],- "faces": [[0, 1, 2, 3], [3, 2, 4]],- "maxInfluence": 6,- "skin": [- [[1], [1]],- [[0.5, 0.5], [1, 2]],- [- [- 0.300000012, 0.200000003, 0.150000006, 0.150000006, 0.100000001,- 0.100000001- ],- [2, 3, 4, 1, 0, 3]- ],- [[1], [1]],- [[0.5, 0.5], [1, 2]]- ],- "targets": [- {- "channel": 0,- "deltas": [[0, 0], [-1.5, -1.5], [0.200000003, 0.200000003]],- "vertices": [0, 1]- },- {- "channel": 1,- "deltas": [[0.300000012], [0.400000006], [-0.100000001]],- "vertices": [2]- }- ]- },- {- "positions": [[-5, 5, 0], [150, 150, 170], [9, 9, 7.5]],- "uvs": [[0, 1, 0.5], [0, 0, 1]],- "normals": [[0], [0], [1]],- "layouts": [[0, 1, 2], [0, 1, 2], [0, 0, 0]],- "faces": [[0, 1, 2]],- "maxInfluence": 1,- "skin": [[[1], [1]], [[1], [1]], [[1], [1]]],- "targets": [- {- "channel": 0,- "deltas": [[0], [-1], [0]],- "vertices": [0]- }- ]- }- ]-}diff --git a/packages/dna/package.json b/packages/dna/package.jsondeleted file mode 100644index 4d9c0a31..00000000--- a/packages/dna/package.json+++ /dev/null@@ -1,41 +0,0 @@-{- "name": "@framefields/dna",- "version": "2.14.0",- "private": true,- "description": "Read DNA character files (MetaHuman-compatible rigs: joints, meshes, skin weights, blend shapes, rig behavior) and turn them into GLB characters.",- "type": "module",- "sideEffects": false,- "license": "Apache-2.0",- "module": "./dist/index.mjs",- "types": "./dist/index.d.mts",- "exports": {- ".": {- "types": "./dist/index.d.mts",- "development": "./src/index.ts",- "import": "./dist/index.mjs",- "default": "./dist/index.mjs"- }- },- "files": [- "dist/**"- ],- "scripts": {- "build": "tsdown",- "dev": "tsdown --watch",- "typecheck": "tsc --noEmit -p .",- "test": "vitest run",- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"- },- "dependencies": {- "@framefields/forge": "workspace:*"- },- "devDependencies": {- "@framefields/tsconfig": "workspace:*",- "@framefields/webgpu-renderers": "workspace:*",- "@types/node": "^24.1.0",- "gltf-validator": "2.0.0-dev.3.10",- "tsdown": "^0.19.0",- "typescript": "^5.8.3",- "vitest": "^4.1.5"- }-}diff --git a/packages/dna/src/bytes.ts b/packages/dna/src/bytes.tsdeleted file mode 100644index d6d351f9..00000000--- a/packages/dna/src/bytes.ts+++ /dev/null@@ -1,102 +0,0 @@-/**- * Reads the binary archives DNA files are written in: big-endian numbers,- * and arrays and strings prefixed with a 32-bit element count.- *- * Based on OpenRigLogic's `terse` binary input archive (MIT, Epic Games).- */-export class ByteReader {- private readonly view: DataView;- private at = 0;-- constructor(private readonly bytes: Uint8Array) {- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);- }-- get offset(): number {- return this.at;- }-- get length(): number {- return this.bytes.byteLength;- }-- seek(offset: number): void {- if (offset < 0 || offset > this.bytes.byteLength)- throw new Error(- `dna: seek to ${offset} is outside the file (${this.bytes.byteLength} bytes)`,- );- this.at = offset;- }-- private need(n: number): number {- const start = this.at;- if (start + n > this.bytes.byteLength)- throw new Error(- `dna: the file ends at ${this.bytes.byteLength} bytes; ${n} more needed at ${start}`,- );- this.at += n;- return start;- }-- u8(): number {- return this.view.getUint8(this.need(1));- }-- u16(): number {- return this.view.getUint16(this.need(2));- }-- u32(): number {- return this.view.getUint32(this.need(4));- }-- i32(): number {- return this.view.getInt32(this.need(4));- }-- f32(): number {- return this.view.getFloat32(this.need(4));- }-- chars(n: number): string {- const start = this.need(n);- return new TextDecoder().decode(this.bytes.subarray(start, start + n));- }-- /** A counted string. */- string(): string {- return this.chars(this.u32());- }-- u16s(): Uint16Array {- const n = this.u32();- const start = this.need(n * 2);- const out = new Uint16Array(n);- for (let i = 0; i < n; i++) out[i] = this.view.getUint16(start + i * 2);- return out;- }-- u32s(): Uint32Array {- const n = this.u32();- const start = this.need(n * 4);- const out = new Uint32Array(n);- for (let i = 0; i < n; i++) out[i] = this.view.getUint32(start + i * 4);- return out;- }-- f32s(): Float32Array {- const n = this.u32();- const start = this.need(n * 4);- const out = new Float32Array(n);- for (let i = 0; i < n; i++) out[i] = this.view.getFloat32(start + i * 4);- return out;- }-- /** A counted list of anything. */- list<T>(item: (r: ByteReader) => T): T[] {- const n = this.u32();- const out: T[] = [];- for (let i = 0; i < n; i++) out.push(item(this));- return out;- }-}diff --git a/packages/dna/src/dna-oracle.test.ts b/packages/dna/src/dna-oracle.test.tsdeleted file mode 100644index 074c6700..00000000--- a/packages/dna/src/dna-oracle.test.ts+++ /dev/null@@ -1,267 +0,0 @@-/**- * Parity with Epic's own DNA library. `fixtures/oracle.dna` was written by- * OpenRigLogic 5.8's DNA writer (made-up data, see `fixtures/oracle.cpp`);- * `fixtures/v21.dna` is the same character in the 2.1 layout. Each `.json`- * is what Epic's reader reads from its file. `readDna` must read the same:- * every field, every LOD view, every mesh.- */-import { readFileSync } from "node:fs";-import { describe, expect, it } from "vitest";-import { dnaToGlb, readDna } from "./index.js";--const fixture = (name: string) => ({- name,- bytes: new Uint8Array(- readFileSync(new URL(`../fixtures/${name}.dna`, import.meta.url)),- ),- oracle: JSON.parse(- readFileSync(new URL(`../fixtures/${name}.json`, import.meta.url), "utf8"),- ),-});--const AXES = ["left", "right", "up", "down", "front", "back"];-const SEQUENCES = ["xyz", "xzy", "yxz", "yzx", "zxy", "zyx"];-const list = (a: ArrayLike<number>) => Array.from(a);-/** Float32 values as the oracle printed them (9 significant digits). */-const f = (a: ArrayLike<number>) =>- Array.from(a, (x) => Number(x.toPrecision(9)));--describe.each([- fixture("oracle"),- fixture("v21"),-])("readDna against OpenRigLogic ($name)", ({ bytes, oracle }) => {- const dna = readDna(bytes);- const d = dna.descriptor;- const def = dna.definition;- const b = dna.behavior!;-- it("reads the descriptor", () => {- expect([dna.version.generation, dna.version.version]).toEqual(- oracle.version,- );- expect({- name: d.name,- archetype: d.archetype,- gender: d.gender,- age: d.age,- metadata: d.metadata,- translationUnit: d.translationUnit === "m" ? 1 : 0,- rotationUnit: d.rotationUnit === "radians" ? 1 : 0,- coordinateSystem: d.coordinateSystem.map((a) => AXES.indexOf(a)),- rotationSequence: SEQUENCES.indexOf(d.rotationSequence),- rotationSign: d.rotationSign,- faceWindingOrder: d.faceWindingOrder === "cw" ? 1 : 0,- lodCount: d.lodCount,- maxLOD: d.maxLOD,- complexity: d.complexity,- dbName: d.dbName,- }).toEqual({- name: oracle.name,- archetype: oracle.archetype,- gender: oracle.gender,- age: oracle.age,- metadata: oracle.metadata,- translationUnit: oracle.translationUnit,- rotationUnit: oracle.rotationUnit,- coordinateSystem: oracle.coordinateSystem,- rotationSequence: oracle.rotationSequence,- rotationSign: oracle.rotationSign,- faceWindingOrder: oracle.faceWindingOrder,- lodCount: oracle.lodCount,- maxLOD: oracle.maxLOD,- complexity: oracle.complexity,- dbName: oracle.dbName,- });- });-- it("reads the definition, with each LOD's elements", () => {- for (const key of [- "guiControlNames",- "rawControlNames",- "jointNames",- "blendShapeChannelNames",- "animatedMapNames",- "meshNames",- ] as const)- expect(def[key]).toEqual(oracle[key]);- const perLod = (m: { lods: Uint16Array; indices: Uint16Array[] }) =>- Array.from({ length: d.lodCount }, (_, lod) =>- list(m.indices[m.lods[lod] as number] ?? []),- );- expect(perLod(def.lodJointMapping)).toEqual(oracle.jointsPerLod);- expect(perLod(def.lodBlendShapeMapping)).toEqual(oracle.blendShapesPerLod);- expect(perLod(def.lodAnimatedMapMapping)).toEqual(- oracle.animatedMapsPerLod,- );- expect(perLod(def.lodMeshMapping)).toEqual(oracle.meshesPerLod);- const m = def.meshBlendShapeChannelMapping;- expect(list(m.from).map((x, i) => [x, m.to[i]])).toEqual(- oracle.meshBlendShapeChannelMapping,- );- // Epic's reader reports a root as its own parent.- expect(list(def.jointHierarchy)).toEqual(oracle.parents);- const t = def.neutralJointTranslations;- const r = def.neutralJointRotations;- expect([f(t.xs), f(t.ys), f(t.zs)]).toEqual(oracle.neutralTranslations);- expect([f(r.xs), f(r.ys), f(r.zs)]).toEqual(oracle.neutralRotations);- });-- it("reads the rig behavior", () => {- const c = b.controls;- expect({- guiToRawInput: list(c.conditionals.inputIndices),- guiToRawOutput: list(c.conditionals.outputIndices),- guiToRawFrom: f(c.conditionals.fromValues),- guiToRawTo: f(c.conditionals.toValues),- guiToRawSlope: f(c.conditionals.slopeValues),- guiToRawCut: f(c.conditionals.cutValues),- psdCount: c.psdCount,- psdRows: list(c.psds.rows),- psdColumns: list(c.psds.columns),- psdValues: f(c.psds.values),- jointRowCount: b.joints.rowCount,- jointColumnCount: b.joints.colCount,- jointGroups: b.joints.jointGroups.map((g) => ({- lods: list(g.lods),- inputs: list(g.inputIndices),- outputs: list(g.outputIndices),- values: f(g.values),- joints: list(g.jointIndices),- })),- blendShapeLods: list(b.blendShapeChannels.lods),- blendShapeInputs: list(b.blendShapeChannels.inputIndices),- blendShapeOutputs: list(b.blendShapeChannels.outputIndices),- animatedMapLods: list(b.animatedMaps.lods),- animatedMapInputs: list(b.animatedMaps.conditionals.inputIndices),- animatedMapOutputs: list(b.animatedMaps.conditionals.outputIndices),- animatedMapFrom: f(b.animatedMaps.conditionals.fromValues),- animatedMapTo: f(b.animatedMaps.conditionals.toValues),- animatedMapSlope: f(b.animatedMaps.conditionals.slopeValues),- animatedMapCut: f(b.animatedMaps.conditionals.cutValues),- }).toEqual(- Object.fromEntries(- [- "guiToRawInput",- "guiToRawOutput",- "guiToRawFrom",- "guiToRawTo",- "guiToRawSlope",- "guiToRawCut",- "psdCount",- "psdRows",- "psdColumns",- "psdValues",- "jointRowCount",- "jointColumnCount",- "jointGroups",- "blendShapeLods",- "blendShapeInputs",- "blendShapeOutputs",- "animatedMapLods",- "animatedMapInputs",- "animatedMapOutputs",- "animatedMapFrom",- "animatedMapTo",- "animatedMapSlope",- "animatedMapCut",- ].map((k) => [k, oracle[k]]),- ),- );- });-- it("reads every mesh", () => {- const meshes = dna.geometry!.meshes.map((m) => ({- positions: [f(m.positions.xs), f(m.positions.ys), f(m.positions.zs)],- uvs: [f(m.uvs.us), f(m.uvs.vs)],- normals: [f(m.normals.xs), f(m.normals.ys), f(m.normals.zs)],- layouts: [- list(m.layouts.positions),- list(m.layouts.uvs),- list(m.layouts.normals),- ],- faces: m.faces.map(list),- maxInfluence: m.maximumInfluencePerVertex,- skin: m.skinWeights.map((s) => [f(s.weights), list(s.jointIndices)]),- targets: m.blendShapeTargets.map((t) => ({- channel: t.channel,- deltas: [f(t.deltas.xs), f(t.deltas.ys), f(t.deltas.zs)],- vertices: list(t.vertexIndices),- })),- }));- expect(meshes).toEqual(oracle.meshes);- });-- it("reads the RBF, twist/swing and joint metadata layers", () => {- const rbf = dna.rbf;- const SOLVER = ["additive", "interpolative"];- const DISTANCE = ["euclidean", "quaternion", "swingAngle", "twistAngle"];- const NORMALIZE = ["onlyAboveOne", "always"];- const FUNCTION = ["gaussian", "exponential", "linear", "cubic", "quintic"];- const AXIS = ["x", "y", "z"];- expect(dna.mlControlNames?.length ?? 0).toBe(oracle.mlControlCount);- const perLod = rbf- ? Array.from({ length: d.lodCount }, (_, lod) =>- list(- rbf.lodSolverMapping.indices[- rbf.lodSolverMapping.lods[lod] as number- ] ?? [],- ),- )- : oracle.rbfSolversPerLod.map(() => []);- expect(perLod).toEqual(oracle.rbfSolversPerLod);- expect(- (rbf?.solvers ?? []).map((x) => ({- name: x.name,- rawControlIndices: list(x.rawControlIndices),- poseIndices: list(x.poseIndices),- rawControlValues: f(x.rawControlValues),- radius: Number(x.radius.toPrecision(9)),- weightThreshold: Number(x.weightThreshold.toPrecision(9)),- solverType: SOLVER.indexOf(x.solverType),- automaticRadius: x.automaticRadius ? 0 : 1,- distanceMethod: DISTANCE.indexOf(x.distanceMethod),- normalizeMethod: NORMALIZE.indexOf(x.normalizeMethod),- functionType: FUNCTION.indexOf(x.functionType),- twistAxis: AXIS.indexOf(x.twistAxis),- })),- ).toEqual(oracle.rbfSolvers);- expect(- (rbf?.poses ?? []).map((p, i) => ({- name: p.name,- scale: Number(p.scale.toPrecision(9)),- inputs: list(rbf?.poseControls[i]?.inputControlIndices ?? []),- outputs: list(rbf?.poseControls[i]?.outputControlIndices ?? []),- weights: f(rbf?.poseControls[i]?.outputControlWeights ?? []),- })),- ).toEqual(oracle.rbfPoses);- expect(rbf?.poseControlNames ?? []).toEqual(oracle.rbfPoseControlNames);- const setups = (- list_: {- twistAxis: string;- inputControlIndices: Uint16Array;- outputJointIndices: Uint16Array;- blendWeights: Float32Array;- }[],- ) =>- list_.map((x) => ({- twistAxis: AXIS.indexOf(x.twistAxis),- inputs: list(x.inputControlIndices),- outputs: list(x.outputJointIndices),- weights: f(x.blendWeights),- }));- expect(setups(dna.twistSwing?.twists ?? [])).toEqual(oracle.twists);- expect(setups(dna.twistSwing?.swings ?? [])).toEqual(oracle.swings);- const reps =- dna.jointRepresentations ??- def.jointNames.map(() => ({ rotation: "euler" }));- expect(reps.map((r) => (r.rotation === "quaternion" ? 1 : 0))).toEqual(- oracle.rotationRepresentations,- );- });-- it("converts Epic's file to a GLB", () => {- // zyx order with a negative y sign, six influences on one vertex, two LODs.- for (const lod of [0, 1])- expect(dnaToGlb(dna, { lod }).byteLength).toBeGreaterThan(0);- });-});diff --git a/packages/dna/src/dna.test.ts b/packages/dna/src/dna.test.tsdeleted file mode 100644index 389d5eda..00000000--- a/packages/dna/src/dna.test.ts+++ /dev/null@@ -1,346 +0,0 @@-/**- * DNA files read back what was written (versions 2.1 and 2.8, unknown- * layers skipped), Euler angles follow OpenRigLogic's convention, and a- * character converts to a GLB the Khronos validator accepts and the engine- * loader reads: joints at their neutral pose with rest rotations, meshes per- * LOD, skin weights capped at four, blend shapes as named morph targets,- * mirrored axes handled.- */-import { denseMorphDeltas, parseGLB } from "@framefields/webgpu-renderers";-import { validateBytes } from "gltf-validator";-import { describe, expect, it } from "vitest";-import { dnaToGlb, eulerQuat, readDna, spaceOf } from "./index.js";-import type { DnaDescriptor } from "./read.js";-import { type TestDna, writeDna21, writeDna28 } from "./write-dna.test-util.js";--const f32 = (...v: number[]) => Float32Array.from(v);-const u16 = (...v: number[]) => Uint16Array.from(v);-const u32 = (...v: number[]) => Uint32Array.from(v);-const table = () => ({- inputIndices: u16(),- outputIndices: u16(),- fromValues: f32(),- toValues: f32(),- slopeValues: f32(),- cutValues: f32(),-});--function descriptor(over: Partial<DnaDescriptor> = {}): DnaDescriptor {- return {- name: "Tester",- archetype: 5,- gender: 2,- age: 30,- metadata: [["source", "unit test"]],- translationUnit: "cm",- rotationUnit: "degrees",- coordinateSystem: ["right", "up", "front"],- lodCount: 2,- maxLOD: 0,- complexity: "test",- dbName: "none",- rotationSequence: "xyz",- rotationSign: [1, 1, 1],- faceWindingOrder: "ccw",- ...over,- };-}--/**- * Three joints: a root, an elbow 10 up turned 90° about z (its x now points- * up), and a hand 10 along the elbow's x, so at 20 up. One quad facing the- * viewer (+z), with a UV seam copy of its first corner, skinned and with a- * "jawOpen" shape that pushes that corner forward; a second, empty mesh- * belongs to LOD 1 only.- */-function arm(over: Partial<DnaDescriptor> = {}): TestDna {- return {- descriptor: descriptor(over),- definition: {- lodJointMapping: { lods: u16(0, 0), indices: [u16(0, 1, 2, 3, 4)] },- lodBlendShapeMapping: { lods: u16(0, 0), indices: [u16(0)] },- lodAnimatedMapMapping: { lods: u16(0, 0), indices: [u16()] },- lodMeshMapping: { lods: u16(0, 1), indices: [u16(0), u16(1)] },- guiControlNames: ["CTRL_jaw"],- rawControlNames: ["jawOpen"],- jointNames: ["root", "elbow", "hand", "thumb", "index"],- blendShapeChannelNames: ["jawOpen"],- animatedMapNames: [],- meshNames: ["quad_lod0", "quad_lod1"],- meshBlendShapeChannelMapping: { from: u16(0), to: u16(0) },- jointHierarchy: u16(0, 0, 1, 2, 2),- neutralJointTranslations: {- xs: f32(0, 0, 10, 2, 3),- ys: f32(0, 10, 0, 0, 0),- zs: f32(0, 0, 0, 1, -1),- },- neutralJointRotations: {- xs: f32(0, 0, 0, 0, 0),- ys: f32(0, 0, 0, 0, 0),- zs: f32(0, 90, 0, 0, 0),- },- },- behavior: {- controls: {- psdCount: 0,- conditionals: table(),- psds: { rows: u16(), columns: u16(), values: f32() },- },- joints: { rowCount: 0, colCount: 0, jointGroups: [] },- blendShapeChannels: {- lods: u16(1, 1),- inputIndices: u16(0),- outputIndices: u16(0),- },- animatedMaps: { lods: u16(0, 0), conditionals: table() },- },- meshes: [- {- positions: {- xs: f32(-5, 5, 5, -5),- ys: f32(0, 0, 20, 20),- zs: f32(0, 0, 0, 0),- },- uvs: { us: f32(0, 1, 1, 0, 0.5), vs: f32(0, 0, 1, 1, 0) },- normals: { xs: f32(0), ys: f32(0), zs: f32(1) },- layouts: {- positions: u32(0, 1, 2, 3, 0),- uvs: u32(0, 1, 2, 3, 4),- normals: u32(0, 0, 0, 0, 0),- },- faces: [u32(0, 1, 2, 3), u32(4, 1, 2)],- maximumInfluencePerVertex: 5,- skinWeights: [- { weights: f32(1), jointIndices: u16(0) },- { weights: f32(0.5, 0.5), jointIndices: u16(0, 1) },- {- weights: f32(0.4, 0.3, 0.1, 0.1, 0.05, 0.05),- jointIndices: u16(2, 1, 0, 3, 4, 0),- },- { weights: f32(1), jointIndices: u16(2) },- ],- blendShapeTargets: [- {- deltas: { xs: f32(0), ys: f32(0), zs: f32(2) },- vertexIndices: u32(0),- channel: 0,- },- ],- },- {- positions: { xs: f32(), ys: f32(), zs: f32() },- uvs: { us: f32(), vs: f32() },- normals: { xs: f32(), ys: f32(), zs: f32() },- layouts: { positions: u32(), uvs: u32(), normals: u32() },- faces: [],- maximumInfluencePerVertex: 0,- skinWeights: [],- blendShapeTargets: [],- },- ],- };-}--async function validate(glb: Uint8Array) {- const report = await validateBytes(glb, { maxIssues: 50 });- return report.issues.messages- .filter((m: { severity: number }) => m.severity <= 1)- .map(- (m: { code: string; message: string; pointer?: string }) =>- `${m.code} ${m.pointer ?? ""}: ${m.message}`,- );-}--/** A column-major 4×4 matrix times a point. */-const transform = (- m: ArrayLike<number>,- o: number,- p: [number, number, number],-) =>- [0, 1, 2].map(- (r) =>- (m[o + r] as number) * p[0] +- (m[o + 4 + r] as number) * p[1] +- (m[o + 8 + r] as number) * p[2] +- (m[o + 12 + r] as number),- );--describe("readDna", () => {- for (const [label, write] of [- ["2.8", writeDna28],- ["2.1", writeDna21],- ] as const)- it(`reads every layer it knows from a ${label} file`, () => {- const src = arm({- rotationSequence: label === "2.8" ? "zyx" : "xyz",- faceWindingOrder: label === "2.8" ? "cw" : "ccw",- });- const dna = readDna(write(src));- expect(dna.version).toEqual({- generation: 2,- version: label === "2.8" ? 8 : 1,- });- expect(dna.descriptor).toEqual(src.descriptor);- expect(dna.definition).toEqual(src.definition);- expect(dna.behavior).toEqual(src.behavior);- expect(dna.geometry?.meshes).toEqual(src.meshes);- if (label === "2.8")- expect(dna.layers.map((l) => l.id)).toEqual([- "desc",- "defn",- "bhvr",- "geom",- "twsw",- "dsce",- ]);- });-- it("skips layers it is not asked for", () => {- const dna = readDna(writeDna28(arm()), {- geometry: false,- behavior: false,- });- expect(dna.geometry).toBeUndefined();- expect(dna.behavior).toBeUndefined();- expect(dna.definition.jointNames).toEqual([- "root",- "elbow",- "hand",- "thumb",- "index",- ]);- });-- it("refuses what is not a DNA file it can read", () => {- expect(() => readDna(new TextEncoder().encode("GLTF1234"))).toThrow(- /not a DNA file/,- );- const future = writeDna28(arm());- future[6] = 9;- expect(() => readDna(future)).toThrow(/2\.9 is not supported/);- expect(() => readDna(writeDna28(arm()).subarray(0, 60))).toThrow(/ends at/);- });-});--describe("eulerQuat", () => {- it("matches OpenRigLogic's xyz conversion (x turns first)", () => {- const s = spaceOf(descriptor({ rotationUnit: "radians" }), "cm");- const [x, y, z] = [0.3, -0.7, 1.1];- // tdm's euler_to_quat<rot_seq::xyz>.- const [cx, cy, cz] = [Math.cos(x / 2), Math.cos(y / 2), Math.cos(z / 2)];- const [sx, sy, sz] = [Math.sin(x / 2), Math.sin(y / 2), Math.sin(z / 2)];- const expected = [- sx * cy * cz - cx * sy * sz,- cx * sy * cz + sx * cy * sz,- cx * cy * sz - sx * sy * cz,- cx * cy * cz + sx * sy * sz,- ];- for (const [i, c] of eulerQuat(s, x, y, z).entries())- expect(c).toBeCloseTo(expected[i] as number, 12);- });-});--describe("dnaToGlb", () => {- it("writes a valid skinned GLB with the neutral pose, one LOD and named blend shapes", async () => {- const glb = dnaToGlb(readDna(writeDna28(arm())));- expect(await validate(glb)).toEqual([]);- const model = parseGLB(glb);- // LOD 0: only the quad, a vertex per layout, two faces fanned into three triangles.- expect(model.meshes).toHaveLength(1);- const m = model.meshes[0]!;- expect(m.positions.length / 3).toBe(5);- expect(m.indices.length).toBe(9);- expect(m.morphTargetNames).toEqual(["jawOpen"]);- // The shape moves both copies of the first corner.- const jaw = denseMorphDeltas(m.morphTargets![0]!, 5);- expect([jaw[2], jaw[14], jaw[5]]).toEqual([2, 2, 0]);- // UVs flip to glTF's v-down.- expect(Array.from(m.uvs.slice(4, 6))).toEqual([1, 0]);- // Six entries over five joints: the root's two add up (0.15), and with- // five influences the vertex takes glTF's second set too.- const set0 = Array.from(m.jointIndices!.slice(8, 12));- const set1 = Array.from(m.jointIndices1!.slice(8, 12));- expect(set0).toEqual([2, 1, 0, 3]);- expect(set1).toEqual([4, 0, 0, 0]);- const w = [- ...m.jointWeights!.slice(8, 12),- ...m.jointWeights1!.slice(8, 12),- ];- for (const [k, x] of [0.4, 0.3, 0.15, 0.1, 0.05, 0, 0, 0].entries())- expect(w[k]).toBeCloseTo(x, 6);-- // Joints at the neutral pose: each inverse bind matrix takes its joint's- // rest position to the origin; the elbow rests turned 90° about z.- const skin = model.skins![0]!;- const names = skin.joints.map((j) => model.nodes![j]!.name);- expect(names).toEqual(["root", "elbow", "hand", "thumb", "index"]);- // The fingers sit in the hand's frame, which the elbow turned: its x is up, its y is -x.- const rest: Record<string, [number, number, number]> = {- root: [0, 0, 0],- elbow: [0, 10, 0],- hand: [0, 20, 0],- thumb: [0, 22, 1],- index: [0, 23, -1],- };- for (const [i, n] of names.entries())- for (const c of transform(- skin.inverseBindMatrices,- i * 16,- rest[n] as [number, number, number],- ))- expect(c).toBeCloseTo(0, 5);- const elbow = model.nodes![skin.joints[1]!]!;- expect(elbow.rotation?.[2]).toBeCloseTo(Math.SQRT1_2, 6);- expect(model.nodes![skin.joints[2]!]!.translation?.[0]).toBeCloseTo(10, 5);- });-- it("keeps four influences when asked, renormalized", async () => {- const glb = dnaToGlb(readDna(writeDna28(arm())), { influences: 4 });- expect(await validate(glb)).toEqual([]);- const m = parseGLB(glb).meshes[0]!;- expect(m.jointIndices1).toBeUndefined();- const w = Array.from(m.jointWeights!.slice(8, 12));- for (const [k, x] of [0.4, 0.3, 0.15, 0.1].entries())- expect(w[k]).toBeCloseTo(x / 0.95, 6);- });-- it("converts mirrored axes and meters, keeping faces turned outward", async () => {- // x points to the viewer's left: a mirror image of glTF's axes.- const dna = readDna(- writeDna28(- arm({- coordinateSystem: ["left", "up", "front"],- translationUnit: "m",- }),- ),- );- const glb = dnaToGlb(dna);- expect(await validate(glb)).toEqual([]);- const m = parseGLB(glb).meshes[0]!;- // Meters become centimeters, and x flips.- expect(m.positions[0]).toBeCloseTo(500, 3);- // Every triangle's winding agrees with its vertex normals.- for (let t = 0; t < m.indices.length; t += 3) {- const [a, b, c] = [m.indices[t]!, m.indices[t + 1]!, m.indices[t + 2]!];- const p = (i: number) => [- m.positions[i * 3]!,- m.positions[i * 3 + 1]!,- m.positions[i * 3 + 2]!,- ];- const [pa, pb, pc] = [p(a), p(b), p(c)];- const u = pb.map((v, k) => v - pa[k]!);- const v = pc.map((x, k) => x - pa[k]!);- const nz = u[0]! * v[1]! - u[1]! * v[0]!;- expect(Math.sign(nz)).toBe(Math.sign(m.normals![a * 3 + 2]!));- }- });-- it("writes the meshes of the asked LOD", () => {- const dna = readDna(writeDna28(arm()));- // LOD 1's only mesh is empty: the character is its skeleton alone.- const model = parseGLB(dnaToGlb(dna, { lod: 1 }));- expect(model.meshes).toHaveLength(0);- expect(model.nodes?.map((n) => n.name)).toContain("hand");- expect(() => dnaToGlb(dna, { lod: 2 })).toThrow(/LOD 2 is not in the file/);- });-});diff --git a/packages/dna/src/gltf-validator.d.ts b/packages/dna/src/gltf-validator.d.tsdeleted file mode 100644index 5116ab64..00000000--- a/packages/dna/src/gltf-validator.d.ts+++ /dev/null@@ -1,21 +0,0 @@-/** The subset of the Khronos glTF validator's API the tests use. */-declare module "gltf-validator" {- export interface ValidationMessage {- code: string;- message: string;- /** 0 error, 1 warning, 2 info, 3 hint. */- severity: number;- pointer?: string;- }- export interface ValidationReport {- issues: {- numErrors: number;- numWarnings: number;- messages: ValidationMessage[];- };- }- export function validateBytes(- data: Uint8Array,- options?: { maxIssues?: number; uri?: string },- ): Promise<ValidationReport>;-}diff --git a/packages/dna/src/index.ts b/packages/dna/src/index.tsdeleted file mode 100644index 9c644024..00000000--- a/packages/dna/src/index.ts+++ /dev/null@@ -1,44 +0,0 @@-/**- * `framefields/dna`: characters from DNA files (the format MetaHuman- * characters export to), read in TypeScript and written as GLB files for- * `Layer.glb`. The reader is based on OpenRigLogic's DNA library (MIT,- * Epic Games).- */-export { ByteReader } from "./bytes.js";-export {- dnaMaterials,- type FoundTextures,- type MeshRole,- meshRole,- type RoleTextures,- roleMaterial,-} from "./materials.js";-export {- type AxisDirection,- type ConditionalTable,- type DnaBehavior,- type DnaDefinition,- type DnaDescriptor,- type DnaFile,- type DnaMesh,- type JointGroup,- type LodMapping,- type ReadDnaOptions,- type RotationSequence,- readDna,- type Vec3Array,-} from "./read.js";-export {- JOINT_ATTRIBUTES,- RigEvaluator,- type RigEvaluatorOptions,-} from "./rig.js";-export { eulerQuat, type Space, spaceOf } from "./space.js";-export {- type AddedDna,- addDna,- type DnaToGltfOptions,- dnaSkeleton,- dnaToGlb,- lodMeshes,-} from "./to-glb.js";diff --git a/packages/dna/src/materials.test.ts b/packages/dna/src/materials.test.tsdeleted file mode 100644index eb7b5277..00000000--- a/packages/dna/src/materials.test.ts+++ /dev/null@@ -1,94 +0,0 @@-/**- * Mesh roles come from DNA mesh names, each role has a material the engine- * renders, and an export folder's textures land on the right roles.- */-import { mkdtemp, rm, writeFile } from "node:fs/promises";-import { tmpdir } from "node:os";-import path from "node:path";-import { encodePng, GltfDocument } from "@framefields/forge";-import { describe, expect, it } from "vitest";-import { dnaMaterials, meshRole, roleMaterial } from "./index.js";--describe("meshRole", () => {- it("names the role of each head mesh", () => {- const roles = Object.fromEntries(- [- "head_lod0_mesh",- "teeth_lod0_mesh",- "saliva_lod0_mesh",- "eyeLeft_lod0_mesh",- "eyeRight_lod0_mesh",- "eyeshell_lod0_mesh",- "eyelashes_lod0_mesh",- "eyeEdge_lod0_mesh",- "cartilage_lod0_mesh",- "body_lod0_mesh",- ].map((n) => [n, meshRole(n)]),- );- expect(roles).toEqual({- head_lod0_mesh: "skin",- teeth_lod0_mesh: "teeth",- saliva_lod0_mesh: "saliva",- eyeLeft_lod0_mesh: "eye",- eyeRight_lod0_mesh: "eye",- eyeshell_lod0_mesh: "eyeshell",- eyelashes_lod0_mesh: "eyelashes",- eyeEdge_lod0_mesh: "eyeEdge",- cartilage_lod0_mesh: "cartilage",- body_lod0_mesh: "skin",- });- });-- it("gives clear and thin layers materials that let what is under them show", () => {- expect(roleMaterial("eyeshell").transmission).toBe(1);- for (const role of ["saliva", "eyeEdge", "cartilage"] as const)- expect(roleMaterial(role).alphaMode).toBe("blend");- expect(roleMaterial("eyelashes").doubleSided).toBe(true);- });-});--describe("dnaMaterials", () => {- it("puts an export folder's textures on their roles and reports the rest", async () => {- const dir = await mkdtemp(path.join(tmpdir(), "framefields-dna-tex-"));- const png = encodePng(new Uint8Array(4 * 4 * 4).fill(128), 4, 4);- const files = [- "head_color_map.png",- "head_normal_map.png",- "head_roughness_map.png",- "head_cavity_map.png",- "head_wm1_normal_map.png",- "teeth_color_map.png",- "eyes_color_map.png",- "eyelashes_color.png",- "notes.txt",- ];- for (const f of files) await writeFile(path.join(dir, f), png);- try {- const doc = new GltfDocument();- const t = await dnaMaterials(doc, dir);- expect(t.found).toEqual({- skin: {- color: "head_color_map.png",- normal: "head_normal_map.png",- roughness: "head_roughness_map.png",- occlusion: "head_cavity_map.png",- },- teeth: { color: "teeth_color_map.png" },- eye: { color: "eyes_color_map.png" },- eyelashes: { color: "eyelashes_color.png" },- });- expect(t.unused).toEqual(["head_wm1_normal_map.png"]);- const head = t.materials("head_lod0_mesh");- expect(- [head.colorTexture, head.normalTexture, head.occlusionTexture].every(- Boolean,- ),- ).toBe(true);- // Roughness from the map's green channel; no metal from its blue.- expect([head.metallic, head.roughness]).toEqual([0, 1]);- expect(t.materials("eyelashes_lod0_mesh").alphaMode).toBe("mask");- } finally {- await rm(dir, { recursive: true, force: true });- }- });-});diff --git a/packages/dna/src/materials.ts b/packages/dna/src/materials.tsdeleted file mode 100644index d063905d..00000000--- a/packages/dna/src/materials.ts+++ /dev/null@@ -1,199 +0,0 @@-/**- * Materials for the meshes a DNA head or body is made of. Each mesh plays a- * role, found from its name (`head_lod0_mesh` is skin, `eyeshell_lod0_mesh`- * the clear film over an eye, …), and each role has a material built from- * what the engine renders: skin with subsurface scattering, wet teeth,- * clear glass, thin transparent films, alpha-tested lashes.- *- * `dnaMaterials(doc, folder)` also looks for the export's textures in a- * folder, by the role and map words in their file names (`head_color`,- * `head_normal`, `head_roughness`, `head_cavity`, …). The names a real- * export uses are not confirmed yet: what it finds is reported, so a- * mismatch is easy to see and to fix with `materials`.- */-import { readdir, readFile } from "node:fs/promises";-import path from "node:path";-import type {- GltfDocument,- MaterialSpec,- TextureRef,-} from "@framefields/forge";--export type MeshRole =- | "skin"- | "teeth"- | "saliva"- | "eye"- | "eyeshell"- | "eyeEdge"- | "eyelashes"- | "cartilage";--/** Mesh name patterns, most specific first. */-const ROLES: [RegExp, MeshRole][] = [- [/eye_?shell/i, "eyeshell"],- [/eye_?edge|tear/i, "eyeEdge"],- [/eye_?lash|lashes/i, "eyelashes"],- [/eye_?(left|right|l|r)\b|^eye/i, "eye"],- [/saliva/i, "saliva"],- [/teeth|tooth|tongue|mouth/i, "teeth"],- [/cartilage/i, "cartilage"],-];--/** The role a mesh plays, from its name; skin when nothing else fits. */-export function meshRole(mesh: string): MeshRole {- return ROLES.find(([pattern]) => pattern.test(mesh))?.[1] ?? "skin";-}--export interface RoleTextures {- color?: TextureRef;- normal?: TextureRef;- roughness?: TextureRef;- occlusion?: TextureRef;-}--/** A role's material, with whatever textures were found for it. */-export function roleMaterial(- role: MeshRole,- t: RoleTextures = {},-): MaterialSpec {- const maps: MaterialSpec = {- ...(t.color ? { colorTexture: t.color } : {}),- ...(t.normal ? { normalTexture: t.normal } : {}),- // A grayscale roughness map: glTF reads roughness from green and metal from blue, so metal is kept off.- ...(t.roughness- ? { metallicRoughnessTexture: t.roughness, metallic: 0, roughness: 1 }- : {}),- ...(t.occlusion ? { occlusionTexture: t.occlusion } : {}),- };- switch (role) {- case "skin":- return {- color: t.color ? "#ffffff" : "#d2a98f",- roughness: 0.5,- subsurface: { factor: 0.7, color: "#ff5a3c" },- ...maps,- };- case "teeth":- return {- color: t.color ? "#ffffff" : "#e8dccb",- roughness: 0.3,- subsurface: { factor: 0.5, color: "#ff8070" },- ...maps,- };- case "eye":- return {- color: t.color ? "#ffffff" : "#d8d4cf",- roughness: 0.2,- clearcoat: { factor: 1, roughness: 0.03 },- ...maps,- };- // The clear film over the eye: refracts what is under it.- case "eyeshell":- return {- color: "#ffffff",- roughness: 0.02,- transmission: 1,- ior: 1.376,- volume: { thickness: 0.05 },- };- // Thin wet films and the soft blend where lid meets eye.- case "saliva":- return { color: "#ffffff80", roughness: 0.05, alphaMode: "blend" };- case "eyeEdge":- return { color: "#ffffff30", roughness: 0.1, alphaMode: "blend" };- case "cartilage":- return { color: "#e0a8a060", roughness: 0.3, alphaMode: "blend" };- case "eyelashes":- return {- color: t.color ? "#ffffff" : "#1a1410",- roughness: 0.6,- doubleSided: true,- ...(t.color- ? { colorTexture: t.color, alphaMode: "mask", alphaCutoff: 0.5 }- : {}),- };- }-}--/** File name words per role (what a texture's name must mention) and per map. */-const ROLE_WORDS: Record<MeshRole, RegExp> = {- skin: /head|face|body/i,- teeth: /teeth|tooth/i,- saliva: /saliva/i,- eye: /eye(?!lash|shell|edge)/i,- eyeshell: /eyeshell/i,- eyeEdge: /eyeedge/i,- eyelashes: /lash/i,- cartilage: /cartilage/i,-};-const MAP_WORDS: [keyof RoleTextures, RegExp][] = [- ["normal", /normal|nrm|_n\b/i],- ["roughness", /rough/i],- ["occlusion", /cavity|occlusion|\bao\b/i],- ["color", /color|colour|albedo|diffuse|base/i],-];-const IMAGE = /\.(png|jpe?g|webp)$/i;-const MIME: Record<string, "image/png" | "image/jpeg" | "image/webp"> = {- ".png": "image/png",- ".jpg": "image/jpeg",- ".jpeg": "image/jpeg",- ".webp": "image/webp",-};--export interface FoundTextures {- /** Which file each role's map came from. */- found: Partial<Record<MeshRole, Partial<Record<keyof RoleTextures, string>>>>;- /** Images that matched no role and map. */- unused: string[];- /** A material per mesh, for `dnaToGlb` / `addDna`'s `materials`. */- materials: (mesh: string) => MaterialSpec;-}--/**- * Finds the export's textures in `folder` (PNG, JPEG, WebP), adds them to- * `doc`, and returns a material per mesh role. Wrinkle maps and masks- * (animated maps) are left for the rig evaluation. A texture name naming- * several maps counts for the first that fits, in the order normal,- * roughness, cavity, color.- */-export async function dnaMaterials(- doc: GltfDocument,- folder: string,-): Promise<FoundTextures> {- const files = (await readdir(folder)).filter((f) => IMAGE.test(f)).sort();- const found: FoundTextures["found"] = {};- const refs: Partial<Record<MeshRole, RoleTextures>> = {};- const unused: string[] = [];- for (const file of files) {- const base = path.basename(file, path.extname(file));- if (/wrinkle|mask|_wm\d/i.test(base)) {- unused.push(file);- continue;- }- const role =- (Object.keys(ROLE_WORDS) as MeshRole[]).find(- (r) => r !== "skin" && ROLE_WORDS[r].test(base),- ) ?? (ROLE_WORDS.skin.test(base) ? "skin" : undefined);- const map = MAP_WORDS.find(([, w]) => w.test(base))?.[0];- if (!role || !map || found[role]?.[map]) {- unused.push(file);- continue;- }- const image = new Uint8Array(await readFile(path.join(folder, file)));- const ref = doc.addTexture({- image,- mimeType: MIME[path.extname(file).toLowerCase()] ?? "image/png",- });- refs[role] = { ...refs[role], [map]: ref };- found[role] = { ...found[role], [map]: file };- }- return {- found,- unused,- materials: (mesh) => {- const role = meshRole(mesh);- return roleMaterial(role, refs[role]);- },- };-}diff --git a/packages/dna/src/read.ts b/packages/dna/src/read.tsdeleted file mode 100644index b3f812f2..00000000--- a/packages/dna/src/read.ts+++ /dev/null@@ -1,616 +0,0 @@-/**- * Reads a DNA file: the character description (name, units, axes), the- * definition (controls, joints and their neutral pose, blend shape channels,- * animated maps, meshes, LOD mappings), the rig behavior (pose-space- * controls, joint matrices, blend shape and animated map mappings) and the- * geometry (meshes with UVs, normals, skin weights and blend shape targets).- *- * File versions 2.1 (section table) and 2.2–2.8 (layer index) are read.- * Layers this reader does not use yet (RBF, twist/swing, machine-learned- * behavior, joint metadata) are listed by id and left unread.- *- * Based on OpenRigLogic's DNA library (MIT, Epic Games): the layout follows- * its `DNA.h` serializers.- */-import { ByteReader } from "./bytes.js";--export type AxisDirection = "left" | "right" | "up" | "down" | "front" | "back";-export type RotationSequence = "xyz" | "xzy" | "yxz" | "yzx" | "zxy" | "zyx";--export interface DnaDescriptor {- name: string;- archetype: number;- gender: number;- age: number;- metadata: [string, string][];- translationUnit: "cm" | "m";- rotationUnit: "degrees" | "radians";- /** Where each file axis points. */- coordinateSystem: [AxisDirection, AxisDirection, AxisDirection];- lodCount: number;- maxLOD: number;- complexity: string;- dbName: string;- /** Euler order of joint rotations (from file version 2.7; before it, xyz). */- rotationSequence: RotationSequence;- /** Per axis, 1 or -1: the direction a positive angle turns. */- rotationSign: [number, number, number];- faceWindingOrder: "ccw" | "cw";-}--/** For each LOD, a row of `indices`: the elements that LOD uses. */-export interface LodMapping {- lods: Uint16Array;- indices: Uint16Array[];-}--export interface DnaDefinition {- lodJointMapping: LodMapping;- lodBlendShapeMapping: LodMapping;- lodAnimatedMapMapping: LodMapping;- lodMeshMapping: LodMapping;- guiControlNames: string[];- rawControlNames: string[];- jointNames: string[];- blendShapeChannelNames: string[];- animatedMapNames: string[];- meshNames: string[];- /** Pairs (mesh, blend shape channel). */- meshBlendShapeChannelMapping: { from: Uint16Array; to: Uint16Array };- /** Per joint, its parent (a root is its own parent). */- jointHierarchy: Uint16Array;- /** Per joint, translation from its parent, in the descriptor's unit. */- neutralJointTranslations: Vec3Array;- /** Per joint, Euler rotation relative to its parent, in the descriptor's unit and order. */- neutralJointRotations: Vec3Array;-}--/** Three parallel arrays. */-export interface Vec3Array {- xs: Float32Array;- ys: Float32Array;- zs: Float32Array;-}--/** Piecewise linear outputs: `output += slope · input + cut` where `from ≤ input ≤ to`. */-export interface ConditionalTable {- inputIndices: Uint16Array;- outputIndices: Uint16Array;- fromValues: Float32Array;- toValues: Float32Array;- slopeValues: Float32Array;- cutValues: Float32Array;-}--export interface JointGroup {- lods: Uint16Array;- inputIndices: Uint16Array;- outputIndices: Uint16Array;- /** Row-major, outputIndices × inputIndices. */- values: Float32Array;- jointIndices: Uint16Array;-}--export interface DnaBehavior {- controls: {- psdCount: number;- /** GUI to raw controls. */- conditionals: ConditionalTable;- /** Pose-space controls: products of raw controls. */- psds: { rows: Uint16Array; columns: Uint16Array; values: Float32Array };- };- joints: { rowCount: number; colCount: number; jointGroups: JointGroup[] };- blendShapeChannels: {- lods: Uint16Array;- inputIndices: Uint16Array;- outputIndices: Uint16Array;- };- animatedMaps: { lods: Uint16Array; conditionals: ConditionalTable };-}--export interface DnaMesh {- positions: Vec3Array;- uvs: { us: Float32Array; vs: Float32Array };- normals: Vec3Array;- /** Per vertex layout: position, UV and normal indices. */- layouts: { positions: Uint32Array; uvs: Uint32Array; normals: Uint32Array };- /** Polygons as layout indices. */- faces: Uint32Array[];- maximumInfluencePerVertex: number;- /** Per position. */- skinWeights: { weights: Float32Array; jointIndices: Uint16Array }[];- blendShapeTargets: {- deltas: Vec3Array;- vertexIndices: Uint32Array;- channel: number;- }[];-}--export type TwistAxis = "x" | "y" | "z";--/** One RBF solver: how close the current joint rotations are to each of its poses. */-export interface RbfSolver {- name: string;- /** The raw controls it reads (usually joint quaternions, four per joint). */- rawControlIndices: Uint16Array;- /** Its poses (indices into `DnaRbf.poses`). */- poseIndices: Uint16Array;- /** Per pose, the raw control values that define it. */- rawControlValues: Float32Array;- /** Kernel width, in the descriptor's rotation unit. */- radius: number;- weightThreshold: number;- solverType: "additive" | "interpolative";- /** Radius from the mean distance between poses. */- automaticRadius: boolean;- distanceMethod: "euclidean" | "quaternion" | "swingAngle" | "twistAngle";- normalizeMethod: "onlyAboveOne" | "always";- functionType: "gaussian" | "exponential" | "linear" | "cubic" | "quintic";- twistAxis: TwistAxis;-}--/** Pose-space correctives (body): RBF solvers whose pose weights drive controls. */-export interface DnaRbf {- lodSolverMapping: LodMapping;- solvers: RbfSolver[];- poses: { name: string; scale: number }[];- /** The controls poses write (after raw, PSD and ML controls). */- poseControlNames: string[];- /** Per pose: controls that gate it (multiplied), and the controls it writes with their weights. */- poseControls: {- inputControlIndices: Uint16Array;- outputControlIndices: Uint16Array;- outputControlWeights: Float32Array;- }[];-}--/** A joint's rotation split into twist and swing, spread over other joints. */-export interface TwistSwingSetup {- /** Per output joint: how far it stays from the full rotation (0 follows it, 1 stays still). */- blendWeights: Float32Array;- outputJointIndices: Uint16Array;- /** The four raw controls holding the source joint's quaternion. */- inputControlIndices: Uint16Array;- twistAxis: TwistAxis;-}--export interface DnaFile {- version: { generation: number; version: number };- descriptor: DnaDescriptor;- definition: DnaDefinition;- behavior?: DnaBehavior;- /** Machine-learned controls (their values are not evaluated yet; they sit between PSD and RBF controls). */- mlControlNames?: string[];- rbf?: DnaRbf;- twistSwing?: { twists: TwistSwingSetup[]; swings: TwistSwingSetup[] };- /** Per joint: how translation, rotation and scale are represented (rotation "quaternion" joints need RigLogic's quaternion path). */- jointRepresentations?: {- translation: "vector";- rotation: "euler" | "quaternion";- scale: "vector";- }[];- geometry?: { meshes: DnaMesh[] };- /** Every layer in the file, by four-letter id and layer version. */- layers: { id: string; version: string }[];-}--export interface ReadDnaOptions {- /** Read the meshes. Default true. */- geometry?: boolean;- /** Read the rig behavior. Default true. */- behavior?: boolean;-}--const AXES: AxisDirection[] = ["left", "right", "up", "down", "front", "back"];-const SEQUENCES: RotationSequence[] = [- "xyz",- "xzy",- "yxz",- "yzx",- "zxy",- "zyx",-];--export function readDna(- bytes: Uint8Array,- options: ReadDnaOptions = {},-): DnaFile {- const r = new ByteReader(bytes);- if (r.length < 7 || r.chars(3) !== "DNA")- throw new Error("dna: not a DNA file (no DNA signature)");- const generation = r.u16();- const version = r.u16();- if (generation !== 2)- throw new Error(- `dna: file generation ${generation} is not supported (2 is)`,- );- if (version < 1 || version > 8)- throw new Error(- `dna: file version 2.${version} is not supported (2.1 to 2.8 are)`,- );- return version === 1 ? readV21(r, options) : readLayered(r, version, options);-}--/** 2.2 and later: an index of layers by id, version, offset and size. */-function readLayered(- r: ByteReader,- version: number,- options: ReadDnaOptions,-): DnaFile {- const index = r.list((x) => ({- id: x.u32(),- version: x.u32(),- offset: x.u32(),- size: x.u32(),- }));- const name = (id: number) =>- String.fromCharCode(- id >>> 24,- (id >>> 16) & 255,- (id >>> 8) & 255,- id & 255,- );- const at = (id: string) => {- const entry = index.find((e) => name(e.id) === id);- if (entry) r.seek(entry.offset);- return entry;- };- if (!at("desc")) throw new Error("dna: no descriptor layer");- const descriptor = readDescriptor(r);- if (at("dsce")) Object.assign(descriptor, readDescriptorExt(r, version));- if (!at("defn")) throw new Error("dna: no definition layer");- const definition = readDefinition(r);- const file: DnaFile = {- version: { generation: 2, version },- descriptor,- definition,- layers: index.map((e) => ({- id: name(e.id),- version: `${e.version >>> 16}.${e.version & 0xffff}`,- })),- };- if (options.behavior !== false && at("bhvr")) {- file.behavior = readBehavior(r);- if (at("mlbh")) file.mlControlNames = r.list((x) => x.string());- if (at("rbfb")) {- const rbf = readRbf(r);- if (at("rbfe")) readRbfExt(r, rbf);- file.rbf = withPoseControls(rbf, file);- }- if (at("twsw"))- file.twistSwing = {- twists: r.list(readTwistSwing),- swings: r.list(readTwistSwing),- };- if (at("jbmd")) {- const listed = r.list((x) => {- x.u16();- const rotation: "euler" | "quaternion" =- x.u16() === 1 ? "quaternion" : "euler";- x.u16();- return {- translation: "vector" as const,- rotation,- scale: "vector" as const,- };- });- // Joints the layer does not list are Euler, as RigLogic reads them.- file.jointRepresentations = definition.jointNames.map(- (_, j) =>- listed[j] ?? {- translation: "vector" as const,- rotation: "euler" as const,- scale: "vector" as const,- },- );- }- }- if (options.geometry !== false && at("geom"))- file.geometry = { meshes: r.list(readMesh) };- return file;-}--/** 2.1: a table of section offsets, then the sections. */-function readV21(r: ByteReader, options: ReadDnaOptions): DnaFile {- const [- descriptorAt,- definitionAt,- ,- controlsAt,- jointsAt,- blendShapesAt,- animatedMapsAt,- geometryAt,- ] = Array.from({ length: 8 }, () => r.u32());- r.seek(descriptorAt as number);- const descriptor = readDescriptor(r);- r.seek(definitionAt as number);- const definition = readDefinition(r);- const file: DnaFile = {- version: { generation: 2, version: 1 },- descriptor,- definition,- layers: [],- };- if (options.behavior !== false) {- r.seek(controlsAt as number);- const controls = readControls(r);- r.seek(jointsAt as number);- const joints = readJoints(r);- r.seek(blendShapesAt as number);- const blendShapeChannels = readBlendShapeChannels(r);- r.seek(animatedMapsAt as number);- const animatedMaps = readAnimatedMaps(r);- file.behavior = { controls, joints, blendShapeChannels, animatedMaps };- }- if (options.geometry !== false) {- r.seek(geometryAt as number);- file.geometry = { meshes: r.list(readMeshV21) };- }- return file;-}--function readDescriptor(r: ByteReader): DnaDescriptor {- const name = r.string();- const archetype = r.u16();- const gender = r.u16();- const age = r.u16();- const metadata = r.list((x) => [x.string(), x.string()] as [string, string]);- const translationUnit = r.u16() === 1 ? "m" : "cm";- const rotationUnit = r.u16() === 1 ? "radians" : "degrees";- const axis = () => {- const a = AXES[r.u16()];- if (!a)- throw new Error("dna: unknown axis direction in the coordinate system");- return a;- };- const coordinateSystem: [AxisDirection, AxisDirection, AxisDirection] = [- axis(),- axis(),- axis(),- ];- return {- name,- archetype,- gender,- age,- metadata,- translationUnit,- rotationUnit,- coordinateSystem,- lodCount: r.u16(),- maxLOD: r.u16(),- complexity: r.string(),- dbName: r.string(),- rotationSequence: "xyz",- rotationSign: [1, 1, 1],- faceWindingOrder: "ccw",- };-}--/** Rotation order and signs; the face winding order from file version 2.8. */-function readDescriptorExt(- r: ByteReader,- version: number,-): Pick<- DnaDescriptor,- "rotationSequence" | "rotationSign" | "faceWindingOrder"-> {- const sequence = SEQUENCES[r.u32()];- if (!sequence) throw new Error("dna: unknown rotation sequence");- const sign: [number, number, number] = [- r.i32() < 0 ? -1 : 1,- r.i32() < 0 ? -1 : 1,- r.i32() < 0 ? -1 : 1,- ];- const faceWindingOrder = version >= 8 && r.u8() === 1 ? "cw" : "ccw";- return { rotationSequence: sequence, rotationSign: sign, faceWindingOrder };-}--function readLodMapping(r: ByteReader): LodMapping {- return { lods: r.u16s(), indices: r.list((x) => x.u16s()) };-}--function readVec3Array(r: ByteReader): Vec3Array {- return { xs: r.f32s(), ys: r.f32s(), zs: r.f32s() };-}--function readDefinition(r: ByteReader): DnaDefinition {- const strings = () => r.list((x) => x.string());- return {- lodJointMapping: readLodMapping(r),- lodBlendShapeMapping: readLodMapping(r),- lodAnimatedMapMapping: readLodMapping(r),- lodMeshMapping: readLodMapping(r),- guiControlNames: strings(),- rawControlNames: strings(),- jointNames: strings(),- blendShapeChannelNames: strings(),- animatedMapNames: strings(),- meshNames: strings(),- meshBlendShapeChannelMapping: { from: r.u16s(), to: r.u16s() },- jointHierarchy: r.u16s(),- neutralJointTranslations: readVec3Array(r),- neutralJointRotations: readVec3Array(r),- };-}--function readConditionalTable(r: ByteReader): ConditionalTable {- return {- inputIndices: r.u16s(),- outputIndices: r.u16s(),- fromValues: r.f32s(),- toValues: r.f32s(),- slopeValues: r.f32s(),- cutValues: r.f32s(),- };-}--function readControls(r: ByteReader): DnaBehavior["controls"] {- return {- psdCount: r.u16(),- conditionals: readConditionalTable(r),- psds: { rows: r.u16s(), columns: r.u16s(), values: r.f32s() },- };-}--function readJoints(r: ByteReader): DnaBehavior["joints"] {- return {- rowCount: r.u16(),- colCount: r.u16(),- jointGroups: r.list((x) => ({- lods: x.u16s(),- inputIndices: x.u16s(),- outputIndices: x.u16s(),- values: x.f32s(),- jointIndices: x.u16s(),- })),- };-}--function readBlendShapeChannels(- r: ByteReader,-): DnaBehavior["blendShapeChannels"] {- return { lods: r.u16s(), inputIndices: r.u16s(), outputIndices: r.u16s() };-}--function readAnimatedMaps(r: ByteReader): DnaBehavior["animatedMaps"] {- return { lods: r.u16s(), conditionals: readConditionalTable(r) };-}--function readBehavior(r: ByteReader): DnaBehavior {- return {- controls: readControls(r),- joints: readJoints(r),- blendShapeChannels: readBlendShapeChannels(r),- animatedMaps: readAnimatedMaps(r),- };-}--function readMeshBody(r: ByteReader): DnaMesh {- return {- positions: readVec3Array(r),- uvs: { us: r.f32s(), vs: r.f32s() },- normals: readVec3Array(r),- layouts: { positions: r.u32s(), uvs: r.u32s(), normals: r.u32s() },- faces: r.list((x) => x.u32s()),- maximumInfluencePerVertex: r.u16(),- skinWeights: r.list((x) => ({ weights: x.f32s(), jointIndices: x.u16s() })),- blendShapeTargets: r.list((x) => ({- deltas: readVec3Array(x),- vertexIndices: x.u32s(),- channel: x.u16(),- })),- };-}--/** 2.2 and later: the mesh's byte size, then the mesh. */-function readMesh(r: ByteReader): DnaMesh {- const size = r.u32();- const base = r.offset;- const mesh = readMeshBody(r);- r.seek(base + size);- return mesh;-}--/** 2.1: the offset just past the mesh, then the mesh. */-function readMeshV21(r: ByteReader): DnaMesh {- const end = r.u32();- const mesh = readMeshBody(r);- r.seek(end);- return mesh;-}--const AXIS: TwistAxis[] = ["x", "y", "z"];-const SOLVER_TYPES: RbfSolver["solverType"][] = ["additive", "interpolative"];-const DISTANCES: RbfSolver["distanceMethod"][] = [- "euclidean",- "quaternion",- "swingAngle",- "twistAngle",-];-const NORMALIZE: RbfSolver["normalizeMethod"][] = ["onlyAboveOne", "always"];-const FUNCTIONS: RbfSolver["functionType"][] = [- "gaussian",- "exponential",- "linear",- "cubic",- "quintic",-];--function pick<T>(list: readonly T[], i: number, what: string): T {- const v = list[i];- if (v === undefined) throw new Error(`dna: unknown ${what} ${i}`);- return v;-}--/** The RBF layer: solvers, their LODs, and poses. */-function readRbf(r: ByteReader): DnaRbf {- const lodSolverMapping = readLodMapping(r);- const solvers = r.list((x): RbfSolver => {- const size = x.u32();- const base = x.offset;- const solver: RbfSolver = {- name: x.string(),- rawControlIndices: x.u16s(),- poseIndices: x.u16s(),- rawControlValues: x.f32s(),- radius: x.f32(),- weightThreshold: x.f32(),- solverType: pick(SOLVER_TYPES, x.u16(), "RBF solver type"),- // AutomaticRadius: On is 0, Off is 1.- automaticRadius: x.u16() === 0,- distanceMethod: pick(DISTANCES, x.u16(), "RBF distance method"),- normalizeMethod: pick(NORMALIZE, x.u16(), "RBF normalize method"),- functionType: pick(FUNCTIONS, x.u16(), "RBF function type"),- twistAxis: pick(AXIS, x.u16(), "twist axis"),- };- x.seek(base + size);- return solver;- });- const poses = r.list((x) => ({ name: x.string(), scale: x.f32() }));- return {- lodSolverMapping,- solvers,- poses,- poseControlNames: [],- poseControls: [],- };-}--/** The RBF extension layer: the controls poses write, and what gates them. */-function readRbfExt(r: ByteReader, rbf: DnaRbf): void {- rbf.poseControlNames = r.list((x) => x.string());- rbf.poseControls = r.list((x) => ({- inputControlIndices: x.u16s(),- outputControlIndices: x.u16s(),- outputControlWeights: x.f32s(),- }));-}--/** Without the extension, pose i writes control (raw + PSD + ML) + i, weight 1. */-function withPoseControls(rbf: DnaRbf, file: DnaFile): DnaRbf {- if (rbf.poseControls.length || !rbf.poses.length) return rbf;- const first =- file.definition.rawControlNames.length +- (file.behavior?.controls.psdCount ?? 0) +- (file.mlControlNames?.length ?? 0);- return {- ...rbf,- poseControlNames: rbf.poses.map((p) => p.name),- poseControls: rbf.poses.map((_, i) => ({- inputControlIndices: new Uint16Array(0),- outputControlIndices: Uint16Array.of(first + i),- outputControlWeights: Float32Array.of(1),- })),- };-}--function readTwistSwing(r: ByteReader): TwistSwingSetup {- return {- blendWeights: r.f32s(),- outputJointIndices: r.u16s(),- inputControlIndices: r.u16s(),- twistAxis: pick(AXIS, r.u16(), "twist axis"),- };-}diff --git a/packages/dna/src/rig-body.ts b/packages/dna/src/rig-body.tsdeleted file mode 100644index 6809eef2..00000000--- a/packages/dna/src/rig-body.ts+++ /dev/null@@ -1,548 +0,0 @@-/**- * The body parts of rig evaluation, driven by the animated skeleton (joint- * rotations arrive as quaternions in raw controls):- *- * - RBF solvers measure how close the current rotations are to each of a- * set of poses (by Euclidean, quaternion arc, swing or twist distance,- * through a Gaussian, exponential, linear, cubic or quintic kernel), and- * the pose weights drive corrective controls: the shoulder and elbow- * shapes linear skinning alone cannot make.- * - Twist/swing splits a joint's rotation about an axis and spreads it over- * helper joints (forearm twist bones, the shoulder following the arm).- *- * Based on OpenRigLogic's RigLogic (MIT, Epic Games): the solver, distance,- * kernel, slerp and quaternion-to-Euler code follow `RBFSolver.cpp`,- * `InterpolativeRBFSolver.cpp`, `TwistSwingJointsEvaluator.h` and tdm.- */-import type {- DnaFile,- RbfSolver,- RotationSequence,- TwistAxis,- TwistSwingSetup,-} from "./read.js";--type Q = [number, number, number, number];--const AXIS_INDEX: Record<TwistAxis, number> = { x: 0, y: 1, z: 2 };-const FLOAT_EPSILON = 1.1920929e-7;--// ── Quaternion parts ────────────────────────────────────────────────--/** The swing part about `axis` (twist removed), in place; w comes out non-positive, as RigLogic's. */-function toSwing(q: Float64Array, o: number, axis: TwistAxis): void {- const [x, y, z, w] = [- q[o] as number,- q[o + 1] as number,- q[o + 2] as number,- q[o + 3] as number,- ];- if (axis === "x") {- const nw = -Math.sqrt(x * x + w * w);- q.set([0, (w * y - x * z) / nw, (w * z + x * y) / nw, nw], o);- } else if (axis === "y") {- const nw = -Math.sqrt(y * y + w * w);- q.set([(w * x + y * z) / nw, 0, (w * z - y * x) / nw, nw], o);- } else {- const nw = -Math.sqrt(z * z + w * w);- q.set([(w * x - z * y) / nw, (w * y + z * x) / nw, 0, nw], o);- }-}--/** The twist part about `axis`, normalized, in place. */-function toTwist(q: Float64Array, o: number, axis: TwistAxis): void {- const t = AXIS_INDEX[axis];- q[o + ((t + 1) % 3)] = 0;- q[o + ((t + 2) % 3)] = 0;- const m = Math.hypot(q[o + t] as number, q[o + 3] as number);- if (m === 0) {- q[o + t] = 0;- q[o + 3] = 1;- return;- }- q[o + t] = (q[o + t] as number) / m;- q[o + 3] = (q[o + 3] as number) / m;-}--function twistAngle(q: ArrayLike<number>, o: number): number {- let a =- 2 *- Math.atan2(- (q[o] as number) + (q[o + 1] as number) + (q[o + 2] as number),- q[o + 3] as number,- );- if (a > Math.PI) a -= 2 * Math.PI;- else if (a < -Math.PI) a += 2 * Math.PI;- return a;-}--// ── RBF ─────────────────────────────────────────────────────────────--type Distance = (target: Float64Array, input: Float64Array) => number;--const DISTANCE: Record<"euclidean" | "quaternion" | "twistAngle", Distance> = {- euclidean: (t, x) => {- let s = 0;- for (let i = 0; i < x.length; i++)- s += ((t[i] as number) - (x[i] as number)) ** 2;- return Math.sqrt(s);- },- quaternion: (t, x) => {- let s = 0;- for (let o = 0; o + 3 < x.length; o += 4) {- const dot =- (t[o] as number) * (x[o] as number) +- (t[o + 1] as number) * (x[o + 1] as number) +- (t[o + 2] as number) * (x[o + 2] as number) +- (t[o + 3] as number) * (x[o + 3] as number);- const d2 = dot * dot;- const arc = d2 > 1 ? 0 : Math.acos(2 * d2 - 1);- s += arc * arc;- }- return Math.sqrt(s);- },- twistAngle: (t, x) => {- let s = 0;- for (let o = 0; o + 3 < x.length; o += 4)- s += (twistAngle(t, o) - twistAngle(x, o)) ** 2;- return Math.sqrt(s);- },-};--const KERNEL: Record<- RbfSolver["functionType"],- (d: number, width: number) => number-> = {- linear: (d, w) => Math.max(0, 1 - d / w),- cubic: (d, w) => Math.max(0, 1 - (d / w) ** 3),- quintic: (d, w) => Math.max(0, 1 - (d / w) ** 5),- gaussian: (d, w) => Math.exp(-d / (w * w)),- exponential: (d, w) => Math.exp((-2 * d) / w),-};--/** Inverts `m` in place by LU decomposition with scaled partial pivoting; leaves it as is when a row is all zero. */-function invert(m: Float64Array[]): Float64Array[] {- const n = m.length;- const a = m.map((row) => Float64Array.from(row));- const permute = new Array<number>(n).fill(0);- const scale = new Float64Array(n);- for (let i = 0; i < n; i++) {- let max = 0;- for (let j = 0; j < n; j++)- max = Math.max(max, Math.abs((a[i] as Float64Array)[j] as number));- if (max === 0) return m;- scale[i] = 1 / max;- }- for (let j = 0; j < n; j++) {- for (let i = 0; i < j; i++) {- const ai = a[i] as Float64Array;- let sum = ai[j] as number;- for (let k = 0; k < i; k++)- sum -= (ai[k] as number) * ((a[k] as Float64Array)[j] as number);- ai[j] = sum;- }- let iMax = 0;- let colMax = 0;- for (let i = j; i < n; i++) {- const ai = a[i] as Float64Array;- let sum = ai[j] as number;- for (let k = 0; k < j; k++)- sum -= (ai[k] as number) * ((a[k] as Float64Array)[j] as number);- ai[j] = sum;- const t = (scale[i] as number) * Math.abs(sum);- if (t >= colMax) {- colMax = t;- iMax = i;- }- }- if (j !== iMax) {- const rowMax = a[iMax];- const rowJ = a[j];- if (rowMax && rowJ) {- a[iMax] = rowJ;- a[j] = rowMax;- }- scale[iMax] = scale[j] as number;- }- permute[j] = iMax;- const aj = a[j] as Float64Array;- if (aj[j] === 0) aj[j] = 1e-20;- if (j !== n - 1) {- const t = 1 / (aj[j] as number);- for (let i = j + 1; i < n; i++)- (a[i] as Float64Array)[j] = ((a[i] as Float64Array)[j] as number) * t;- }- }- const inv = Array.from({ length: n }, () => new Float64Array(n));- for (let j = 0; j < n; j++) {- const b = new Float64Array(n);- b[j] = 1;- let ii = 0;- for (let i = 0; i < n; i++) {- const ip = permute[i] as number;- let sum = b[ip] as number;- b[ip] = b[i] as number;- if (ii)- for (let k = ii - 1; k < i; k++)- sum -= ((a[i] as Float64Array)[k] as number) * (b[k] as number);- else if (sum !== 0) ii = i + 1;- b[i] = sum;- }- for (let i = n - 1; i >= 0; i--) {- let sum = b[i] as number;- for (let k = i + 1; k < n; k++)- sum -= ((a[i] as Float64Array)[k] as number) * (b[k] as number);- b[i] = sum / ((a[i] as Float64Array)[i] as number);- }- for (let i = 0; i < n; i++) (inv[i] as Float64Array)[j] = b[i] as number;- }- return inv;-}--/** A solver ready to run: converted targets, radius, interpolation coefficients. */-export class RbfSolverRuntime {- private readonly targets: Float64Array[];- private readonly distance: Distance;- private readonly convert: (q: Float64Array) => void;- private readonly radius: number;- private readonly coefficients?: Float64Array[];- private readonly input: Float64Array;- /** Pose weights from the last `solve`. */- readonly weights: Float64Array;- /** The controls its poses write, cleared before they add up. */- readonly outputs: number[];-- constructor(- readonly solver: RbfSolver,- private readonly scales: number[],- angleToRadians: number,- poseOutputs: number[],- ) {- const n = solver.rawControlIndices.length;- const convertEach =- solver.distanceMethod === "twistAngle"- ? toTwist- : solver.distanceMethod === "swingAngle"- ? toSwing- : undefined;- this.convert = (q) => {- if (convertEach)- for (let o = 0; o + 3 < q.length; o += 4)- convertEach(q, o, solver.twistAxis);- };- this.distance =- DISTANCE[- solver.distanceMethod === "swingAngle"- ? "quaternion"- : solver.distanceMethod- ];- this.targets = Array.from(solver.poseIndices, (_, i) => {- const t = Float64Array.from(- solver.rawControlValues.subarray(i * n, i * n + n),- );- this.convert(t);- return t;- });- const count = this.targets.length;- if (solver.automaticRadius) {- let sum = 0;- for (let i = 0; i < count; i++)- for (let j = i + 1; j < count; j++)- sum += this.distance(- this.targets[j] as Float64Array,- this.targets[i] as Float64Array,- );- this.radius = sum / ((count * (count - 1)) / 2);- } else this.radius = solver.radius * angleToRadians;- if (solver.solverType === "interpolative") {- const kernel = KERNEL[solver.functionType];- const m = this.targets.map((ti) =>- Float64Array.from(this.targets, (tj) =>- kernel(this.distance(tj, ti), this.radius),- ),- );- this.coefficients = invert(m);- }- this.input = new Float64Array(n);- this.weights = new Float64Array(count);- this.outputs = [...new Set(poseOutputs)].sort((x, y) => x - y);- }-- /** Pose weights for the current controls. */- solve(controls: Float32Array): void {- const s = this.solver;- s.rawControlIndices.forEach((c, i) => {- this.input[i] = controls[c] as number;- });- this.convert(this.input);- const kernel = KERNEL[s.functionType];- const count = this.targets.length;- const near: Float64Array = Float64Array.from(this.targets, (t) =>- kernel(this.distance(t, this.input), this.radius),- );- const w = this.weights;- if (this.coefficients) {- for (let i = 0; i < count; i++) {- let sum = 0;- const row = this.coefficients[i] as Float64Array;- for (let j = 0; j < count; j++)- sum += (row[j] as number) * (near[j] as number);- w[i] = Math.min(1, Math.max(0, sum));- }- } else w.set(near);- let total = 0;- for (const x of w) total += x;- const ratio = total > 1 || s.normalizeMethod === "always" ? 1 / total : 1;- for (let i = 0; i < count; i++) {- const x = (w[i] as number) * ratio * (this.scales[i] as number);- w[i] = x > s.weightThreshold ? x : 0;- }- }-}--// ── Twist and swing ─────────────────────────────────────────────────--/** A swing (and the twist on the same source joint, if any), or a twist alone. */-export interface TwistSwingRuntime {- swing?: TwistSwingSetup;- twist?: TwistSwingSetup;-}--/** Swings first, then each twist joins the swing on the same source joint or stands alone. */-export function twistSwingSetups(dna: DnaFile): TwistSwingRuntime[] {- const ts = dna.twistSwing;- if (!ts) return [];- const setups: TwistSwingRuntime[] = ts.swings.map((swing) => ({ swing }));- const same = (a: Uint16Array, b: Uint16Array) =>- a.length === b.length && a.every((v, i) => v === b[i]);- for (const twist of ts.twists) {- const host = setups.find(- (s) =>- s.swing && same(s.swing.inputControlIndices, twist.inputControlIndices),- );- if (host) host.twist = twist;- else setups.push({ twist });- }- return setups;-}--const mul = (a: Q, b: Q): Q => [- a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],- a[3] * b[1] + a[1] * b[3] + a[2] * b[0] - a[0] * b[2],- a[3] * b[2] + a[2] * b[3] + a[0] * b[1] - a[1] * b[0],- a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],-];--function inverse(q: Q): Q {- const l2 = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3];- return [-q[0] / l2, -q[1] / l2, -q[2] / l2, q[3] / l2];-}--/** tdm's slerp: toward the nearer of q2 and −q2; linear when nearly equal. */-function slerp(q1: Q, q2: Q, t: number): Q {- let cos = q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3];- let b: Q = q2;- if (cos < 0) {- b = [-q2[0], -q2[1], -q2[2], -q2[3]];- cos = -cos;- }- let t1: number;- let t2: number;- if (cos > 1 - FLOAT_EPSILON) {- t1 = 1 - t;- t2 = t;- } else {- const theta = Math.acos(cos);- const r = 1 / Math.sin(theta);- t1 = Math.sin((1 - t) * theta) * r;- t2 = Math.sin(t * theta) * r;- }- return [- q1[0] * t1 + b[0] * t2,- q1[1] * t1 + b[1] * t2,- q1[2] * t1 + b[2] * t2,- q1[3] * t1 + b[3] * t2,- ];-}--function twistOf(q: Q, axis: TwistAxis): Q {- const t: Q = [0, 0, 0, q[3]];- const k = AXIS_INDEX[axis];- t[k] = q[k];- const l2 = t[k] * t[k] + t[3] * t[3];- if (l2 === 0) return [0, 0, 0, 1];- const l = Math.sqrt(l2);- return [t[0] / l, t[1] / l, t[2] / l, t[3] / l];-}--/** tdm's 7th-degree minimax asin. */-function fastAsin(value: number): number {- const halfPi = 1.570796305;- const nonNegative = value >= 0;- const v = Math.abs(value);- const root = Math.sqrt(Math.max(0, 1 - v));- const r =- ((((((-0.0012624911 * v + 0.0066700901) * v - 0.0170881256) * v +- 0.030891881) *- v -- 0.0501743046) *- v +- 0.0889789874) *- v -- 0.2145988016) *- v +- halfPi;- const acos = r * root;- return nonNegative ? halfPi - acos : acos - halfPi;-}--const NEAR_POLE = 0.99999999999;--/** tdm's quaternion to Euler angles (radians) in the given order, signs applied. */-export function quatToEuler(- q: Q,- order: RotationSequence,- signs: [number, number, number],-): [number, number, number] {- const [x, y, z, w] = q;- const xx2 = 2 * x * x;- const xy2 = 2 * x * y;- const xz2 = 2 * x * z;- const yy2 = 2 * y * y;- const yz2 = 2 * y * z;- const zz2 = 2 * z * z;- const wx2 = 2 * w * x;- const wy2 = 2 * w * y;- const wz2 = 2 * w * z;- let a: [number, number, number];- switch (order) {- case "xyz": {- const s = xz2 - wy2;- a =- Math.abs(s) < NEAR_POLE- ? [- Math.atan2(yz2 + wx2, 1 - (xx2 + yy2)),- fastAsin(-s),- Math.atan2(xy2 + wz2, 1 - (yy2 + zz2)),- ]- : [0, fastAsin(-s), Math.atan2(wz2 - xy2, 1 - (xx2 + zz2))];- break;- }- case "xzy": {- const s = xy2 + wz2;- a =- Math.abs(s) < NEAR_POLE- ? [- Math.atan2(wx2 - yz2, 1 - (xx2 + zz2)),- Math.atan2(wy2 - xz2, 1 - (yy2 + zz2)),- fastAsin(s),- ]- : [0, Math.atan2(xz2 + wy2, 1 - (xx2 + yy2)), fastAsin(s)];- break;- }- case "yxz": {- const s = yz2 + wx2;- a =- Math.abs(s) < NEAR_POLE- ? [- fastAsin(s),- Math.atan2(wy2 - xz2, 1 - (xx2 + yy2)),- Math.atan2(wz2 - xy2, 1 - (xx2 + zz2)),- ]- : [fastAsin(s), 0, Math.atan2(xy2 + wz2, 1 - (yy2 + zz2))];- break;- }- case "yzx": {- const s = xy2 - wz2;- a =- Math.abs(s) < NEAR_POLE- ? [- Math.atan2(yz2 + wx2, 1 - (xx2 + zz2)),- Math.atan2(xz2 + wy2, 1 - (yy2 + zz2)),- fastAsin(-s),- ]- : [Math.atan2(wx2 - yz2, 1 - (xx2 + yy2)), 0, fastAsin(-s)];- break;- }- case "zxy": {- const s = yz2 - wx2;- a =- Math.abs(s) < NEAR_POLE- ? [- fastAsin(-s),- Math.atan2(xz2 + wy2, 1 - (xx2 + yy2)),- Math.atan2(xy2 + wz2, 1 - (xx2 + zz2)),- ]- : [fastAsin(-s), Math.atan2(wy2 - xz2, 1 - (yy2 + zz2)), 0];- break;- }- case "zyx": {- const s = xz2 + wy2;- a =- Math.abs(s) < NEAR_POLE- ? [- Math.atan2(wx2 - yz2, 1 - (xx2 + yy2)),- fastAsin(s),- Math.atan2(wz2 - xy2, 1 - (yy2 + zz2)),- ]- : [Math.atan2(yz2 + wx2, 1 - (xx2 + zz2)), fastAsin(s), 0];- break;- }- }- return [a[0] * signs[0], a[1] * signs[1], a[2] * signs[2]];-}--/**- * Writes the twist/swing rotations over the joint outputs (Euler angles in- * the file's units and order, `attributes` values per joint, rotation at 3).- */-export function applyTwistSwing(- setups: TwistSwingRuntime[],- controls: Float32Array,- out: Float32Array,- attributes: number,- order: RotationSequence,- signs: [number, number, number],- fromRadians: number,-): void {- const identity: Q = [0, 0, 0, 1];- const quat = (idx: Uint16Array): Q => [- controls[idx[0] as number] as number,- controls[idx[1] as number] as number,- controls[idx[2] as number] as number,- controls[idx[3] as number] as number,- ];- const write = (joint: number, q: Q) => {- const e = quatToEuler(q, order, signs);- const o = joint * attributes + 3;- out[o] = e[0] * fromRadians;- out[o + 1] = e[1] * fromRadians;- out[o + 2] = e[2] * fromRadians;- };- for (const { swing, twist } of setups) {- let invTwist: Q = identity;- if (swing) {- const input = quat(swing.inputControlIndices);- invTwist = inverse(twistOf(input, swing.twistAxis));- const invSwing = inverse(mul(input, invTwist));- swing.outputJointIndices.forEach((joint, i) => {- write(- joint,- mul(- invTwist,- slerp(invSwing, identity, swing.blendWeights[i] as number),- ),- );- });- }- if (twist && !swing)- invTwist = twistOf(quat(twist.inputControlIndices), twist.twistAxis);- if (twist)- twist.outputJointIndices.forEach((joint, i) => {- write(- joint,- slerp(invTwist, identity, twist.blendWeights[i] as number),- );- });- }-}diff --git a/packages/dna/src/rig.test.ts b/packages/dna/src/rig.test.tsdeleted file mode 100644index 6bf6a84a..00000000--- a/packages/dna/src/rig.test.ts+++ /dev/null@@ -1,134 +0,0 @@-/**- * The rig evaluator matches Epic's RigLogic (scalar, full precision) on the- * oracle character: for 48 seeded random control sets, alternating GUI and- * raw controls and cycling the LODs, every raw control, PSD, joint- * attribute, blend shape weight and animated map equals RigLogic's- * (`fixtures/oracle-eval.json`). Evaluation is stateless: any order of- * frames gives the same outputs.- */-import { readFileSync } from "node:fs";-import { describe, expect, it } from "vitest";-import { RigEvaluator, readDna } from "./index.js";--const dna = readDna(- new Uint8Array(- readFileSync(new URL("../fixtures/oracle.dna", import.meta.url)),- ),-);-const cases: {- lod: number;- gui?: number[];- raw?: number[];- /** The arm's and forearm's rotations (raw controls 3 … 10), set after any GUI mapping. */- quats: number[];- rawControls: number[];- rbfControls: number[];- psdControls: number[];- joints: number[];- blendShapes: number[];- animatedMaps: number[];-}[] = JSON.parse(- readFileSync(- new URL("../fixtures/oracle-eval.json", import.meta.url),- "utf8",- ),-);--/**- * Equal up to float32 rounding: RigLogic works in float32, we in float64.- * Face controls, PSDs, blend shapes and maps agree to 1e-6; RBF weights and- * twist/swing angles pass through acos and atan, which amplify float32- * rounding (worst case 1.4e-5). The fixture's arm solver has two poses- * close together, so its interpolation matrix is ill-conditioned and- * RigLogic's float32 inversion lands up to 1.2e-4 from the float64 one: RBF- * controls and the joints they move get 2e-4. Every behavior change tried- * against this test (normalization, interpolation clamp, automatic radius,- * swing split, kernel, slerp direction, twist inversion) misses by far more.- */-const close = (- actual: ArrayLike<number>,- expected: number[],- tolerance = 1e-6,-) => {- expect(actual.length).toBe(expected.length);- for (let i = 0; i < expected.length; i++)- expect(- Math.abs((actual[i] as number) - (expected[i] as number)),- ).toBeLessThanOrEqual(- tolerance * Math.max(1, Math.abs(expected[i] as number)),- );-};--function run(rig: RigEvaluator, c: (typeof cases)[number]) {- rig.lod = c.lod;- if (c.gui) {- rig.guiControls.set(c.gui);- rig.mapGuiToRaw();- } else rig.inputs.set(c.raw ?? [], 0);- rig.inputs.set(c.quats, 3);- rig.calculate();-}--describe("RigEvaluator against RigLogic", () => {- it("matches every output for random GUI and raw controls at every LOD", () => {- const rig = new RigEvaluator(dna);- expect(cases.length).toBe(48);- for (const c of cases) {- run(rig, c);- const raw = rig.inputs.subarray(0, rig.rawControlNames.length);- close(raw, c.rawControls);- close(- rig.inputs.subarray(raw.length, raw.length + c.psdControls.length),- c.psdControls,- );- close(- rig.inputs.subarray(rig.inputs.length - rig.rbfControlNames.length),- c.rbfControls,- 2e-4,- );- close(rig.jointOutputs, c.joints, 2e-4);- close(rig.blendShapeOutputs, c.blendShapes);- close(rig.animatedMapOutputs, c.animatedMaps);- }- // Something moved: the fixture exercises joints, PSDs and maps.- expect(cases.some((c) => c.joints.some((v) => v !== 0))).toBe(true);- expect(cases.some((c) => c.psdControls.some((v) => v > 0))).toBe(true);- expect(cases.some((c) => c.rbfControls.some((v) => v > 0.1))).toBe(true);- });-- it("gives the same outputs in any order (seeking equals playing)", () => {- const forward = new RigEvaluator(dna);- const outputs = cases.map((c) => {- run(forward, c);- return [- ...forward.jointOutputs,- ...forward.blendShapeOutputs,- ...forward.animatedMapOutputs,- ];- });- const backward = new RigEvaluator(dna);- for (let i = cases.length - 1; i >= 0; i--) {- run(backward, cases[i]!);- expect([- ...backward.jointOutputs,- ...backward.blendShapeOutputs,- ...backward.animatedMapOutputs,- ]).toEqual(outputs[i]);- }- });-- it("sets controls by name and refuses unknown ones and LODs", () => {- const rig = new RigEvaluator(dna);- rig.setGuiControls({ CTRL_jaw: 0.5 });- rig.mapGuiToRaw();- rig.calculate();- expect(rig.inputs[0]).toBeCloseTo(0.5, 6);- expect(rig.blendShapeOutputs[0]).toBeCloseTo(0.5, 6);- expect(() => rig.setRawControls({ nope: 1 })).toThrow(- /no raw control "nope"/,- );- expect(() => {- rig.lod = 2;- }).toThrow(/LOD 2 is not in the rig/);- });-});diff --git a/packages/dna/src/rig.ts b/packages/dna/src/rig.tsdeleted file mode 100644index b19aa369..00000000--- a/packages/dna/src/rig.ts+++ /dev/null@@ -1,369 +0,0 @@-/**- * Evaluates a DNA character's rig: controls in, deformation out.- *- * - GUI controls map to raw controls through a conditional table.- * - Pose-space controls (PSDs) are products of raw controls, for- * expressions that only look right in combination.- * - Joint groups are sparse matrices from controls to joint attribute- * deltas: per joint, translation, Euler rotation (the file's units and- * order) and scale, added to the neutral pose.- * - Blend shape channel weights copy controls.- * - Animated maps (wrinkle masks) come from a second conditional table.- * - Body correctives: RBF solvers turn joint rotations (quaternions the- * host puts in raw controls) into pose weights that drive controls, and- * twist/swing spreads a joint's rotation over helper joints- * (`rig-body.ts`).- *- * Each LOD uses the first rows of every table, so lower LODs do less work.- * Evaluation keeps no state between calls: the outputs depend only on the- * controls and the LOD, so rendering frame 200 directly equals rendering- * frames 0 to 200.- *- * Based on OpenRigLogic's RigLogic (MIT, Epic Games). Its scalar,- * full-precision path is the reference; `fixtures/oracle-eval.json` holds its- * outputs.- */-import type { ConditionalTable, DnaFile } from "./read.js";-import {- applyTwistSwing,- RbfSolverRuntime,- type TwistSwingRuntime,- twistSwingSetups,-} from "./rig-body.js";--/** Attributes per joint in `jointOutputs`: tx, ty, tz, rx, ry, rz, sx, sy, sz. */-export const JOINT_ATTRIBUTES = 9;--interface Psd {- /** Control index this PSD writes. */- output: number;- weight: number;- inputs: number[];-}--/** A conditional table with, per row, how many rows of its (input, output) run follow it. */-interface Conditionals {- table: ConditionalTable;- skip: Uint16Array;-}--function conditionals(table: ConditionalTable): Conditionals {- const n = table.inputIndices.length;- const skip = new Uint16Array(n);- // Rows of one input feeding one output form a run of intervals: once one- // matches, the rest of the run is skipped.- for (let i = 0; i < n; ) {- let end = i + 1;- while (- end < n &&- table.inputIndices[end] === table.inputIndices[i] &&- table.outputIndices[end] === table.outputIndices[i]- )- end++;- for (let k = i; k < end; k++) skip[k] = end - 1 - k;- i = end;- }- return { table, skip };-}--/** Rows `0 … rows - 1` of a conditional table: each output sums its matching rows, clamped to 0 … 1. */-function forward(- c: Conditionals,- inputs: Float32Array,- outputs: Float32Array,- rows: number,-): void {- outputs.fill(0);- const t = c.table;- for (let row = 0; row < rows; row++) {- const value = inputs[t.inputIndices[row] as number] as number;- if (- (t.fromValues[row] as number) <= value &&- value <= (t.toValues[row] as number)- ) {- const out = t.outputIndices[row] as number;- outputs[out] =- (outputs[out] as number) +- (t.slopeValues[row] as number) * value +- (t.cutValues[row] as number);- row += c.skip[row] as number;- }- }- for (let i = 0; i < outputs.length; i++)- outputs[i] = Math.min(1, Math.max(0, outputs[i] as number));-}--export interface RigEvaluatorOptions {- /** Level of detail. Default 0. */- lod?: number;-}--export class RigEvaluator {- readonly guiControlNames: readonly string[];- readonly rawControlNames: readonly string[];- /** GUI control values; `mapGuiToRaw()` turns them into raw controls. */- readonly guiControls: Float32Array;- /** Raw controls, then PSD, machine-learned (not evaluated yet, 0) and RBF pose controls. */- readonly inputs: Float32Array;- /** Names of the RBF pose controls (the end of `inputs`). */- readonly rbfControlNames: readonly string[];- /** Per joint: translation, rotation, scale deltas from the neutral pose (`JOINT_ATTRIBUTES` each). */- readonly jointOutputs: Float32Array;- /** Per blend shape channel: its weight. */- readonly blendShapeOutputs: Float32Array;- /** Per animated map (wrinkle mask): its weight, 0 … 1. */- readonly animatedMapOutputs: Float32Array;-- private readonly rawCount: number;- private readonly guiToRaw: Conditionals;- private readonly animatedMaps: Conditionals;- private readonly psds: Psd[];- /** Per LOD, the PSDs (by position in `psds`) some output at that LOD uses. */- private readonly psdsForLod: number[][];- private readonly dna: DnaFile;- private readonly solvers: RbfSolverRuntime[];- /** Per pose: the controls that gate it and the controls it writes. */- private readonly poseControls: NonNullable<DnaFile["rbf"]>["poseControls"];- private readonly twistSwing: TwistSwingRuntime[];- private lodIndex = 0;-- constructor(dna: DnaFile, options: RigEvaluatorOptions = {}) {- const behavior = dna.behavior;- if (!behavior)- throw new Error("dna: the file was read without its rig behavior");- const def = dna.definition;- this.dna = dna;- this.guiControlNames = def.guiControlNames;- this.rawControlNames = def.rawControlNames;- this.rawCount = def.rawControlNames.length;- const psdCount = behavior.controls.psdCount;- const rbf = dna.rbf;- this.rbfControlNames = rbf?.poseControlNames ?? [];- this.guiControls = new Float32Array(def.guiControlNames.length);- this.inputs = new Float32Array(- this.rawCount +- psdCount +- (dna.mlControlNames?.length ?? 0) +- this.rbfControlNames.length,- );- const toRadians =- dna.descriptor.rotationUnit === "degrees" ? Math.PI / 180 : 1;- this.poseControls = rbf?.poseControls ?? [];- this.solvers = (rbf?.solvers ?? []).map(- (solver) =>- new RbfSolverRuntime(- solver,- Array.from(solver.poseIndices, (p) => rbf?.poses[p]?.scale ?? 1),- toRadians,- Array.from(solver.poseIndices).flatMap((p) =>- Array.from(this.poseControls[p]?.outputControlIndices ?? []),- ),- ),- );- this.twistSwing = twistSwingSetups(dna);- const quaternionJoints = new Set(- (dna.jointRepresentations ?? []).flatMap((r, j) =>- r.rotation === "quaternion" ? [j] : [],- ),- );- const blocked = behavior.joints.jointGroups.flatMap((g) =>- Array.from(g.jointIndices).filter((j) => quaternionJoints.has(j)),- );- if (blocked.length)- throw new Error(- `dna: joints ${blocked.map((j) => def.jointNames[j]).join(", ")} use quaternion joint groups, which are not evaluated yet`,- );- this.jointOutputs = new Float32Array(- def.jointNames.length * JOINT_ATTRIBUTES,- );- this.blendShapeOutputs = new Float32Array(- def.blendShapeChannelNames.length,- );- this.animatedMapOutputs = new Float32Array(def.animatedMapNames.length);- this.guiToRaw = conditionals(behavior.controls.conditionals);- this.animatedMaps = conditionals(behavior.animatedMaps.conditionals);-- // PSDs: every (row, column, value) of the PSD matrix with one row is one PSD.- const { rows, columns, values } = behavior.controls.psds;- const byOutput = new Map<number, Psd>();- for (let i = 0; i < rows.length; i++) {- const output = rows[i] as number;- let psd = byOutput.get(output);- if (!psd) {- psd = { output, weight: 1, inputs: [] };- byOutput.set(output, psd);- }- psd.inputs.push(columns[i] as number);- psd.weight *= values[i] as number;- }- this.psds = [...byOutput.values()].sort((a, b) => a.output - b.output);- this.psdsForLod = Array.from(- { length: dna.descriptor.lodCount },- (_, lod) => {- const used = this.controlsUsed(lod);- return this.psds.flatMap((p, i) => (used.has(p.output) ? [i] : []));- },- );- this.lod = options.lod ?? 0;- }-- get lod(): number {- return this.lodIndex;- }-- set lod(value: number) {- if (- !Number.isInteger(value) ||- value < 0 ||- value >= this.dna.descriptor.lodCount- )- throw new Error(- `dna: LOD ${value} is not in the rig (it has ${this.dna.descriptor.lodCount})`,- );- this.lodIndex = value;- }-- /** The controls any output reads at a LOD. */- private controlsUsed(lod: number): Set<number> {- const b = this.dna.behavior;- const used = new Set<number>();- if (!b) return used;- for (const g of b.joints.jointGroups) {- const rows = g.lods[lod] ?? 0;- const cols = g.inputIndices.length;- for (let c = 0; c < cols; c++)- for (let r = 0; r < rows; r++)- if ((g.values[r * cols + c] as number) !== 0) {- used.add(g.inputIndices[c] as number);- break;- }- }- const bs = b.blendShapeChannels;- for (let i = 0; i < (bs.lods[lod] ?? 0); i++)- used.add(bs.inputIndices[i] as number);- const am = b.animatedMaps;- for (let i = 0; i < (am.lods[lod] ?? 0); i++)- used.add(am.conditionals.inputIndices[i] as number);- return used;- }-- /** The LOD's RBF solvers: each clears its outputs, weighs its poses, and adds them up. */- private calculateRbf(lod: number): void {- const map = this.dna.rbf?.lodSolverMapping;- if (!map) return;- const inputs = this.inputs;- for (const index of map.indices[map.lods[lod] as number] ?? []) {- const solver = this.solvers[index] as RbfSolverRuntime;- for (const o of solver.outputs) inputs[o] = 0;- solver.solve(inputs);- solver.solver.poseIndices.forEach((pose, i) => {- const pc = this.poseControls[pose];- if (!pc) return;- let gate = 1;- for (const c of pc.inputControlIndices) gate *= inputs[c] as number;- const weight = solver.weights[i] as number;- pc.outputControlIndices.forEach((o, k) => {- inputs[o] =- (inputs[o] as number) +- (pc.outputControlWeights[k] as number) * weight * gate;- });- });- }- }-- /** Sets GUI controls by name (unnamed ones keep their values). */- setGuiControls(values: Record<string, number>): void {- this.setByName(this.guiControlNames, this.guiControls, values, "GUI");- }-- /** Sets raw controls by name (unnamed ones keep their values). */- setRawControls(values: Record<string, number>): void {- this.setByName(this.rawControlNames, this.inputs, values, "raw");- }-- private setByName(- names: readonly string[],- into: Float32Array,- values: Record<string, number>,- kind: string,- ) {- for (const [name, value] of Object.entries(values)) {- const i = names.indexOf(name);- if (i < 0) throw new Error(`dna: no ${kind} control "${name}"`);- into[i] = value;- }- }-- /** Raw controls from the GUI controls (the rest of the raw controls become 0). */- mapGuiToRaw(): void {- forward(- this.guiToRaw,- this.guiControls,- this.inputs.subarray(0, this.rawCount),- this.guiToRaw.table.inputIndices.length,- );- }-- /** Every output from the current raw controls, at the current LOD. */- calculate(): void {- const lod = this.lodIndex;- const b = this.dna.behavior as NonNullable<DnaFile["behavior"]>;- const inputs = this.inputs;-- // Everything after the raw controls is computed from them, frame by frame.- inputs.fill(0, this.rawCount);- this.calculateRbf(lod);-- // PSDs read their inputs clamped to 0 … 1, as they were before this pass.- const clamped = Float32Array.from(inputs, (v) =>- Math.min(1, Math.max(0, v)),- );- for (const i of this.psdsForLod[lod] ?? []) {- const psd = this.psds[i] as Psd;- let value = psd.weight;- for (const input of psd.inputs) value *= clamped[input] as number;- inputs[psd.output] = Math.min(1, value);- }-- const out = this.jointOutputs;- out.fill(0);- for (const g of b.joints.jointGroups) {- const rows = g.lods[lod] ?? 0;- const cols = g.inputIndices.length;- for (let r = 0; r < rows; r++) {- let sum = 0;- for (let c = 0; c < cols; c++)- sum +=- (g.values[r * cols + c] as number) *- (inputs[g.inputIndices[c] as number] as number);- const o = g.outputIndices[r] as number;- out[o] = (out[o] as number) + sum;- }- }-- const d = this.dna.descriptor;- applyTwistSwing(- this.twistSwing,- inputs,- out,- JOINT_ATTRIBUTES,- d.rotationSequence,- d.rotationSign,- d.rotationUnit === "degrees" ? 180 / Math.PI : 1,- );-- const bs = b.blendShapeChannels;- this.blendShapeOutputs.fill(0);- for (let i = 0; i < (bs.lods[lod] ?? 0); i++)- this.blendShapeOutputs[bs.outputIndices[i] as number] = inputs[- bs.inputIndices[i] as number- ] as number;-- forward(- this.animatedMaps,- inputs,- this.animatedMapOutputs,- b.animatedMaps.lods[lod] ?? 0,- );- }-}diff --git a/packages/dna/src/space.ts b/packages/dna/src/space.tsdeleted file mode 100644index bc861aaa..00000000--- a/packages/dna/src/space.ts+++ /dev/null@@ -1,104 +0,0 @@-/**- * From a DNA file's space to glTF's. A DNA descriptor names where each of- * its axes points (`right`, `up`, `front`, …) and its units; glTF is y-up,- * the character faces +z, and the viewer's right (the character's left) is- * +x. Joint rotations are Euler angles in the file's order and signs.- *- * The Euler convention follows OpenRigLogic's `tdm` (MIT, Epic Games): for- * the order `xyz`, x turns first, then y, then z (q = qz · qy · qx).- */-import { type Quat, quatMultiply, type Vec3 } from "@framefields/forge";-import type { AxisDirection, DnaDescriptor, RotationSequence } from "./read.js";--const DIRECTION: Record<AxisDirection, Vec3> = {- right: [1, 0, 0],- left: [-1, 0, 0],- up: [0, 1, 0],- down: [0, -1, 0],- front: [0, 0, 1],- back: [0, 0, -1],-};--/** A change of axes (orthonormal, maybe mirroring) and of units. */-export interface Space {- /** Columns: where the file's x, y and z go in glTF. */- axes: [Vec3, Vec3, Vec3];- /** +1, or -1 when the file is mirrored relative to glTF (left-handed). */- handedness: 1 | -1;- /** File translation units to output units. */- scale: number;- /** File rotation units to radians. */- angle: number;- sequence: RotationSequence;- sign: [number, number, number];-}--export function spaceOf(d: DnaDescriptor, units: "cm" | "m"): Space {- const axes = d.coordinateSystem.map((a) => DIRECTION[a]) as [- Vec3,- Vec3,- Vec3,- ];- const [a, b, c] = axes;- const det =- a[0] * (b[1] * c[2] - b[2] * c[1]) -- a[1] * (b[0] * c[2] - b[2] * c[0]) +- a[2] * (b[0] * c[1] - b[1] * c[0]);- if (Math.abs(det) !== 1)- throw new Error(- `dna: axes ${d.coordinateSystem.join(", ")} do not span space`,- );- const fileCm = d.translationUnit === "m" ? 100 : 1;- return {- axes,- handedness: det > 0 ? 1 : -1,- scale: units === "m" ? fileCm / 100 : fileCm,- angle: d.rotationUnit === "degrees" ? Math.PI / 180 : 1,- sequence: d.rotationSequence,- sign: d.rotationSign,- };-}--/** A file direction (normal, axis) in glTF axes. */-export function direction(s: Space, x: number, y: number, z: number): Vec3 {- const [a, b, c] = s.axes;- return [- a[0] * x + b[0] * y + c[0] * z,- a[1] * x + b[1] * y + c[1] * z,- a[2] * x + b[2] * y + c[2] * z,- ];-}--/** A file position (or offset) in glTF axes and output units. */-export function point(s: Space, x: number, y: number, z: number): Vec3 {- const d = direction(s, x, y, z);- return [d[0] * s.scale, d[1] * s.scale, d[2] * s.scale];-}--const AXIS = { x: 0, y: 1, z: 2 } as const;--/** Euler angles (file units, order and signs) as a quaternion in the file's axes. */-export function eulerQuat(s: Space, x: number, y: number, z: number): Quat {- const angles = [- x * s.sign[0] * s.angle,- y * s.sign[1] * s.angle,- z * s.sign[2] * s.angle,- ];- let q: Quat = [0, 0, 0, 1];- for (const letter of s.sequence) {- const k = AXIS[letter as keyof typeof AXIS];- const half = (angles[k] as number) / 2;- const turn: Quat = [0, 0, 0, Math.cos(half)];- turn[k] = Math.sin(half);- // Each later axis turns after the earlier ones.- q = quatMultiply(turn, q);- }- return q;-}--/** A rotation in the file's axes as one in glTF's: the same turn, about the converted axis. */-export function rotation(s: Space, q: Quat): Quat {- const v = direction(s, q[0], q[1], q[2]);- // A mirror flips which way a turn about an axis goes.- return [v[0] * s.handedness, v[1] * s.handedness, v[2] * s.handedness, q[3]];-}diff --git a/packages/dna/src/to-glb.ts b/packages/dna/src/to-glb.tsdeleted file mode 100644index c6ba2ea9..00000000--- a/packages/dna/src/to-glb.ts+++ /dev/null@@ -1,327 +0,0 @@-/**- * A DNA character as glTF: its joints at their neutral pose (with rest- * orientations), and the meshes of one LOD, skinned, with their blend shape- * targets as named morph targets. Loaded with `Layer.glb`, it then takes- * `pose`, `aim`, `lookAt`, IK and `morphs` like any character.- */-import {- GltfDocument,- type MaterialRef,- type MaterialSpec,- type MorphTargetSpec,- type NodeRef,- type Quat,- quatMultiply,- quatRotate,- Skeleton,- type SkeletonRefs,- type Vec3,-} from "@framefields/forge";-import { meshRole, roleMaterial } from "./materials.js";-import type { DnaFile, DnaMesh } from "./read.js";-import {- direction,- eulerQuat,- point,- rotation,- type Space,- spaceOf,-} from "./space.js";--export interface DnaToGltfOptions {- /** Level of detail (0 is the most detailed). Default 0. */- lod?: number;- /** Output units. Default "cm", like forge humans. */- units?: "cm" | "m";- /** Blend shape targets as morph targets. Default true. */- blendShapes?: boolean;- /**- * Skin influences kept per vertex: 8 (glTF's two sets, only written- * where a vertex has more than four) or 4. Default 8.- */- influences?: 4 | 8;- /**- * Material per mesh, by mesh name (or a function of it, like- * `dnaMaterials(…).materials`). Default: the material of the mesh's role- * (skin, teeth, eye, eye shell, lashes, …) without textures.- */- materials?:- | Record<string, MaterialSpec>- | ((mesh: string) => MaterialSpec | undefined);- /** Name of the character's root node. Default: the descriptor's name. */- name?: string;-}--export interface AddedDna {- rig: SkeletonRefs;- /** Mesh nodes by DNA mesh name. */- meshes: Map<string, NodeRef>;- materials: Map<string, MaterialRef>;-}--/** The DNA character written as a GLB. */-export function dnaToGlb(- dna: DnaFile,- options: DnaToGltfOptions = {},-): Uint8Array {- const doc = new GltfDocument();- addDna(doc, dna, options);- return doc.toGlb();-}--/** Writes the DNA character into `doc`: skeleton, then one skinned node per mesh of the LOD. */-export function addDna(- doc: GltfDocument,- dna: DnaFile,- options: DnaToGltfOptions = {},-): AddedDna {- const space = spaceOf(dna.descriptor, options.units ?? "cm");- const skeleton = dnaSkeleton(dna, space);- const rig = doc.addSkeleton(skeleton.skeleton);- const meshes = new Map<string, NodeRef>();- const materials = new Map<string, MaterialRef>();- const geometry = dna.geometry?.meshes;- if (!geometry) return { rig, meshes, materials };- for (const m of lodMeshes(dna, options.lod ?? 0)) {- const mesh = geometry[m];- if (!mesh)- throw new Error(`dna: mesh ${m} is listed for the LOD but missing`);- const name = dna.definition.meshNames[m] ?? `mesh${m}`;- // Nothing to draw (an empty placeholder mesh).- if (!mesh.layouts.positions.length || !mesh.faces.length) continue;- const material = doc.addMaterial({ name, ...materialFor(options, name) });- materials.set(name, material);- const primitive = meshPrimitive(- dna,- mesh,- space,- skeleton.order,- options.blendShapes !== false,- options.influences ?? 8,- );- meshes.set(- name,- doc.addNode({- name,- mesh: doc.addMesh({ name, primitives: [{ ...primitive, material }] }),- skin: rig.skin,- }),- );- }- return { rig, meshes, materials };-}--function materialFor(options: DnaToGltfOptions, mesh: string): MaterialSpec {- const m = options.materials;- const own = typeof m === "function" ? m(mesh) : m?.[mesh];- return own ?? roleMaterial(meshRole(mesh));-}--/** The meshes a LOD uses. */-export function lodMeshes(dna: DnaFile, lod: number): number[] {- const map = dna.definition.lodMeshMapping;- if (lod < 0 || lod >= map.lods.length)- throw new Error(- `dna: LOD ${lod} is not in the file (it has ${map.lods.length})`,- );- return Array.from(map.indices[map.lods[lod] as number] ?? []);-}--/**- * The joints at their neutral pose in glTF space, parents first. `order`- * maps a DNA joint index to its index in the skeleton (and so in the skin).- */-export function dnaSkeleton(- dna: DnaFile,- space: Space,-): { skeleton: Skeleton; order: Int32Array } {- const def = dna.definition;- const n = def.jointNames.length;- const parent = (j: number) => {- const p = def.jointHierarchy[j] as number;- return p === j || p >= n ? -1 : p;- };- // World transforms in the file's axes, parents first.- const worldRot: Quat[] = new Array(n);- const worldPos: Vec3[] = new Array(n);- const done = new Uint8Array(n);- const visit = (j: number, depth: number): void => {- if (done[j]) return;- if (depth > n) throw new Error("dna: the joint hierarchy has a cycle");- const p = parent(j);- if (p >= 0) visit(p, depth + 1);- const t = def.neutralJointTranslations;- const r = def.neutralJointRotations;- const local = eulerQuat(- space,- r.xs[j] as number,- r.ys[j] as number,- r.zs[j] as number,- );- const offset: Vec3 = [- t.xs[j] as number,- t.ys[j] as number,- t.zs[j] as number,- ];- if (p < 0) {- worldRot[j] = local;- worldPos[j] = offset;- } else {- worldRot[j] = quatMultiply(worldRot[p] as Quat, local);- const d = quatRotate(worldRot[p] as Quat, offset);- const pp = worldPos[p] as Vec3;- worldPos[j] = [pp[0] + d[0], pp[1] + d[1], pp[2] + d[2]];- }- done[j] = 1;- };- for (let j = 0; j < n; j++) visit(j, 0);-- // Parents first: a depth-first walk from the roots.- const children: number[][] = Array.from({ length: n }, () => []);- const roots: number[] = [];- for (let j = 0; j < n; j++) {- const p = parent(j);- if (p < 0) roots.push(j);- else (children[p] as number[]).push(j);- }- const skeleton = new Skeleton();- const order = new Int32Array(n).fill(-1);- let next = 0;- const stack = [...roots].reverse();- while (stack.length) {- const j = stack.pop() as number;- const p = parent(j);- const w = worldPos[j] as Vec3;- skeleton.add(def.jointNames[j] ?? `joint${j}`, {- at: point(space, w[0], w[1], w[2]),- orient: rotation(space, worldRot[j] as Quat),- ...(p < 0 ? {} : { parent: def.jointNames[p] ?? `joint${p}` }),- });- order[j] = next++;- for (const c of [...(children[j] as number[])].reverse()) stack.push(c);- }- return { skeleton, order };-}--/**- * One mesh as a glTF primitive: a vertex per layout (position, UV and- * normal indices), polygons fanned into triangles, the strongest four skin- * influences per vertex, and blend shape targets spread to every vertex- * that shares a moved position.- */-function meshPrimitive(- dna: DnaFile,- mesh: DnaMesh,- space: Space,- order: Int32Array,- blendShapes: boolean,- limit: 4 | 8,-) {- const L = mesh.layouts.positions.length;- const positions = new Float32Array(L * 3);- const normals = new Float32Array(L * 3);- const uvs = new Float32Array(L * 2);- for (let v = 0; v < L; v++) {- const p = mesh.layouts.positions[v] as number;- const t = mesh.layouts.uvs[v] as number;- const nn = mesh.layouts.normals[v] as number;- positions.set(- point(- space,- mesh.positions.xs[p] ?? 0,- mesh.positions.ys[p] ?? 0,- mesh.positions.zs[p] ?? 0,- ),- v * 3,- );- const nv = direction(- space,- mesh.normals.xs[nn] ?? 0,- mesh.normals.ys[nn] ?? 0,- mesh.normals.zs[nn] ?? 1,- );- const l = Math.hypot(nv[0], nv[1], nv[2]) || 1;- normals.set([nv[0] / l, nv[1] / l, nv[2] / l], v * 3);- // DNA UVs have v up; glTF's v runs down the image.- uvs[v * 2] = mesh.uvs.us[t] ?? 0;- uvs[v * 2 + 1] = 1 - (mesh.uvs.vs[t] ?? 0);- }-- // Mirrored axes or clockwise faces turn the winding around.- const flip =- (dna.descriptor.faceWindingOrder === "cw") !== space.handedness < 0;- const indices: number[] = [];- for (const face of mesh.faces)- for (let k = 1; k + 1 < face.length; k++) {- const a = face[0] as number;- const b = face[k] as number;- const c = face[k + 1] as number;- if (flip) indices.push(a, c, b);- else indices.push(a, b, c);- }-- // Each vertex's influences: a joint listed more than once adds up, the- // strongest `limit` stay. Eight (two glTF sets) only when some vertex has more than four.- const influences = Array.from({ length: L }, (_, v) => {- const sw = mesh.skinWeights[mesh.layouts.positions[v] as number];- const byJoint = new Map<number, number>();- sw?.weights.forEach((w, i) => {- const j = order[sw.jointIndices[i] as number] as number;- if (w > 0 && j >= 0) byJoint.set(j, (byJoint.get(j) ?? 0) + w);- });- return [...byJoint].sort((x, y) => y[1] - x[1]).slice(0, limit);- });- const size = influences.some((list) => list.length > 4) ? 8 : 4;- const joints = new Uint16Array(L * size);- const weights = new Float32Array(L * size);- influences.forEach((list, v) => {- // Unweighted: follows the first joint.- if (!list.length) weights[v * size] = 1;- const sum = list.reduce((t, [, w]) => t + w, 0) || 1;- list.forEach(([j, w], k) => {- joints[v * size + k] = j;- weights[v * size + k] = w / sum;- });- });-- const targets: MorphTargetSpec[] = [];- if (blendShapes && mesh.blendShapeTargets.length) {- // Every layout vertex that uses a position.- const users = new Map<number, number[]>();- for (let v = 0; v < L; v++) {- const p = mesh.layouts.positions[v] as number;- const list = users.get(p);- if (list) list.push(v);- else users.set(p, [v]);- }- const names = dna.definition.blendShapeChannelNames;- const seen = new Set<string>();- for (const target of mesh.blendShapeTargets) {- let name = names[target.channel] ?? `channel${target.channel}`;- // Morph target names must be unique within a mesh.- if (seen.has(name)) name = `${name}_${target.channel}`;- seen.add(name);- const deltas = new Float32Array(L * 3);- for (let i = 0; i < target.vertexIndices.length; i++) {- const d = point(- space,- target.deltas.xs[i] ?? 0,- target.deltas.ys[i] ?? 0,- target.deltas.zs[i] ?? 0,- );- for (const v of users.get(target.vertexIndices[i] as number) ?? [])- deltas.set(d, v * 3);- }- targets.push({ name, positions: deltas });- }- }- return {- positions,- normals,- uvs,- indices,- joints,- weights,- ...(targets.length ? { targets } : {}),- };-}diff --git a/packages/dna/src/write-dna.test-util.ts b/packages/dna/src/write-dna.test-util.tsdeleted file mode 100644index 51a30a9f..00000000--- a/packages/dna/src/write-dna.test-util.ts+++ /dev/null@@ -1,300 +0,0 @@-/**- * Writes small DNA files for tests, in the layout `readDna` reads (file- * versions 2.1 and 2.8). Tests only: it covers the layers the reader reads.- */-import type {- DnaBehavior,- DnaDefinition,- DnaDescriptor,- DnaMesh,- LodMapping,- Vec3Array,-} from "./read.js";--class ByteWriter {- private chunks: number[] = [];- private readonly view = new DataView(new ArrayBuffer(8));-- get offset(): number {- return this.chunks.length;- }-- private put(n: number) {- for (let i = 0; i < n; i++) this.chunks.push(this.view.getUint8(i));- }- u8(v: number) {- this.chunks.push(v & 255);- }- u16(v: number) {- this.view.setUint16(0, v);- this.put(2);- }- u32(v: number) {- this.view.setUint32(0, v >>> 0);- this.put(4);- }- i32(v: number) {- this.view.setInt32(0, v);- this.put(4);- }- f32(v: number) {- this.view.setFloat32(0, v);- this.put(4);- }- chars(s: string) {- for (const b of new TextEncoder().encode(s)) this.chunks.push(b);- }- string(s: string) {- const b = new TextEncoder().encode(s);- this.u32(b.length);- for (const x of b) this.chunks.push(x);- }- u16s(a: ArrayLike<number>) {- this.u32(a.length);- for (let i = 0; i < a.length; i++) this.u16(a[i] as number);- }- u32s(a: ArrayLike<number>) {- this.u32(a.length);- for (let i = 0; i < a.length; i++) this.u32(a[i] as number);- }- f32s(a: ArrayLike<number>) {- this.u32(a.length);- for (let i = 0; i < a.length; i++) this.f32(a[i] as number);- }- list<T>(items: readonly T[], each: (w: ByteWriter, item: T) => void) {- this.u32(items.length);- for (const item of items) each(this, item);- }- patchU32(at: number, v: number) {- this.view.setUint32(0, v >>> 0);- for (let i = 0; i < 4; i++) this.chunks[at + i] = this.view.getUint8(i);- }- bytes(): Uint8Array {- return Uint8Array.from(this.chunks);- }-}--const AXES = ["left", "right", "up", "down", "front", "back"];-const SEQUENCES = ["xyz", "xzy", "yxz", "yzx", "zxy", "zyx"];--export interface TestDna {- descriptor: DnaDescriptor;- definition: DnaDefinition;- behavior: DnaBehavior;- meshes: DnaMesh[];-}--function descriptor(w: ByteWriter, d: DnaDescriptor) {- w.string(d.name);- w.u16(d.archetype);- w.u16(d.gender);- w.u16(d.age);- w.list(d.metadata, (x, [k, v]) => {- x.string(k);- x.string(v);- });- w.u16(d.translationUnit === "m" ? 1 : 0);- w.u16(d.rotationUnit === "radians" ? 1 : 0);- for (const a of d.coordinateSystem) w.u16(AXES.indexOf(a));- w.u16(d.lodCount);- w.u16(d.maxLOD);- w.string(d.complexity);- w.string(d.dbName);-}--function descriptorExt(w: ByteWriter, d: DnaDescriptor) {- w.u32(SEQUENCES.indexOf(d.rotationSequence));- for (const s of d.rotationSign) w.i32(s);- w.u8(d.faceWindingOrder === "cw" ? 1 : 0);-}--function lodMapping(w: ByteWriter, m: LodMapping) {- w.u16s(m.lods);- w.list(m.indices, (x, row) => x.u16s(row));-}--function vec3s(w: ByteWriter, v: Vec3Array) {- w.f32s(v.xs);- w.f32s(v.ys);- w.f32s(v.zs);-}--function definition(w: ByteWriter, d: DnaDefinition) {- lodMapping(w, d.lodJointMapping);- lodMapping(w, d.lodBlendShapeMapping);- lodMapping(w, d.lodAnimatedMapMapping);- lodMapping(w, d.lodMeshMapping);- for (const names of [- d.guiControlNames,- d.rawControlNames,- d.jointNames,- d.blendShapeChannelNames,- d.animatedMapNames,- d.meshNames,- ])- w.list(names, (x, s) => x.string(s));- w.u16s(d.meshBlendShapeChannelMapping.from);- w.u16s(d.meshBlendShapeChannelMapping.to);- w.u16s(d.jointHierarchy);- vec3s(w, d.neutralJointTranslations);- vec3s(w, d.neutralJointRotations);-}--function conditional(- w: ByteWriter,- c: DnaBehavior["controls"]["conditionals"],-) {- w.u16s(c.inputIndices);- w.u16s(c.outputIndices);- w.f32s(c.fromValues);- w.f32s(c.toValues);- w.f32s(c.slopeValues);- w.f32s(c.cutValues);-}--function controls(w: ByteWriter, b: DnaBehavior) {- w.u16(b.controls.psdCount);- conditional(w, b.controls.conditionals);- w.u16s(b.controls.psds.rows);- w.u16s(b.controls.psds.columns);- w.f32s(b.controls.psds.values);-}-function joints(w: ByteWriter, b: DnaBehavior) {- w.u16(b.joints.rowCount);- w.u16(b.joints.colCount);- w.list(b.joints.jointGroups, (x, g) => {- x.u16s(g.lods);- x.u16s(g.inputIndices);- x.u16s(g.outputIndices);- x.f32s(g.values);- x.u16s(g.jointIndices);- });-}-function blendShapes(w: ByteWriter, b: DnaBehavior) {- w.u16s(b.blendShapeChannels.lods);- w.u16s(b.blendShapeChannels.inputIndices);- w.u16s(b.blendShapeChannels.outputIndices);-}-function animatedMaps(w: ByteWriter, b: DnaBehavior) {- w.u16s(b.animatedMaps.lods);- conditional(w, b.animatedMaps.conditionals);-}--function meshBody(w: ByteWriter, m: DnaMesh) {- vec3s(w, m.positions);- w.f32s(m.uvs.us);- w.f32s(m.uvs.vs);- vec3s(w, m.normals);- w.u32s(m.layouts.positions);- w.u32s(m.layouts.uvs);- w.u32s(m.layouts.normals);- w.list(m.faces, (x, f) => x.u32s(f));- w.u16(m.maximumInfluencePerVertex);- w.list(m.skinWeights, (x, s) => {- x.f32s(s.weights);- x.u16s(s.jointIndices);- });- w.list(m.blendShapeTargets, (x, t) => {- vec3s(x, t.deltas);- x.u32s(t.vertexIndices);- x.u16(t.channel);- });-}--const sid = (s: string) =>- ((s.charCodeAt(0) << 24) |- (s.charCodeAt(1) << 16) |- (s.charCodeAt(2) << 8) |- s.charCodeAt(3)) >>>- 0;--/** A 2.8 file: the layer index, then descriptor, extension, definition, behavior and geometry layers. */-export function writeDna28(dna: TestDna): Uint8Array {- const w = new ByteWriter();- w.chars("DNA");- w.u16(2);- w.u16(8);- const layers: [string, number, (x: ByteWriter) => void][] = [- ["desc", 0x10001, (x) => descriptor(x, dna.descriptor)],- ["defn", 0x10001, (x) => definition(x, dna.definition)],- [- "bhvr",- 0x10001,- (x) => {- controls(x, dna.behavior);- joints(x, dna.behavior);- blendShapes(x, dna.behavior);- animatedMaps(x, dna.behavior);- },- ],- [- "geom",- 0x10001,- (x) =>- x.list(dna.meshes, (y, m) => {- const sizeAt = y.offset;- y.u32(0);- const base = y.offset;- meshBody(y, m);- y.patchU32(sizeAt, y.offset - base);- }),- ],- // A layer the reader skips: no twists, no swings.- [- "twsw",- 0x10000,- (x) => {- x.u32(0);- x.u32(0);- },- ],- ["dsce", 0x10000, (x) => descriptorExt(x, dna.descriptor)],- ];- w.u32(layers.length);- const slots = layers.map(([id, version]) => {- w.u32(sid(id));- w.u32(version);- const at = w.offset;- w.u32(0);- w.u32(0);- return at;- });- layers.forEach(([, , body], i) => {- const start = w.offset;- body(w);- w.patchU32(slots[i] as number, start);- w.patchU32((slots[i] as number) + 4, w.offset - start);- });- return w.bytes();-}--/** A 2.1 file: the section table, then the sections, then the closing signature. */-export function writeDna21(dna: TestDna): Uint8Array {- const w = new ByteWriter();- w.chars("DNA");- w.u16(2);- w.u16(1);- const table = w.offset;- for (let i = 0; i < 8; i++) w.u32(0);- const section = (k: number, body: () => void) => {- w.patchU32(table + k * 4, w.offset);- body();- };- section(0, () => descriptor(w, dna.descriptor));- section(1, () => definition(w, dna.definition));- section(2, () => {});- section(3, () => controls(w, dna.behavior));- section(4, () => joints(w, dna.behavior));- section(5, () => blendShapes(w, dna.behavior));- section(6, () => animatedMaps(w, dna.behavior));- section(7, () =>- w.list(dna.meshes, (y, m) => {- const endAt = y.offset;- y.u32(0);- meshBody(y, m);- y.patchU32(endAt, y.offset);- }),- );- w.chars("AND");- return w.bytes();-}diff --git a/packages/dna/tsconfig.json b/packages/dna/tsconfig.jsondeleted file mode 100644index c00e3e04..00000000--- a/packages/dna/tsconfig.json+++ /dev/null@@ -1,9 +0,0 @@-{- "extends": "@framefields/tsconfig/base.json",- "compilerOptions": {- "lib": ["ES2022", "ESNext"],- "types": ["node"]- },- "include": ["src"],- "exclude": ["dist", "node_modules"]-}diff --git a/packages/dna/tsdown.config.ts b/packages/dna/tsdown.config.tsdeleted file mode 100644index 94257a01..00000000--- a/packages/dna/tsdown.config.ts+++ /dev/null@@ -1,10 +0,0 @@-import { defineConfig } from "tsdown";--export default defineConfig({- entry: ["src/index.ts"],- format: ["esm"],- dts: true,- clean: true,- sourcemap: true,- treeshake: true,-});diff --git a/packages/framefields/NOTICE.md b/packages/framefields/NOTICE.mdindex ac249ee7..ee177004 100644--- a/packages/framefields/NOTICE.md+++ b/packages/framefields/NOTICE.md@@ -16,31 +16,3 @@ Before SAM 3 weights are downloaded or run, you must accept Meta's SAM License (## Depth`comp.vision(clip, { depth: true })` and `withVision({ mode: "depth" })` estimate depth with Depth Anything V2 **Small** (onnx-community export of `depth-anything/Depth-Anything-V2-Small`), whose weights are Apache-2.0. The larger Depth Anything V2 checkpoints are licensed CC-BY-NC-4.0 and are not used.--## DNA characters (`framefields/dna`)--The DNA file reader and the conversion of DNA rigs (`packages/dna`) are a TypeScript port based on OpenRigLogic's DNA library (https://github.com/EpicGames/openriglogic, branch `5.8`), used under the MIT License below. "Epic Games", "MetaHuman", "RigLogic" and "OpenRigLogic" are trademarks of Epic Games, Inc.; framefields is not affiliated with or endorsed by Epic Games. No DNA files or characters ship with framefields: you load your own, under the terms they came with.--```-MIT License--Copyright (c) 2026 Epic Games, Inc.--Permission is hereby granted, free of charge, to any person obtaining a copy-of this software and associated documentation files (the "Software"), to deal-in the Software without restriction, including without limitation the rights-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell-copies of the Software, and to permit persons to whom the Software is-furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in-all copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN-THE SOFTWARE.-```diff --git a/packages/framefields/package.json b/packages/framefields/package.jsonindex 9099f8ff..b61d3a5d 100644--- a/packages/framefields/package.json+++ b/packages/framefields/package.json@@ -99,12 +99,6 @@"import": "./dist/forge/index.mjs","default": "./dist/forge/index.mjs"},- "./dna": {- "types": "./dist/dna/index.d.mts",- "development": "./src/dna/index.ts",- "import": "./dist/dna/index.mjs",- "default": "./dist/dna/index.mjs"- },"./sam": {"types": "./dist/sam/index.d.mts","development": "./src/sam/index.ts",@@ -210,7 +204,6 @@"@framefields/node-vision": "workspace:*","@framefields/renderer": "workspace:*","@framefields/renderers": "workspace:*",- "@framefields/dna": "workspace:*","@framefields/forge": "workspace:*","@framefields/storage": "workspace:*","@framefields/tensor-webgpu": "workspace:*",diff --git a/packages/framefields/src/dna/index.ts b/packages/framefields/src/dna/index.tsdeleted file mode 100644index 292ec48d..00000000--- a/packages/framefields/src/dna/index.ts+++ /dev/null@@ -1,6 +0,0 @@-/**- * `framefields/dna`: characters from DNA files (the rig format MetaHuman- * characters export to), read and written as GLB files for `Layer.glb`.- * Based on OpenRigLogic's DNA library (MIT, Epic Games); see NOTICE.md.- */-export * from "@framefields/dna";diff --git a/packages/framefields/tsdown.config.ts b/packages/framefields/tsdown.config.tsindex 738a3902..80c81daf 100644--- a/packages/framefields/tsdown.config.ts+++ b/packages/framefields/tsdown.config.ts@@ -18,7 +18,6 @@ export default defineConfig({"src/cloud/index.ts","src/storage/index.ts","src/forge/index.ts",- "src/dna/index.ts","src/cli.ts","src/cli/check-worker.ts","src/cli/local-worker.ts",diff --git a/plugins/framefields/skills/framefields-compose/SKILL.md b/plugins/framefields/skills/framefields-compose/SKILL.mdindex ae68a582..34e68cd8 100644--- a/plugins/framefields/skills/framefields-compose/SKILL.md+++ b/plugins/framefields/skills/framefields-compose/SKILL.md@@ -480,20 +480,6 @@ Layer.glb("rig.glb", { rotateX: 180, pose: { LeftArm: { rotateZ: 90 } } });Layer.glb("head.glb", { morphs: { jawOpen: [[0, 0], [12, 0.6]], mouthSmileLeft: 0.8, eyeBlinkLeft: blink } });```-**DNA characters (`framefields/dna`)**: `readDna(bytes, { geometry?, behavior? })` reads a DNA file, the rig format MetaHuman characters export to (Export > DCC Export writes one for the head and one for the body). It returns the descriptor (units, axes, LOD count), the definition (controls, joints and their neutral pose, blend shape channels, meshes per LOD), the rig behavior, and the meshes. File versions 2.1 to 2.8 are read. `dnaToGlb(dna, { lod, units, blendShapes, materials })` writes it as a GLB:-- joints at their neutral pose, with rest orientations;-- the LOD's meshes, skinned, with blend shapes as named morph targets;-- axes and units converted to glTF and centimeters.--Skins keep up to eight influences per vertex (glTF's `JOINTS_1` / `WEIGHTS_1`, written only where a vertex has more than four; `influences: 4` caps them). Each mesh gets the material of its role, found from its name (skin, teeth, saliva, eye, the clear eye shell, eye edge, lashes, cartilage). `await dnaMaterials(doc, folder)` adds the export's textures by the role and map words in their file names (`head_color…`, `…normal…`, `…roughness…`, `…cavity…`) and returns `{ found, unused, materials }`; pass `materials` to `addDna`. The export's real file names are unconfirmed, so check `found`. `addDna(doc, dna, options)` writes into your own `GltfDocument`. Load the result with `Layer.glb`; `pose`, `aim`, `lookAt`, IK and `morphs` by channel name work on it. `new RigEvaluator(dna, { lod })` evaluates the rig: set `setGuiControls({ CTRL_expressions_jawOpen: 0.6 })` then `mapGuiToRaw()`, or `setRawControls(…)`; `calculate()` fills `jointOutputs` (per joint: translation, Euler rotation and scale deltas from the neutral pose, `JOINT_ATTRIBUTES` = 9 each), `blendShapeOutputs` (per channel) and `animatedMapOutputs` (wrinkle masks, 0 … 1). Body correctives run too: put each driving joint's rotation (a unit quaternion, in the file's axes) into its four raw controls after any GUI mapping, and RBF solvers turn them into pose controls (`rbfControlNames`, at the end of `inputs`) while twist/swing writes helper joints' rotations. It matches Epic's RigLogic (to float32 rounding) and keeps no state between frames. Quaternion joint groups and machine-learned behavior are not evaluated yet (a file that needs quaternion groups is refused). Layers do not run the evaluator yet. No DNA files ship with framefields; the reader is based on OpenRigLogic (MIT, Epic Games). Joints with rest orientations also work in forge: `skeleton.add(name, { at, parent, orient })`.--```ts-import { readFile, writeFile } from "node:fs/promises";-import { dnaToGlb, readDna } from "framefields/dna";-const head = readDna(await readFile("head.dna"));-await writeFile("head.glb", dnaToGlb(head, { lod: 0, materials: { head_lod0_mesh: { color: "#c99a82", roughness: 0.5, subsurface: 0.7 } } }));-```-**Sculpting skinned bodies (`sculpt`)**: a character's body is an ordered list of parts, each an SDF shape (`sphere`, `ellipsoid`, `box`, `cylinder`, `capsule`, `roundCone`, `tube` through points, `torus`, `lathe` profile) with `at`, `rotation`, `op` (`union` / `subtract` / `intersect`), `blend` (smooth join radius), `twist`, `bend`, `displace` (noise detail), `material`, `color`, and the `joint` (or joints) that moves it (default: the nearest bone). `sculpt({ parts, skeleton, cell, triangles })` meshes it closed and manifold at hero resolution, simplifies to the triangle budget, cuts material borders on smooth curves, takes normals and blended colors from the field, and skins every vertex from the parts that reach it (smooth joins share weights, `rigid: true` parts move with one joint), returning one primitive per material plus a report (`openEdges` is 0 for a closed mesh). `limb(skeleton, "LeftForeArm", { radii: [4, 3], blend: 3 })` puts a round cone along a bone; `mirrorParts(leftParts)` adds the right side.```tsdiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex e697c74a..c125bbcd 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2908,34 +2908,6 @@ importers:specifier: ^4.1.11version: 4.1.11(@opentelemetry/[email protected])(@types/[email protected])(@vitest/[email protected])([email protected](@noble/[email protected])([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))- packages/dna:- dependencies:- '@framefields/forge':- specifier: workspace:*- version: link:../forge- devDependencies:- '@framefields/tsconfig':- specifier: workspace:*- version: link:../tsconfig- '@framefields/webgpu-renderers':- specifier: workspace:*- version: link:../webgpu-renderers- '@types/node':- specifier: ^24.1.0- version: 24.10.14- gltf-validator:- specifier: 2.0.0-dev.3.10- version: 2.0.0-dev.3.10- tsdown:- specifier: ^0.19.0- version: 0.19.0([email protected])([email protected])- typescript:- specifier: ^5.8.3- version: 5.9.3- vitest:- specifier: ^4.1.11- version: 4.1.11(@opentelemetry/[email protected])(@types/[email protected])(@vitest/[email protected])([email protected](@noble/[email protected])([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))-packages/forge:devDependencies:'@framefields/tsconfig':@@ -3056,9 +3028,6 @@ importers:'@framefields/core':specifier: workspace:*version: link:../core- '@framefields/dna':- specifier: workspace:*- version: link:../dna'@framefields/forge':specifier: workspace:*version: link:../forgediff --git a/specs/character-forge.md b/specs/character-forge.mdindex 987f8e3e..1b1e58e8 100644--- a/specs/character-forge.md+++ b/specs/character-forge.md@@ -1,8 +1,8 @@# Character Forge: rigged characters built in code-Status (2026-11-05): `human()` and the MakeHuman assets were removed; realistic humans now come from DNA files (`specs/dna-face-rig.md`). The forge keeps the GLB writer, skeletons, `sculpt`, `subdivide` and the engine work below (glass eyes, drivers, `morphs`, sparse morphs, texture transforms). The MakeHuman notes below are history.+Status (2026-11-05): `human()` and the MakeHuman assets were removed, and realistic human building is shelved (the DNA reader and RigLogic port were removed too; they are in git history at commit 8d124af5). The forge keeps the GLB writer, skeletons, `sculpt`, `subdivide` and the engine work below (glass eyes, drivers, `morphs`, sparse morphs, texture transforms). The MakeHuman notes below are history.-Earlier status: Phases 1–2 done (GLB writer, skeleton, humanoid preset, bone gizmo; bound sculpting, manifold narrow-band meshing, simplification, smooth material borders, skin weights from the field; `packages/forge`, exposed as `framefields/forge`). Sharp-edge preservation for hard surfaces moves to Phase 7's hard-surface work. Human bodies and faces now start from MakeHuman's CC0 base (`human()`): realistic anatomy, edge loops and UVs, macro and feature targets, painted weights. `sculpt` stays for stylization, costume, armor and non-humans. The face rig (Phase 4) builds on MakeHuman's expression units and the ARKit 52 names. Phase 3 in progress: the loader reads clearcoat, sheen, anisotropy and iridescence and forge's `extras.framefields.subsurface`, the compositor uses them under layer overrides, and the subsurface lobe was rewritten to conserve energy (per-channel wrap). Eyes (first step of Phase 5): `human()` returns MakeHuman's eyeballs fitted to the shaped head (proxy binding), skinned to Mixamo `LeftEye` / `RightEye` pivoted at each ball's least-squares sphere center, plus the CC0 iris texture; a clear coat gives the wet highlight. Corneas are back as glass: glass now refracts the 3D scene behind it (a pre-pass of the batch without glass), and glTF transmission + IOR + volume thickness map to glass whose bend follows the refracted ray through that depth, so the iris shifts with the viewing angle. Lids follow the gaze through joint drivers (`drive`, carried in the GLB), and `addHuman` writes the whole character. Face (Phase 4): ARKit-named blend shapes from MakeHuman's expression units (symmetric ones split into sides with a soft seam), a teeth-and-tongue `mouth` part that moves with the jaw and lips, per-layer `morphs` by name, Loop subdivision that carries shapes and weights exactly, and sparse morph accessors (2 MB per face-rigged body). Skin look development: `skinTextures` bakes the color (blush, lips, mottling) and roughness into the body's UVs from regions found through the blend shapes, plus a tiling pore and crease normal map; `addHuman` uses them by default, and the writer generates tangents and writes texture transforms. Still to do in Phase 4: sculpted teeth to replace MakeHuman's helper blocks, a darkened mouth cavity, wrinkle maps driven by expression weights. Maps now sample with their own glTF samplers (DNA plan, Phase 1). Still to do in Phase 3: alpha-to-coverage for hair cards and morphs combined with skinning; the specular, IOR, transmission and volume extensions are written but not yet rendered. First character: **Ithrael Sunmourn** (`examples/36_emberwake/CHARACTERS.md`), an original hooded elven ranger with a long cloak, long hair, a sculpted face, real eyes, and a full set of expressions.+Earlier status: Phases 1–2 done (GLB writer, skeleton, humanoid preset, bone gizmo; bound sculpting, manifold narrow-band meshing, simplification, smooth material borders, skin weights from the field; `packages/forge`, exposed as `framefields/forge`). Sharp-edge preservation for hard surfaces moves to Phase 7's hard-surface work. Human bodies and faces now start from MakeHuman's CC0 base (`human()`): realistic anatomy, edge loops and UVs, macro and feature targets, painted weights. `sculpt` stays for stylization, costume, armor and non-humans. The face rig (Phase 4) builds on MakeHuman's expression units and the ARKit 52 names. Phase 3 in progress: the loader reads clearcoat, sheen, anisotropy and iridescence and forge's `extras.framefields.subsurface`, the compositor uses them under layer overrides, and the subsurface lobe was rewritten to conserve energy (per-channel wrap). Eyes (first step of Phase 5): `human()` returns MakeHuman's eyeballs fitted to the shaped head (proxy binding), skinned to Mixamo `LeftEye` / `RightEye` pivoted at each ball's least-squares sphere center, plus the CC0 iris texture; a clear coat gives the wet highlight. Corneas are back as glass: glass now refracts the 3D scene behind it (a pre-pass of the batch without glass), and glTF transmission + IOR + volume thickness map to glass whose bend follows the refracted ray through that depth, so the iris shifts with the viewing angle. Lids follow the gaze through joint drivers (`drive`, carried in the GLB), and `addHuman` writes the whole character. Face (Phase 4): ARKit-named blend shapes from MakeHuman's expression units (symmetric ones split into sides with a soft seam), a teeth-and-tongue `mouth` part that moves with the jaw and lips, per-layer `morphs` by name, Loop subdivision that carries shapes and weights exactly, and sparse morph accessors (2 MB per face-rigged body). Skin look development: `skinTextures` bakes the color (blush, lips, mottling) and roughness into the body's UVs from regions found through the blend shapes, plus a tiling pore and crease normal map; `addHuman` uses them by default, and the writer generates tangents and writes texture transforms. Still to do in Phase 4: sculpted teeth to replace MakeHuman's helper blocks, a darkened mouth cavity, wrinkle maps driven by expression weights. Maps now sample with their own glTF samplers. Still to do in Phase 3: alpha-to-coverage for hair cards and morphs combined with skinning; the specular, IOR, transmission and volume extensions are written but not yet rendered. First character: **Ithrael Sunmourn** (`examples/36_emberwake/CHARACTERS.md`), an original hooded elven ranger with a long cloak, long hair, a sculpted face, real eyes, and a full set of expressions.## Goaldiff --git a/specs/dna-face-rig.md b/specs/dna-face-rig.mddeleted file mode 100644index 749938ef..00000000--- a/specs/dna-face-rig.md+++ /dev/null@@ -1,144 +0,0 @@-# DNA characters: MetaHuman-compatible faces and bodies--Status: Phases 1–2 done, plus the engine gaps they found.-- **Phase 1:** each material map samples with its own glTF sampler.-- **Phase 2:** `packages/dna` (`framefields/dna`) reads DNA files (2.1 to 2.8: descriptor and its extension, definition, behavior, geometry; other layers are listed and skipped). `dnaToGlb` / `addDna` write the neutral pose with rest orientations (the forge skeleton gained `orient`), a LOD's meshes, skin weights (duplicate joint entries merged) and blend shapes as named morph targets.-- **Parity with Epic's library:** `packages/dna/fixtures/oracle.cpp` builds against OpenRigLogic 5.8 (commit `d3d329bb`). `oracle.dna` is made-up data written by Epic's writer, and each fixture's `.json` is what Epic's reader reads. `readDna` matches it field for field for 2.8 and 2.1 files. Epic's reader also reads our test writer's files identically.-- **Engine gaps, closed:**- - **Sparse morphs:** the loader keeps sparse morph targets sparse (`MorphTarget3D.indices`), and the GPU pass gathers deltas per vertex from entries that exist (memory follows the deltas, no atomics).- - **Eight influences:** skins take up to eight influences per vertex (`JOINTS_1` / `WEIGHTS_1` through writer, loader and shader; a second vertex slot, flagged).- - **Materials:** DNA meshes get role materials, and `dnaMaterials` scans an export folder for textures.--Still open:-- The export's real texture file names (the scan's patterns are guesses until a real export is read).-- The rig evaluator (Phase 3).--## Goal--Load a character exported from MetaHuman Creator (Export > DCC Export: a head DNA file, a body DNA file and textures) into a composition, and animate it with the same rig evaluation Unreal Engine uses: face controls drive joints, corrective blend shapes and wrinkle-map weights. The character then animates with the same tracks as forge humans: `morphs` (ARKit names), `pose`, `aim`, `lookAt`, IK and retargeting from vision.--DNA characters are the only realistic-human path: `human()` and MakeHuman were removed (2026-11-05) because their rendering and motion fell short. Characters come from MetaHuman Creator exports and render with our own shaders. The forge stays for skeletons, sculpted props, costumes and non-humans.--## Source and terms--- [OpenRigLogic](https://github.com/EpicGames/openriglogic) (Epic Games, MIT): the DNA library (read and write DNA files) and RigLogic (rig evaluation), C++ with Python bindings. Branch `5.8` is the stable one; `main` is experimental. We pin a `5.8` commit.-- **Code:** we port what we need to TypeScript under MIT. The copyright and license text go into `packages/framefields/NOTICE.md`, and the ported files name their source.-- **Names:** under the repository's `TRADEMARKS.md`, the MIT license covers code, not names. We may say the code is based on OpenRigLogic, and that a feature reads MetaHuman DNA files. No API, package or feature is named after MetaHuman, RigLogic or OpenRigLogic.-- **Characters:** none ship. DNA files and textures come from the user's own MetaHuman export, under Epic's MetaHuman terms. Sample DNA from Fab is under the Fab Standard License: use it locally for testing, never commit it. Before release, read the current MetaHuman license on using exported characters outside Unreal Engine and quote it in the docs (open question 1).-- **Downloads:** cloning OpenRigLogic, and building it locally as a test oracle, needs the user's go-ahead like any download.--## Why a TypeScript port, not native bindings or WebAssembly--- The engine has no native addons outside Dawn, and the forge is pure TypeScript. A port keeps it that way, and runs wherever the renderer runs (CLI, preview, render service).-- The evaluation is small in essence: a sparse matrix-vector product per output kind, plus pose-space products, conditional tables, RBF and twist/swing. The C++ size (`src/riglogic` about 740 KB, `src/dna` about 400 KB) is mostly SIMD variants (block-4 and block-8 layouts, quaternion and Euler paths), builders, writers and the machine-learned behavior. One scalar reference evaluator in TypeScript covers the behavior.-- Its matrix form maps to a WebGPU compute pass later, like the morph pipeline.-- **Fallback:** if the port stalls on format breadth, compile the C++ to WebAssembly with Emscripten and load it as a lazy chunk, like the vision models.--## Design--### Package--`packages/dna` (private, Apache-2.0 plus the MIT notice for the ported parts), bundled into `framefields` as a lazy chunk and exposed as `framefields/dna`. It has no GPU code. The compositor imports it dynamically only when a layer uses a DNA character.--### 1. DNA reader--- Reads the binary format through its layers:- - header and descriptor: name, archetype, gender, age, coordinate system, units, LOD count;- - definition: control, joint, blend shape, animated map and mesh names; joint hierarchy; neutral joint transforms; LOD mappings;- - behavior: GUI-to-raw control map, PSDs, joint matrices per joint group, blend shape channel mapping, animated-map conditional tables;- - geometry: mesh vertices, normals, UVs, faces, skin weights, blend shape target deltas;- - extension layers as they appear: twist/swing, RBF, joint behavior metadata, machine-learned behavior.-- Reads only what is asked: layer filter (behavior only, or with geometry), LOD selection (load LOD 0, or LOD 3 for wide shots). A head with every LOD is large; with one LOD it stays reasonable.-- Checks versions and fails with a clear message on a DNA version it does not know.--### 2. DNA to model--- `dnaToGlb(head, body?, { lod, textures })` in the forge writes a GLB through `GltfDocument`: meshes, skins, blend shapes as named morph targets (sparse), joint hierarchy with neutral transforms, materials from the export's textures (skin, eyes, teeth, eyelashes), and the rig behavior attached as data.-- The coordinate system and units are converted from the descriptor to glTF's (meters or centimeters, y-up).-- Going through the GLB means the existing loader, skinning, morphs, materials, `pose`, `lookAt` and retargeting all work unchanged. The rig evaluator is the only new runtime piece.-- The behavior data (several MB) is stored in the GLB as a buffer view named in the scene's `extras.framefields.rig`, so the file is self-contained. Alternative: keep the `.dna` next to the GLB and reference it (open question 3).--### 3. Rig evaluator--A scalar port with RigLogic's semantics, outputs matched to the C++ within 1e-5:--1. **Controls:** GUI controls → raw controls (clamped ranges); the user sets either.-2. **PSD:** pose-space inputs appended from products of raw controls.-3. **Joints:** per joint group, a sparse matrix times the input vector gives joint deltas (translation, rotation, scale) from the neutral pose, truncated by LOD.-4. **Blend shapes:** a linear map from inputs to blend shape channel weights.-5. **Animated maps:** conditional tables (piecewise slope-intercept) give wrinkle-mask multipliers.-6. **Twist/swing and RBF** (mostly body): RBF poses solved from joint rotations drive correctives. These fix the shoulder and elbow collapse that plain linear blend skinning shows.-7. **Machine-learned behavior:** read, and evaluated last (open question 4).--API: `const rig = new RigEvaluator(reader, { lod })`, then `rig.evaluate(controls)` returns `{ joints, blendShapes, animatedMaps }` into reusable typed arrays, with no allocation per frame.--### 4. Engine wiring--- `Layer.glb(file, { face: { controls: { "CTRL_expressions_jawOpen": track, … } } })`: when the GLB carries rig behavior, the compositor evaluates it each frame.- - Joint deltas compose onto the neutral pose before `pose`.- - Blend shape weights merge with `morphs`: a named `morphs` track overrides.- - Animated map weights go to the material.-- Order: clips → face rig → `pose` → `aim` → `lookAt` → `drive` → IK → springs.-- `morphs` with ARKit names on a DNA character go through a mapping table (ARKit 52 → face controls), so the same tracks animate a forge human or a DNA character. Face tracking from video later drives both.-- Cost: a head has hundreds of joints and thousands of matrix entries. Scalar evaluation on the CPU should take well under a millisecond per frame. It moves to the GPU only if profiling says so.--### 5. Wrinkle maps (renderer)--- A material can carry wrinkle layers: extra normal (and optionally color) maps, plus mask textures whose channels each select a face region. The animated map weights, per region, blend the wrinkle normals in.-- Written as `extras.framefields.wrinkles` on the material (maps, masks and channel → animated-map name), read by the loader, applied in `mesh3d.ts`.-- Builds on **per-map samplers** (Phase 1, done): every map samples with its own wrap and filter.-- The forge human gains wrinkle maps too: bake wrinkle normals for the forehead, eye corners, nasolabial fold and brow furrow from where each expression shape compresses the skin, with masks driven by the ARKit weights. A separate step after the DNA work, using the same renderer feature.--### 6. Body DNA and retargeting--- Body joints come with Unreal's mannequin names (`pelvis`, `spine_01`, `clavicle_l`, `upperarm_l`, …). Add an `"unreal"` preset to `retarget({ rig })`, and joint aliases so `pose` with Mixamo names reaches the right bones.-- Head and body join at the neck: the head's skeleton is a subtree of the body's. `dnaToGlb(head, body)` merges them into one skeleton.--## Verification--- **Oracle:** OpenRigLogic 5.8 built under `scratch/` with a small C++ program (`packages/dna/fixtures/oracle.cpp`; no Python bindings needed). Done for reading; extended to evaluation in Phase 3.-- **Committed fixture:** a small synthetic DNA file written with the C++ writer from data we make up (a few joints, controls, PSDs, blend shapes, a conditional table, one tiny mesh). It contains no MetaHuman content, so it can be committed. A script regenerates it.-- **Parity tests:**- - the reader against the oracle on every layer of the fixture;- - evaluator outputs against the oracle for random controls (fixed seed), within 1e-5.-- **Real character smoke test:** the user's own export (or Fab sample content) loaded locally:- - the GLB passes the Khronos validator;- - rendered frames of a neutral face, then jawOpen, smile, blink and brow raise, with wrinkles on and off;- - the timings recorded.-- Skipped in CI when no export is present.--## Phases--1. Per-map samplers in the renderer. **Done.**-2. DNA reader and `dnaToGlb`. **Done**, with reader parity against Epic's library, sparse morphs, eight influences and role materials.-3. Rig evaluator, body first:- - **3a. Shared core. Done.** `RigEvaluator` (`packages/dna/src/rig.ts`) covers GUI → raw controls, PSDs, joint matrices per group and LOD, blend shapes and animated maps.- - **Parity:** RigLogic's scalar, full-precision outputs on the oracle character (`oracle eval`, 48 seeded cases across GUI/raw controls and both LODs) match to float precision. Mutation checks confirm the fixture catches interval skipping, PSD clamping and the PSD cap.- - **One deliberate difference:** PSDs a LOD does not use are 0 rather than last frame's value, so evaluation is stateless.- - **Still open:** composing deltas onto the neutral pose. Translation and scale add; the rotation delta applies in the joint's oriented frame (Maya's joint-orient convention). That needs a real export to confirm.- - **3b. Body correctives. Evaluation done; wiring and the render milestone open.**- - **RBF and twist/swing:** `rig-body.ts` adds RBF solvers (additive and interpolative; Euclidean, quaternion, swing-angle and twist-angle distances; Gaussian, exponential, linear, cubic and quintic kernels; automatic radius; normalization, pose scales, thresholds, gating) and twist/swing (tdm's slerp and quaternion-to-Euler, including its polynomial asin). The reader adds the `rbfb`, `rbfe`, `twsw`, `jbmd` and `mlbh` (names only) layers.- - **Parity:** the oracle character has five solvers covering every method and kernel, plus a twist and a swing. Outputs match RigLogic to float32 rounding (1e-6 for face parts; 2e-4 where an ill-conditioned interpolation matrix amplifies RigLogic's float32 inversion).- - **Mutation checks:** sixteen behaviour changes are caught.- - **Not evaluated yet:** quaternion joint groups (files needing them are refused) and machine-learned behavior.- - **Still open:** feeding the skeleton's joint quaternions into raw controls inside layers, and the shoulder raise and elbow bend milestone on a real exported body.- - **3c. Face:** face controls drive joints and correctives; ARKit names map to face controls so `morphs` keeps working.-4. Animated maps and wrinkle maps in the renderer.-5. Head and body as one character: the head's skeleton joined to the body's at the neck, with no gap and no double neck motion; the `"unreal"` retarget preset.-6. Machine-learned behavior, if present in exports and worth it.-7. Docs: the skill, NOTICE, changesets, an example film shot with a DNA character, and the license wording from open question 1.--Tests every phase keeps:-- **Seeking matches playing:** rendering frame 200 directly gives the same pixels and rig outputs as rendering 0 through 200. The evaluator keeps no state between frames.-- **LOD switching:** each LOD loads and evaluates; switching LOD mid-shot keeps the pose.-- **Several characters:** two instances of one character and two different characters in one scene evaluate independently.-- **Memory:** rig data and GPU buffers are released when a character leaves the scene; repeated renders do not grow memory.--## Open questions--1. What does the current MetaHuman license allow for exported characters rendered outside Unreal Engine, in our CLI, our render service and users' outputs? The docs must state it accurately before release.-2. Is there a MetaHuman export available for testing (UE 5.8 with MetaHuman Creator)? If not, Fab's sample content works for local testing.-3. Store the rig behavior inside the GLB, or keep the `.dna` next to it?-4. Do current exports use the machine-learned behavior layer, and does the face need it to look right?-5. Grooms (hair, brows, lashes) are not in the export. Eyelash and eyebrow cards come with the head mesh; hair needs the forge's planned hair cards.