import type { Document } from '@gltf-transform/core'; import { type SkinModel } from './armBindSkin'; import type { CanonicalSkeleton } from './conform'; /** * REST POSE AND GROUND — the parts of a generated rig's rest that are not the arms (armBind.ts) and not cloth. * * Three defects, all measured on generated avatars (coordinator/avatar-quality/bind-ground/), all in the rig, none in the mesh: * * 1. JOINTS (`avatar.bind_pose`). An auto-rigger puts the joints of a limb it cannot see (a gown hides the legs) anywhere: the * ball ahead-and-below the foot by 94 deg, the foot 53 deg off the calf, the clavicle 47 deg off the shoulder. The hosted gate reads * the direction between neighbouring joints against Base Female's. A joint that is further off than a rigger's ordinary error * (`legTriggerDeg` / `clavicleTriggerDeg`, well inside the gate's limits) is moved onto the standard direction at the source's * own segment length: the foot, calf and ball come DOWN the leg, the clavicle comes back along the shoulder. Only the joint's * pivot moves; the mesh and its weights are untouched and the rest still renders pristine (IBM = inverse of the new rest). * Two guards keep the repair from creating a disagreement the rig did not have (the hosted skeleton check reads the line between each * left joint and its right twin): a joint is moved on both sides of the body when either side is past its trigger, and a clavicle * takes its length from the shoulder-width part of the observed segment and never crosses the body's midline. * * 2. REST ROTATIONS (`defect.posture`, the walk's sinking and twisting). `conform` aims every mapped bone's rest along the SOURCE * segment, but the engine copies a clip's local rotations verbatim, so the mesh is moved by `clip · inverse(aimed rest)`: a * pelvis/spine aimed 14 deg off the canonical one leans every walk by that much more than Base Female, and a thigh/calf aimed * 30/51 deg off swings the leg mesh through the floor. A chain whose rest is further than `restTriggerDeg` / `legRestTriggerDeg` from the canonical rest * (spine, each leg) takes the canonical rest rotation (feet, clavicles, neck and head already do): the mesh then moves by the * clip's delta from the canonical rest, exactly as Base Female's does. Children keep their world transforms. * * 3. GROUND (`avatar.grounded`). The engine places a clip's pelvis from the clip, so how far the soles dip below the floor in the * idle, walk and run is a property of the rig (leg lengths and rest against the canonical ones). The three clips are played here * on the rig the way the engine plays them (local rotations verbatim, pelvis translation from the clip) and the lowest posed sole * vertex (foot/ball dominated), and the lowest vertex of anything, are measured. When either dips below its target the whole * posed body is lifted by the shortfall (root +d, pelvis -d in the rest locals: every rest world and inverse bind matrix is unchanged, the * rest mesh does not move, the clips carry it that much higher). The soles decide, not the mesh bottom: a gown hem hanging below the shoes does not push * the shoes off the floor (it only counts through the gate's own, looser limits `anyTargetM` / `anyIdleTargetM`). */ export type RestPoseMode = 'repair' | 'report' | 'off'; export interface RestPoseOptions { mode?: RestPoseMode; /** A leg joint (calf, foot, ball) whose direction from its parent is further than this from the standard moves (default 35 deg; gate limit 50-60). */ legTriggerDeg?: number; /** The clavicle: further than this from the standard moves (default 25 deg; gate limit 35). */ clavicleTriggerDeg?: number; /** The spine chain (pelvis, spine_01-05) whose rest rotation is further than this from the canonical one takes the canonical rest (default 6 deg: * the walk then leans like Base Female's; measured on published avatars that passed the gate, the spine sits within 3 deg). */ restTriggerDeg?: number; /** The same for each leg (thigh, calf; default 20 deg: published avatars that passed the gate sit within 15 deg, the broken gowns at 25-58). */ legRestTriggerDeg?: number; /** Skip the joint moves / rest rotations / ground lift. */ joints?: boolean; rests?: boolean; ground?: boolean; /** Lowest posed sole vertex allowed below the floor over the idle, walk and run (default -0.06 m; Base Female's own walk is -0.043, published avatars that passed the gate read down to -0.059). */ soleTargetM?: number; /** Lowest posed vertex of anything allowed below the floor in the walk and run (default -0.10 m, the gate's walk limit). Cloth swung by the legs can * dip far below the soles; the lift this asks for is capped by `maxHoverM`. */ anyTargetM?: number; /** Highest the idle soles may be left above the floor to satisfy the any-vertex targets (default 0.08 m: feet inside a long garment, out of sight). */ maxHoverM?: number; /** The same in the idle (default -0.06 m; the gate's idle limit is -0.08). */ anyIdleTargetM?: number; /** Largest lift (default 0.15 m); beyond it the rig is broken in a way a lift hides, and the shortfall is reported. */ maxLiftM?: number; canonical?: CanonicalSkeleton; } export interface RestPoseJointMove { joint: string; from: string; beforeDeg: number; afterDeg: number; } export interface RestPoseGroundReport { /** Lowest posed sole / any vertex (m) per clip, before the lift. */ before: Record<'idle' | 'walk' | 'run', { sole: number | null; any: number; }>; liftM: number; /** What the lift was asked to be, when the cap held it back. */ wantedLiftM: number; sampledVertices: number; } export interface RestPoseReport { mode: RestPoseMode; skipped?: string; skins: number; joints: RestPoseJointMove[]; rests: Array<{ chain: 'spine' | 'leg_l' | 'leg_r'; deviationDeg: number; }>; ground: RestPoseGroundReport | null; } export interface SoleMeasure { before: RestPoseGroundReport['before']; sampled: number; } /** * Play the idle, walk and run on `model` the way the engine does (clip local rotations verbatim, pelvis translation from the clip, every * other joint at its rest local) and return the lowest posed sole vertex and lowest posed vertex of anything per clip, in metres from the floor. */ export declare function measureSoles(model: SkinModel): SoleMeasure | null; /** Joint moves and canonical rest rotations (stages 1 and 2 above). Run before the arm re-bind and the limb-bridge repair. */ export declare function normalizeRestJoints(document: Document, options?: RestPoseOptions): RestPoseReport; /** The ground lift (stage 3). Run last, after every stage that changes the rest or the weights of the legs. */ export declare function groundSoles(document: Document, options?: RestPoseOptions): RestPoseReport; export declare function describeRestPose(r: RestPoseReport): string[];