import type { Accessor, Document, Node, Primitive, Skin } from '@gltf-transform/core'; /** * The skinned-mesh model the rig-fix stages (armBind.ts, hairWeights.ts) read and write. * * A HELIX character GLB carries one skin per LOD scene (each with its own copy of the 68-joint skeleton, see * splitSharedLodSkeletons) and, per LOD, a body primitive plus a `FaceMesh` primitive that SHARE the body's vertex * accessors. Everything here therefore works per skin and per distinct POSITION accessor ("vertex set"), so a shared * buffer is read once and written once, and every LOD gets the same treatment. * * Positions are read in BIND space: the space glTF skinning puts a vertex in at rest, `jointWorld · IBM · v` (the * same for every joint of a consistent rig; `bind` below). A rig whose joints disagree there (a file saved posed) is * refused by `skinModels` rather than guessed at. */ export interface VertexSet { /** The shared POSITION accessor (bind-space positions are `bind · v`). */ position: Accessor; /** Every primitive drawing this accessor (body + FaceMesh), in document order. */ primitives: Primitive[]; count: number; /** Distinct NORMAL / TANGENT accessors over the set's primitives (usually one each). */ normals: Accessor[]; tangents: Accessor[]; /** Morph target accessors (deltas): POSITION / NORMAL / TANGENT per target, over every primitive. */ targetDeltas: Accessor[]; /** JOINTS_n / WEIGHTS_n pairs of the first primitive (the rest share them or are re-checked on write). */ jointSets: Array<[Accessor, Accessor]>; } export interface SkinModel { skin: Skin; joints: Node[]; names: string[]; index: Map; /** Column-major `jointWorld · IBM`, identical for every (weighted) joint at rest. */ bind: number[]; sets: VertexSet[]; /** Unweighted joints whose `jointWorld · IBM` disagrees with `bind` (their IBMs are rewritten on any rebind). */ inconsistent: number[]; } /** * The rest skinning transform of a skin — the `jointWorld · IBM` most joints agree on — and the joints that disagree * (null when no two joints agree). Unweighted helpers are sometimes left inconsistent by hand tools (a rebind that * moved a hand but not the finger IBMs under its metacarpals); they draw nothing, so they do not decide the bind. */ export declare function restBind(skin: Skin): { bind: number[]; inconsistent: number[]; } | null; /** Every skin of the document with its vertex sets. Throws on a skin posed away from its bind. */ export declare function skinModels(document: Document): SkinModel[]; /** Bind-space positions of a vertex set, flat xyz. */ export declare function bindPositions(model: SkinModel, set: VertexSet): Float64Array; /** Up to 4·sets influences per vertex, flattened `width`-wide (joint -1 = empty slot). */ export interface Weights { width: number; joints: Int32Array; weights: Float64Array; } export declare function readWeights(set: VertexSet): Weights; /** Sum of a vertex's weight on the joints flagged in `mask`. */ export declare function weightIn(w: Weights, v: number, mask: ArrayLike): number; /** A vertex's weights as a joint -> weight map (duplicate joint slots summed). */ export declare function vertexWeights(w: Weights, v: number): Map; /** Store a joint -> weight map into a vertex's slots: top `width` influences, renormalised to 1. */ export declare function setVertexWeights(w: Weights, v: number, map: Map): void; /** Write influences back into the set's JOINTS_n / WEIGHTS_n accessors (empty slots = joint 0, weight 0). */ export declare function writeWeights(set: VertexSet, w: Weights): void; /** Triangles (flat vertex indices into the set) over every primitive of the set. */ export declare function setTriangles(set: VertexSet): Uint32Array; /** Position-welded vertex graph (vertices split only by UV/normal seams are one node), CSR with edge lengths. */ export interface WeldGraph { of: Int32Array; nodes: number; start: Int32Array; nbr: Int32Array; len: Float64Array; pos: Float64Array; } export declare function weldGraph(P: Float64Array, tris: Uint32Array, tol?: number): WeldGraph; /** Multi-source surface (geodesic along edges) distance on a weld graph, cut off at `limit` (Infinity beyond). */ export declare function surfaceDistance(g: WeldGraph, sources: Iterable, limit: number): Float64Array; /** World matrix of a joint's PARENT node (identity at the scene root). */ export declare function parentWorld(node: Node): number[]; /** Set a node's local TRS from a desired world matrix (rotation + translation; scale kept at the node's own). */ export declare function setWorld(node: Node, world: readonly number[], parent: readonly number[]): void;