import type { Node } from '@gltf-transform/core'; import { type BakeRestSkinReport } from './stages/bakeRestSkin'; import { type JoinDrawsReport } from './stages/joinDraws'; import { type MergeSkinsReport } from './stages/mergeSkins'; import { type SpringChainReport } from './stages/vrmSpringChains'; import { type VrmMetaRecord } from './stages/vrmMeta'; import type { CharacterSourceProvenance } from './importTrust'; import { type PruneClippedReport } from './stages/pruneClippedTriangles'; import type { BoneMap } from './stages/retarget'; import { type VrmLodReport, type VrmPreviewReport, type WebEncodeReport } from './stages/vrmLods'; /** Which humanoid vocabulary a file speaks. `vrmFace` reports the same two names for the same reason. */ /** * Morph target names belong on `mesh.extras.targetNames`, where every loader and the face mapping read them. UniVRM's * VRM 0.x exports (VRoid's AvatarSample_A/B/C) write them on each PRIMITIVE's extras instead, so a raw VRoid file * failed `helix bridge import` with "names missing morph" while the web path (which hoists first) passed. Copy them * up when the mesh has none. Returns the meshes changed. */ export declare function hoistTargetNames(document: import('@gltf-transform/core').Document): number; export type VrmVersion = '0.x' | '1.0'; interface GltfJson { nodes?: Array<{ name?: string; children?: number[]; mesh?: number; }>; meshes?: Array<{ name?: string; }>; extensions?: Record; } /** Read the JSON chunk out of a GLB/VRM without a full parse — the humanoid map lives there. */ export declare function readGlbJson(path: string): GltfJson; /** Build a `BoneMap` from the VRM's own humanoid block. Handles both the 0.x array and the 1.0 object form. */ export declare function vrmBoneMap(json: GltfJson, label: string): BoneMap; /** * Point every skinned mesh at ONE skin when the file's skins are interchangeable. * * VRoid exports the body, the face and the hair as separate meshes with separate `Skin` objects that share an * identical joint list and identical inverse bind matrices — three names for one skeleton. `conformToHelixRest` * reads `listSkins()[0]` and rebinds only the meshes using it, so on a file like that it silently converts a * third of the character and leaves the rest bound to a rig it then deletes. The result loads, and the hair is * in the wrong place forever. * * Collapsing only happens when the skins are provably the same skeleton — same joints in the same order, same * bind matrices. Anything else is left alone and reported, because merging genuinely different skins is a * different and much harder operation than this. */ export declare function collapseIdenticalSkins(document: import('@gltf-transform/core').Document): number; /** * How far the converted rig's mapped joints sit from the canonical rest orientations, in degrees. * * This is the bridge's acceptance number. Everything else the importer reports is a count — chains kept, joints * kept — and counts cannot tell you whether the character will MOVE correctly. A clip stores per-bone local * rotations in the canonical rest frame, so the only question that matters for fidelity is how closely the * imported rig's frames match those. Zero means platform clips play exactly as authored. * * It is measured rather than asserted because a VRoid avatar's proportions are its own: the orientations are * aimed down the avatar's real limbs, so a few degrees of divergence on a differently-proportioned character is * expected and correct. A large number means the retarget is wrong, and it is the number to watch. */ export interface RigFidelity { maxDegrees: number; meanDegrees: number; worst: string; } export interface VrmCharacterResult { /** Redundant skins folded into one before conforming — see `collapseIdenticalSkins`. */ collapsedSkins: number; /** Skins folded into the first (joints appended, JOINTS remapped) and the ones left alone — see `mergeCompatibleSkins`. */ mergedSkins: MergeSkinsReport; /** Skins whose bind pose differed from the nodes' rest and were baked to the rest pose (see `bakeRestSkin`). */ restBaked: BakeRestSkinReport; auxiliaryJoints: string[]; /** Mapped joints given the canonical rest ORIENTATION so platform clips land in the right frame. */ reoriented: number; /** Whether the VRM 0.x +Z forward convention was corrected to HELIX's −Z. */ flipped: boolean; trianglesBefore: number; trianglesAfter: number; texturesResized: number; /** How far the converted rig sits from the canonical rest frames the clips were authored against. */ fidelity: RigFidelity; chains: number; /** Roll and rotation node constraints shipped for the runtime to evaluate. */ constraints: number; /** What the spring conversion kept, dropped and trimmed. */ springs: SpringChainReport; colliders: number; /** Materials before and after atlasing — the publish gate's tightest constraint on an import. */ materialsBefore: number; materialsAfter: number; /** The draw-call join (`joinDraws`); `null` for a wearable or an untouched source. */ draws: JoinDrawsReport | null; /** Triangles on fully transparent texels that were removed (nobody draws them; every measure counted them). */ clipped: PruneClippedReport | null; /** Surfaces the first-person camera sits inside, declared so the runtime can hide them. */ firstPersonHide: string[]; /** Surfaces marked `firstPersonOnly` (drawn only from inside the head), for the runtime's third-person view. */ thirdPersonHide: string[]; /** The file's own meta and licence terms; `null` when it declares none. */ vrmMeta: VrmMetaRecord | null; /** A validated provenance record built from the meta when `sourceUrl` was supplied and the licence resolves. */ provenance: CharacterSourceProvenance | null; /** Required provenance fields the file could not supply. */ provenanceMissing: string[]; /** Face channels carried across from the VRM's own expressions — see `vrmFace.ts`. */ faceChannels: string[]; /** Wearable expressions carried across: `helix/avatar-face@1`'s six-id vocabulary. */ faceExpressions: string[]; /** The additive `helixFaceExt` block: multi-morph and custom expressions, overrides, bone lookAt. */ faceExt: import('./stages/vrmFaceExt').FaceExt | null; /** Blend shapes dropped because nothing in the contract could drive them. */ faceMorphsRemoved: number; warnings: string[]; unitScale: number; /** Per-level figures (level 0 first) when the file ships a LOD chain; empty for a single-scene output. */ lods: VrmLodReport[]; /** KTX2 / meshopt encoding of the main file; `null` when it stayed PNG and raw. */ encoding: WebEncodeReport | null; /** The separate first-paint rendition, when written. `path` sits beside the main output. */ preview: (VrmPreviewReport & { path: string; bytes: number; cid: string; }) | null; } /** * The node the forward-axis flip rotates: the top of the skeleton hierarchy (the topmost ancestor of the first skin * joint), falling back to a scene child named `Root`. Never `skin.skeleton`, which skin unification points at the Head. */ export declare function skeletonTopNode(document: import('@gltf-transform/core').Document): Node | null; /** * Turn the source skeleton 180 degrees about world Y, exactly, and without touching any mesh node. * * The flip goes on the topmost ancestor of the first joint that no mesh hangs under. A VRM whose root carries a scale (or any * wrapper holding both the skeleton and the mesh nodes) used to be rotated AT that wrapper, so the mesh nodes turned with * it, `conformToHelixRest` baked their now-rotated world matrices into the vertices, and the mesh was flipped a second time: * skeleton facing -Z, mesh facing +Z (the root_scale2/05 edge copies of AvatarSample_B rendered facing away and passed the * gate). The new local matrix is `inverse(P) * R * P * L` for the parent world P, which is the same world-space rotation * whatever P holds (a translation as well as a scale). */ export declare function flipSourceSkeleton(document: import('@gltf-transform/core').Document): Node | null; /** * VRM 0.x models face +Z. glTF, three.js and `helix-humanoid@1` all face −Z. * * ── WHY THIS IS BAKED INTO THE GEOMETRY AND NOT APPLIED AT RUNTIME ───────────────────────────────────────────── * The obvious fix is a 180° wrapper node above the skeleton. It is wrong, and wrong in a way that looks right * standing still: the wrapper rotates the animated RESULT, so the character faces the correct way but every clip * plays mirrored — she runs backwards, and her heels lead. The locomotion system then turns the model to face * its velocity, which hides the cause and leaves only the symptom. * * The convention has to be normalised into the asset instead. Rotating a skinned character by `R` means rotating * three things together, or the binding breaks: * * v_bind' = R·v_bind the vertices * jointWorld' = R·jointWorld the skeleton * IBM' = inverse(jointWorld') the bind matrices, which follow * * Then `jointWorld'·IBM'·v_bind'` reduces to `R·(jointWorld·IBM·v_bind)`: the whole character turns around and * every weight still means what it meant. This function does the vertices; `reorientToCanonicalRest` does the * skeleton and the bind matrices in the same pass, which is why the two are always called together. * * The skeleton half CANNOT live on the root bone. Platform clips carry `root:rotation` and `pelvis:rotation` * tracks — verified, not assumed — so a rotation written there is overwritten by the mixer on the first frame. */ export declare const YAW_FLIP: readonly number[]; /** Rotate every vertex position, normal and tangent 180° about Y, in place. */ export declare function bakeYawFlip(document: import('@gltf-transform/core').Document): number; export type VrmMode = 'conform' | 'rename'; /** * Rename skin joints to the names the engine will see, unique and from a safe alphabet. Returns old → new for * the joints that changed. `GLTFLoader` applies `PropertyBinding.sanitizeNodeName` (whitespace → `_`, then * `[ ] . : /` removed); the contract's name rule is stricter still, so anything outside `[A-Za-z0-9_-]` goes. */ export declare function sanitiseJointNames(document: import('@gltf-transform/core').Document, canonical?: ReadonlySet): Map; /** * `rename` vs `conform`, and when each is the honest choice. * * `conform` rebuilds the skeleton: canonical topology, canonical orientations, the mesh rebound onto it. That is * what makes the platform's clips look RIGHT, because they were authored against that rest pose. It is also a * lot of surgery on someone else's asset, and it is where things break. * * `rename` touches nothing but node names. The VRM keeps its own skeleton, its own rest pose, its own bind * matrices and its own mesh, and the canonical joints simply answer to helix names so the clips can address * them. The mesh CANNOT break, because nothing about it changed. The cost is that a clip authored for the * canonical rest pose plays on a rest pose that is merely similar — limbs sit a little off — which for a VRoid * avatar against `helix-humanoid@1` is a small error rather than a disqualifying one. */ /** Triangle and texture ceilings an imported avatar is decimated to. `null` keeps the source untouched. */ export interface VrmBudget { triangles: number; textureSize: number; /** * Material ceiling, matching the platform's publish gate. * * This is the limit an imported avatar is most likely to fail, and by the widest margin: a VRoid export is * one material per surface, and the reference avatar arrived with 28 against a cap of 8. Triangles and file * size were never close. */ maxMaterials: number; } /** * The hero budget from the character architecture: 15k triangles for a fully dressed character, and the 512-pixel * canonical character texture size. Well inside the validator's 60k/10 MB avatar ceiling, which is a refusal threshold rather than a * target. */ /** * The hero import budget. * * `maxMaterials` is the platform publish gate's own number (`AVATAR_MAX_MATERIALS`), not a pipeline preference: * an import that clears triangles and bytes but ships 28 materials is refused at upload, and the creator learns * that after the round trip rather than here. */ export declare const HERO_BUDGET: VrmBudget; /** * The wearable budget — roughly a third of an avatar's, because several are worn on one at a time. * * The platform's own `WEARABLE_MAX_*` ceilings are 20,000 triangles and 6 MB; this aims under them for the same * reason `HERO_BUDGET` aims under the avatar's, so a garment that later gains a layer does not immediately * breach the gate. */ export declare const WEARABLE_BUDGET: VrmBudget; export interface VrmCharacterOptions { mode?: VrmMode; budget?: VrmBudget | null; /** Keep only primitives whose material name matches — how a wearable is cut out of a source avatar. */ keepMaterials?: RegExp; /** * Where the file came from. The one required provenance field the file itself cannot know; supply it and the * VRM's own meta (licence, authors, version) fills the rest of the record. Omit it and `provenance` stays null * and `provenanceMissing` names `sourceUrl` — never a fabricated URL. */ sourceUrl?: string; /** * Ship LOD0/1/2 as separate self-contained scenes (default on for an avatar). Off writes the single scene. * A wearable cut with `keepMaterials` never gets a chain: it is one garment, not a body. */ lods?: boolean; /** KTX2 textures and meshopt geometry on the output (default on with `lods`). */ webEncode?: boolean; /** Also write `.preview.glb` (default on with `lods`). */ preview?: boolean; } export declare function makeVrmCharacter(vrmPath: string, canonicalPath: string, outPath: string, options?: VrmCharacterOptions): Promise; export {};