/** * VRM SpringBone → `helix/dynamics@1`. * * ── WHY VRM FIRST ────────────────────────────────────────────────────────────────────────────────────────────── * It is the only openly specified secondary-motion format with a large body of real content, the configuration * travels INSIDE the .vrm (unlike a Unity prefab, where the parameters live in a scene file that never ships), * and both major versions are readable without a game engine. That makes it the honest first target for an * importer and the honest test corpus for a solver. VRChat PhysBone conversion is the same shape of problem with * a harder extraction step, and lands on this same intermediate form. * * ── THE HARD PART IS UNITS, NOT STRUCTURE ────────────────────────────────────────────────────────────────────── * Chains and colliders map across almost mechanically. The parameters do not, and this is where every naive * converter goes wrong — including, by its own admission, VRChat's: * * · VRM `stiffness` is **world units per second**. It is added to the tail as `axis * stiffness * dt`, then the * tail is projected back to its authored bone length. The projection couples stiffness, bone length and drag; * none of the three can be converted independently without changing the response. * * · VRM `dragForce` is a per-FRAME velocity multiplier. Three-vrm's reference Verlet step retains * `(1 - dragForce)` of the previous displacement once per update while stiffness and gravity are scaled by * dt. Converting it means choosing the frame rate it was authored against; 60 Hz is the preview convention. * We linearise that exact projected step and map its two discrete poles to the continuous spring's poles. * This preserves both oscillation frequency and decay instead of equating velocity retention alone, which * over-damped ordinary VRoid hair and flattened distinct authored values at the critical-damping clamp. * * · VRM `gravityPower` is likewise a velocity, not an acceleration, so it cannot be read as m/s². The * conversion goes through the EQUILIBRIUM instead: in VRM the rest droop satisfies * `tan θ ≈ gravityPower / stiffness`, and in this solver the sag is `g / (ω²L)`. Setting those equal gives * `g = gravityPower * ω²L / stiffness`, using the bounded ω this converter actually emits. That preserves * how far a chain hangs rather than preserving a number that means something different on each side. * * None of this is exact, and it is not claimed to be. The research that produced these relations fitted them * numerically and found parameter recovery good but multi-joint waveforms drifting in phase over seconds. The * goal is a chain that hangs and swings the way the author intended, not one that matches frame for frame. */ export declare const VRM_ASSUMED_AUTHORING_HZ = 60; /** * Inertia given to a chain whose VRM declares a `center` node. * * VRoid writes a `center` BY DEFAULT — its UI calls the option "prevent excessive sway during movement" — so a * large share of real VRM files depend on it, and a converter that ignores it produces hair that flails while * the character merely walks. Measured across the reference set: `AvatarSample_B` centres all 11 of its groups * and `Seed-san` 8 of its 9 springs, while `Vivi` and `AliciaSolid` centre nothing at all. * * True centre-space integration resolves motion against the named node — usually the hips — and is a V2 item; * it needs the character root transform, which a chain anchored to the head does not have. This is the honest * approximation available to a per-anchor scalar: carry most of the anchor's motion, keep some lag. It is * deliberately not 1.0, because full carry would also cancel the head-turn response that makes hair read as * hair, and the failure it is fixing is gross body translation, not rotation. */ export declare const CENTRE_INERTIA = 0.6; /** Pole scale fitted against three-vrm; see `convertSpring`. */ export declare const RESPONSE_CALIBRATION: number; export interface ImportedChain { id: string; root: string; importance: 'critical' | 'high' | 'normal' | 'decorative'; stiffness: number; damping: number; inertia?: number; gravity?: number; gravityDir?: [number, number, number]; radius?: number; colliders?: string[]; endpoint?: [number, number, number]; } export interface ImportedCollider { id: string; bone: string; shape: 'sphere' | 'capsule'; offset?: [number, number, number]; radius: number; tail?: [number, number, number]; inside?: boolean; } /** One simulated joint's authored values, in VRM's own units (see the header for what each one means). */ export interface VrmSpringJoint { /** Source node name. */ node: string; stiffness: number; dragForce: number; gravityPower: number; gravityDir?: [number, number, number]; hitRadius: number; } /** * A spring as the SOURCE declares it, before any geometry is consulted. * * The geometry (bone lengths, the tail each joint aims at, which children branch) belongs to the CONVERTED * rig, whose frames and names are not the source's, so turning a spring into manifest chains is a second step * (`vrmSpringChains.ts`) that runs on the final document. This is its input. */ export interface VrmSpring { /** Unique, contract-safe base for the chain ids this spring produces. */ id: string; name: string; importance: ImportedChain['importance']; /** * `joints` (VRM 1.0): an explicit ordered list. Joint i is simulated and aims at joint i+1; the LAST joint is * only the tail the previous one aims at and is never moved. * `tree` (VRM 0.x): every node under each root is simulated with the group's one parameter block, each aiming * at its first child, and a leaf aims along its own offset from its parent. */ kind: 'joints' | 'tree'; joints: VrmSpringJoint[]; /** `tree` only: the chain roots, source node names. */ roots?: string[]; /** `tree` only: the shared parameter block. */ shared?: Omit; /** Collider ids this spring tests against (groups flattened). */ colliders: string[]; /** The spring's declared `center` node, source name. */ center?: string; } export interface VrmImportResult { contract: 'helix/dynamics@1'; chains: ImportedChain[]; /** The springs as declared; `vrmSpringChains.ts` turns them into full chains on the converted rig. */ springs: VrmSpring[]; colliders: ImportedCollider[]; /** Anything dropped or approximated, in creator-readable terms. */ warnings: string[]; /** `0.x` or `1.0`, for reporting. */ sourceVersion: string; } /** ω (rad/s) → the contract's normalised 0..1 stiffness. The inverse of `stiffnessToOmega`. */ export declare function omegaToStiffness(omega: number): number; /** Continuous response plus its bounded `helix/dynamics@1` representation. */ export interface ConvertedSpring { /** Unclamped continuous natural frequency, in rad/s. */ omega: number; /** Unclamped continuous damping ratio. Values above one cannot be represented by dynamics@1. */ dampingRatio: number; /** Natural frequency of the closest representable response, before the engine's 2..40 rad/s clamp. */ mappedOmega: number; /** Natural frequency after the dynamics@1 clamp; this is what the runtime actually solves. */ engineOmega: number; /** Damping ratio of the bounded dynamics@1 representation. */ mappedDampingRatio: number; /** Normalised dynamics@1 stiffness. */ stiffness: number; /** Normalised dynamics@1 damping. */ damping: number; } /** * Convert one VRM projected-Verlet joint to the continuous `helix/dynamics@1` spring. * * For a small angular displacement `x`, three-vrm's documented update linearises to: * * q = 1 + (stiffness / boneLength) dt * x[n+1] = ((1 + retention) / q) x[n] - (retention / q) x[n-1] * * The roots of that recurrence are the response sampled at the authoring rate. Mapping their magnitude and * phase to `exp((-ζω ± iωd)dt)` gives the continuous spring parameters directly. Dynamics@1 cannot express an * overdamped response, so real positive roots map to a critical spring at the slow pole's rate. That preserves * the visible return tail by lowering stiffness, as the contract requires, instead of clamping damping while * retaining the geometric-mean frequency and making a heavily dragged chain snap back too quickly. */ export declare function convertSpring(vrmStiffness: number, dragForce: number, boneLengthM: number, hz?: number): ConvertedSpring; /** VRM `gravityPower` → a multiplier on real world gravity, via the equilibrium droop. See the header. */ export declare function convertGravity(gravityPower: number, vrmStiffness: number, boneLengthM: number, engineOmega: number): number; /** * Guess how much a chain matters from its bone names. * * Importance drives the frame budget, so getting it roughly right is what lets a crowd degrade sensibly rather * than uniformly. Nothing in VRM carries this, and asking a creator to hand-classify twenty-two chains is the * kind of chore the platform is supposed to absorb. Names in real content are remarkably consistent — VRoid * emits `J_Sec_Hair*`, `*Skirt*`, `*Bust*` — so a table gets most of it, and it is only ever a default. */ export declare function guessImportance(name: string): ImportedChain['importance']; interface GltfNode { name?: string; children?: number[]; translation?: number[]; } interface GltfLike { nodes?: GltfNode[]; extensions?: Record; } /** * Convert the spring-bone configuration of a parsed VRM glTF document. * * Takes the JSON chunk, not a file path or a three.js scene, so it runs in the pipeline, in a test, and in a * browser importer without change. */ export declare function convertVrmDynamics(gltf: GltfLike): VrmImportResult | null; export {};