import type { Document } from '@gltf-transform/core'; import { type SkinModel, type VertexSet, type Weights } from './armBindSkin'; import { type FootWeightsOptions } from './footWeights'; import { type HangingClothOptions } from './clothWeights'; /** * STATIC WEIGHTS — hair, loose cloth and appendages skinned to the body they hang from; no weight leaking across limbs. * * Generated characters (Dreamer: Tripo by default, Meshy as rollback) come back auto-rigged on the 68-joint skeleton * with no bones for hair, coat skirts, tails or ears, and with weights a walk exposes. Jack's standing decision * (2026-10-07): physics bones stay OFF for generated characters; hair and cloth must be STATIC but skinned so they * follow the body and never stick out. Measured (probe: production Marketplace retargeter + walk, engine run): * - Cream Hoodie: back hair at 1.2-1.4 m carried upper arm 0.25 and clavicle 0.3 — every arm swing levered the * sheet sideways off the back; sleeve cuffs carried thigh 0.22 + pelvis (18 cm cuff stretch in a run); * - Tripo trench coat: the coat skirt carried the HANDS (1.0) — it flew out with every arm swing, 61 cm edges; * - Tripo fox girl: the tail rode a thigh and a hand — 39 cm edges mid-walk. * Skin weight alone cannot say what a vertex is (the trench skirt is "hand-owned"), so ownership here is GEOMETRIC. * * A. LIMB ENVELOPES. Each arm (shoulder -> elbow -> wrist -> hand tip) and leg (hip -> knee -> ankle -> toe) has a * surface envelope: per segment, the median distance from the bone axis of the vertices that segment's bone owns, * widened to max(`envelopeScale` x that, that + `envelopeMarginM`). Weight on a limb carried by a vertex OUTSIDE * that limb's envelope is a leak and is removed (faded in over `envelopeFadeM`). What it carried goes back to the * vertex's remaining influences — or, when little remains (a coat panel weighted only to the hands, a tail), to a * LOOSE-GEOMETRY FIELD for where it hangs: * above the waist: the spine -> neck -> head chain blended by height (it lies along the back); * below the waist, behind the hips and near the midline (a tail): pelvis and spine_01 — never a thigh; * below the waist otherwise (a coat, dress or skirt panel): pelvis, handing over to the thigh of its side with * depth (up to `skirtThighShare` at the knee) and to BOTH thighs equally at the midline, so a panel between * the legs stretches across its width as the legs part instead of tearing at a seam. * Vertices inside a limb's envelope keep that limb's weight: the posterior deltoid, the lats, a sleeve, the crotch * seam both legs reach. * B. HANGING ON THE BACK. Behind the spine line (more than `backMarginM`), inside the shoulder line, between the waist * and the head joint: clavicle weight away from the arms, and head/neck weight below the neck, move to the height * field (the skin over the shoulder blades keeps its clavicle share — it is next to the arm's territory). * C. HEAD-HUNG STRANDS. A head/neck-owned vertex away from the clavicle's own surface sheds its clavicle weight (front * and side strands follow the head and neck, not the shoulders). * * Run after the bind normalisation (armBind.ts) so the arms already stand clear of the body they were fused against. * Every LOD skin is processed from its own mesh. Auxiliary joints (authored hair/spring chains, accessories) are never * touched. Only JOINTS_n / WEIGHTS_n change. */ export type StaticWeightsMode = 'repair' | 'report' | 'off'; export interface StaticWeightsOptions { mode?: StaticWeightsMode; /** Rule A on/off (default OFF: on 8 of 9 fixtures it grew walk stretch and it spiked the fox tail — see * docs/character-rig-fix.md; its envelope geometry still masks the arm re-bind, see armEnvelopeMembership). */ limbEnvelopes?: boolean; /** Envelope = max(scale x segment radius, radius + margin) (defaults 1.8, 0.05 m at 1.70 m). */ envelopeScale?: number; envelopeMarginM?: number; /** Fade width beyond the envelope (default 0.05 m). */ envelopeFadeM?: number; /** Thigh share of a skirt/coat panel at the knee (default 0.6). */ skirtThighShare?: number; /** Rule B on/off (default true). */ hangingBack?: boolean; /** Rule B: how far behind the spine line a vertex must sit to count as hanging on the back (default 0.05 m). */ backMarginM?: number; /** Rules B/C: surface distance from the arm / clavicle territory over which their weight fades out (0.03-0.12 m). */ fadeStartM?: number; fadeEndM?: number; /** Arm reach (`releaseArmReach`, run before the arm re-bind; default on). `false` skips it. */ armReach?: ArmReachOptions | false; /** Foot siding (`footWeights.ts`): a shoe never carries the other foot's weight (default on). `false` skips it. */ feet?: FootWeightsOptions | false; /** Hanging cloth (`clothWeights.ts`): a skirt, robe or cape tail a stride tears gets its weights relaxed until it does not (default on). `false` skips it. */ hangingCloth?: HangingClothOptions | false; } export interface StaticWeightsSetReport { skin: number; vertices: number; /** Rule A: vertices that lost limb weight from outside the limb's envelope. */ offLimb: number; /** ...of which re-skinned (mostly) to the loose-geometry field: hair, coat/skirt panels, tails. */ loose: number; /** Rules B + C. */ hangingBack: number; /** Foot siding: vertices below the ankle that handed the other foot's weight back to their own side. */ feetSided?: number; /** Hanging cloth: vertices whose weights were relaxed because the walk stride tore the cloth around them. */ clothRelaxed?: number; } export interface StaticWeightsReport { mode: StaticWeightsMode; skipped?: string; sets: StaticWeightsSetReport[]; /** LOD0 totals. */ offLimb: number; loose: number; hangingBack: number; /** LOD0: vertices whose cross-foot weight went back to their own foot. */ feetSided: number; /** LOD0: vertices of hanging cloth (skirt, robe, cape tail) relaxed so the stride does not tear it. */ clothRelaxed: number; } type Group = 'armL' | 'armR' | 'legL' | 'legR' | 'torso' | 'clavL' | 'clavR' | 'neck' | 'head' | 'aux'; export declare function jointGroup(name: string): Group; type V3 = [number, number, number]; /** Distance from p to a polyline, the index of the nearest segment and the parameter along it (0..1). */ export declare function polylineDistance(p: readonly number[], pts: readonly V3[]): [number, number, number]; /** Clean every skin's weights in place (report mode measures only). */ export declare function cleanStaticWeights(document: Document, options?: StaticWeightsOptions): StaticWeightsReport; /** * Per-vertex membership (1 inside .. 0 outside) of each arm's surface envelope (rule A's geometry), for the bind * normalisation: a coat panel or tail the auto-rig weighted to a hand must not swing out with the arm at bind. */ export declare function armEnvelopeMembership(model: SkinModel, set: VertexSet, w: Weights, options?: StaticWeightsOptions): { L: Float64Array; R: Float64Array; }; export interface ArmReachOptions { /** 'repair' (default) moves the weight; 'report' measures only; 'off' skips. */ mode?: StaticWeightsMode; /** Tube around the arm = max(scale x radius, radius + margin) (defaults 1.8, 0.05 m at 1.70 m). */ tubeScale?: number; tubeMarginM?: number; /** Fade beyond the tube and above the waist line (default 0.05 m at 1.70 m). */ fadeM?: number; /** How far from the wrist -> hand-tip line a hand reaches (default 0.15 m at 1.70 m). */ handReachM?: number; /** Longest an arm's surface runs from the shoulder, as a share of body height (default 0.45). */ armLengthShare?: number; /** Thigh share of a skirt/coat panel at the knee (default 0.6, as rule A). */ skirtThighShare?: number; } export interface ArmReachReport { mode: StaticWeightsMode; skipped?: string; /** Per vertex set: vertices that shed arm weight, and the arm weight moved (sum over vertices). */ sets: Array<{ skin: number; vertices: number; released: number; weightMoved: number; }>; /** LOD0. */ released: number; weightMoved: number; } /** * ARM REACH — arm weight on geometry that is not part of the arm goes to the body it hangs from. * * An auto-rig weights by proximity in the source pose, where the hands hang beside the hips: the Tripo trench coat * (r0 item 7cb007c9) carries hand weight 1.0 on its coat skirt down to the hem at 0.47 m, so every arm swing tore a * panel off the coat (66.7 cm walk, 84.5 cm run edges) and the re-bind lifted panels out with the arms. Skin weight * cannot say what is the arm; geometry can: * - REACH: the arm is what an arm-owned path from the shoulder reaches over the arm's own surface. Below the waist * (the hip line for weight under 0.3), arm-owned surface no such path reaches loses its arm weight once it is off * the hand itself; reached surface keeps it unless it lies further down the arm's surface than `armLengthShare` of * the body's height AND outside the hand's reach. Distance along the surface, not the skeleton, because a rig can * put the wrist at the elbow (Tripo fox girl) and make the hand line useless; * - TUBE: around the arm's bones, its radius measured on the SLEEVE (upper-arm and forearm vertices over 20-80% of the * bone), never on hand-owned vertices — a hand-weighted skirt inflates the hand's own radius until it swallows the * coat (why rule A's envelope and the re-bind's mask missed it). The hand reaches `handReachM` (every hand vertex of * the eval set's good avatars lies within 0.143 k); * - CUT OFF: at any height, arm weight on surface outside the tube that no arm-weighted surface connects to the arm; * - PIECES: a mesh piece the arms own outright that lies along the arm (a gripper, a glove or bracelet shell) is the * arm whatever its shape; a coat flap modelled as its own shell is not; * - SLIVERS: an arm-owned vertex joined to a released panel by an edge longer than a hand goes with the panel; * - released weight goes to the loose-geometry field rule A uses (pelvis handing over to the thigh of its side with * depth, both thighs at the midline, a tail behind the hips to pelvis/spine_01, above the waist the spine -> neck * -> head chain by height), faded over `fadeM`. * * Run BEFORE the arm re-bind (armBind.ts): released geometry then stays where it is when the arms go up, instead of * being baked out with them. Legs, torso, clavicles and auxiliary joints are untouched; only JOINTS_n / WEIGHTS_n change. */ export declare function releaseArmReach(document: Document, options?: ArmReachOptions): ArmReachReport; export {};