import { Document, Node, type Skin } from '@gltf-transform/core'; import type { BoneMap } from './retarget'; export interface SkelNodeDef { name: string; /** local rest transform, column-major 16 */ local: number[]; parent: string | null; } export interface CanonicalSkeleton { /** every node in the skeleton subtree (joints + structural, e.g. metacarpals), DFS order */ nodes: SkelNodeDef[]; /** the 68 skin joints, in skin joint order */ jointNames: string[]; /** world rest transform per node, accumulated from the skeleton root (root parent = identity) */ worldByName: Map; skeletonRootName: string; /** * World transform of the wrapper the HOST hoists above its skeleton root (Base Female's `root_offset`, * (0, -0.0331, -0.0049) m), when `extractCanonicalSkeleton` was asked to `hoistRootOffset`. `nodes` and * `worldByName` stay offset-free (the repose maths and the source frame are unchanged); the conform * rebuild re-creates the wrapper and bakes it into the inverse-bind matrices, so the part's skeleton is * the host's own skeleton in the host's frame. Absent when the host has no wrapper (Base Male). */ rootOffset?: number[]; } /** * The transform glTF skinning actually applies to a skin's vertices at rest: `jointWorld · IBM`. * In a rig exported at its bind pose every joint yields the same matrix, and that matrix — not the * skinned mesh node's own transform, which the glTF spec says is ignored — places the vertices in the * joints' world. Returns null when the joints disagree (a posed or inconsistent bind), where there is * no single answer to read. */ export declare function skinBindTransform(skin: Skin): number[] | null; /** * Reads the canonical helix-humanoid@1 rest skeleton out of a shipped body GLB (body-m-default): the * full bone subtree (local rest transforms + hierarchy) and the skin's joint order. World transforms * are recomputed from the skeleton root down (independent of the source file's mesh-node ancestor), * so a rebuilt copy with the root at scene identity reproduces them exactly. A host-aligned add-on * can opt into the root's world transform to retain a base avatar's hoisted root_offset wrapper. */ export declare function extractCanonicalSkeleton(document: Document, options?: { includeRootWorld?: boolean; hoistRootOffset?: boolean; }): CanonicalSkeleton; export interface ConformResult { mode: 'embed' | 'repose' | 'preserve'; /** Uniform scale baked onto the source joint worlds before fitting (1 = rig already matched the mesh's units; 0.01 = cm rig snapped to a meter mesh). */ unitScale: number; /** 'embed' only: mapped bones whose rest orientation was re-aimed onto the source's segment direction (0 in 'repose'). */ restAimed: number; verticesProcessed: number; jointsRebuilt: number; /** Source joints kept as auxiliary joints, in skin order after the canonical set. */ auxiliaryJoints: string[]; /** warrior joint name -> helix joint that received its weights (via map, or nearest mapped ancestor) */ weightTargets: Record; } export interface ConformOptions { /** * 'embed' (default): keep the source mesh EXACTLY (no distortion), embed the canonical skeleton at the * source's own joint positions with canonical orientations. 'repose': re-pose the mesh onto the * canonical rest via frame-based deltas (mesh conforms to canonical proportions — use only when a rig * with canonical proportions is wanted over preserving the source character's silhouette). * 'preserve': keep source vertices in the exact host mesh space while rebinding to the host rig; * require matching mapped anatomical anchors before accepting that claim. */ mode?: 'embed' | 'repose' | 'preserve'; /** Selected source joints captured before retargetSkeleton gives several helpers one canonical name. */ anatomicalAnchorJoints?: ReadonlyMap; /** * Keep the source's UNMAPPED joints — hair, ears, tail, skirt, accessory chains — as auxiliary joints * instead of collapsing their weights onto the nearest canonical ancestor. * * Conforming an avatar that HAS secondary motion is what destroys it otherwise: every hair joint resolves * to `head` and a nineteen-link chain becomes one rigid lump. The spring configuration still points at the * source names, so keeping the joints is what keeps the physics. * * 'embed' ONLY, and the restriction is structural rather than laziness: 'embed' leaves the mesh untouched * and merely fits the canonical skeleton to the source's joint positions, so an auxiliary joint's world * rest transform is still correct in the output space and its skin weights still mean what they meant. * 'repose' moves the vertices, so an auxiliary joint would need the same frame delta applied — solvable, * but it needs its own evidence pass before anyone relies on it. */ preserveAuxiliary?: boolean; } /** * Retargets a source character onto `helix-humanoid@1` so the PLATFORM's shared clips drive it. * * 'embed' (default, the better retarget): the source mesh is left byte-for-byte unchanged and the * canonical 68-bone skeleton is fitted INTO it (segment-aimed canonical orientations at the source's * joint positions, §fitSkeletonToWarrior). Clips — authored as local rotations relative to the canonical * rest — produce the correct WORLD-space motion regardless of the source's bone-axis convention or bind * pose, because the aimed rests subtract the source-bind-vs-canonical direction delta at the IBM. Output * IBMs = inverse(fitted world), so LBS at rest reproduces the pristine source bind pose. * * 'repose' re-poses the mesh onto the canonical rest via frame-based rest-pose correction (kept for * cases wanting canonical proportions); it reshapes the mesh and is not the default. * * Source joints with no map entry fold onto their nearest mapped ancestor. */ export declare function conformToHelixRest(warrior: Document, canon: CanonicalSkeleton, boneMap: BoneMap, opts?: ConformOptions): ConformResult;