import { Document } from '@gltf-transform/core'; import { type HelixBodyRegion } from './bodyRegionHide'; /** * Bakes a `_REGION` per-vertex glTF attribute into a HELIX canonical base body, so the platform's already-built * `hide` grants (`character-slot-pack.ts` / `characterBase.ts`) can actually suppress the body region a garment * covers — WITHOUT adding a single draw call. * * ── WHY BAKED DATA, NOT MORE PRIMITIVES ──────────────────────────────────────────────────────────────────────── * The obvious way to make "hide the thigh" real is to split the body mesh into a separate thigh primitive that * can be toggled invisible. That is the wrong shape here: HELIX's own character draw-call budget is single * digits per character (`docs/proposals/character-mesh-composition-optimization.md`, hero tier <= 6, target 4), * multiplied by every character in a room, so turning ONE body draw into fifteen (one per `HELIX_BODY_REGIONS` * entry) is a real, multiplied regression, not a style choice. Baking the region as VERTEX DATA and collapsing * hidden triangles at runtime (`helix-web-engine-new`'s `applyComposition`) keeps the body at exactly the draw * calls it already has — the same technique this codebase already uses for vehicle parts * (`vehicleBatchedDraw.ts`'s "the part stays in the graph, it just stops being submitted"). * * ── WHY THE COLLAPSE IS AN INDEX REWRITE, NOT A SHADER ──────────────────────────────────────────────────────── * A per-instance-uniform + `onBeforeCompile` shader patch was the first idea and the wrong one: this engine's * own recent history is the reason why. `vehicleBatchedDraw.ts`'s emissive-colour patch relies on exactly that * technique, and `WebGPURenderer` silently skips every `onBeforeCompile` patch — "every batched car rendered * white" until the WebGPU renderer was detected and the batch gracefully degraded (helix-web-engine-new * `11075018`, "car paint on WebGPU"). Collapsing a hidden triangle's three indices to a single shared vertex * index, instead, needs no shader at all: it is the same index-buffer data on WebGL, WebGPU, or any future * renderer, because a triangle whose three corners are the same point has zero area under ANY rasteriser by * definition — there is no renderer-specific code path to keep in parity because there is no renderer-specific * code at all. * * ── WHAT THIS TOOL DOES AND DOES NOT TOUCH ──────────────────────────────────────────────────────────────────── * Adds ONE custom glTF vertex attribute (`_REGION`, one unsigned byte per vertex — an index into * `HELIX_BODY_REGIONS`, `255` for a vertex this classifier could not place). Every other accessor, node name, * skin, material, and socket is byte-for-byte unchanged, which is the point: every add-on's `fits` already * requires specific node/socket names from this exact body, and this must republish as a COMPATIBLE version, * never a breaking one. * * ── THE HIP/TORSO SPLIT: A JOINT BOUNDARY, WIDENED BY THE BLEND ZONE THE RIG ITSELF PAINTED ────────────────── * `body_hip` (pelvis-dominant: glutes, hip crest, lower abdomen, the ring a waistband sits on) is distinguished * from `body_torso` (spine/clavicle-dominant: ribs, chest, upper stomach) using the rig's OWN skin weights, not * an authored world-space height — a height threshold is population-specific (Base Male and Base Female differ * in proportions) and would need re-tuning per body, where the rig's own weight painting needs none. * * A pure "which joint has the single highest weight" argmax is NOT enough on its own, though — MEASURED on the * real Base Female against the real Sinth Ascetic Pants that motivated this file: the argmax boundary sits at * world Y ~1.02 (of a ~1.67m-tall rest pose, i.e. ~61% up), but that pants' actual waistband reaches Y=1.057 — * 3.5cm ABOVE where argmax alone would have drawn the line. Hiding only up to the argmax boundary would have * left exactly the residual poke-through this file exists to close. * * The fix is still entirely rig-driven: any vertex where PELVIS carries at least `HIP_BLEND_WEIGHT_THRESHOLD` * of its total skin weight is `body_hip`, even where spine_01 is nominally the single largest contributor — the * blend zone between two joints is real geometry the rig already describes, and reading it (rather than only * the winning joint) is what recovers the missing 3.5cm. Measured on the same body: vertices where pelvis * weight >= 0.1 reach up to Y=1.068, comfortably (~1.1cm) above that pants' waistband, while >= 0.25 only * reaches Y=1.044 (still short) and "any nonzero pelvis weight at all" reaches Y=1.093 (too far, starting to * eat into unambiguous stomach/ribs territory) — 0.1 is the threshold with headroom on the one real garment * measured against it. This is an empirical property of THIS rig's weight painting, not a universal constant: * re-verify (the poke-through tool's own region breakdown, or a debug region-colour render) against a real * high-rise or low-rise pants item before trusting it unchanged on a differently-proportioned future body. */ /** See "THE HIP/TORSO SPLIT" above — the empirically-chosen pelvis-weight blend threshold. */ export declare const HIP_BLEND_WEIGHT_THRESHOLD = 0.1; /** `_REGION` encodes "no confident classification" as 255 (an unsigned byte, so this is the natural sentinel — * never a valid `HELIX_BODY_REGIONS` index, since the vocabulary has far fewer than 255 entries). */ export declare const UNCLASSIFIED_REGION_INDEX = 255; /** The region for a canonical joint name, or `null` if this classifier cannot confidently place it. */ export declare function regionForJoint(jointName: string): HelixBodyRegion | null; export interface BakeBodyRegionsReport { /** Skinned mesh primitives that received a `_REGION` attribute. */ primitivesBaked: number; /** Vertices across every baked primitive. */ verticesTotal: number; /** Vertices whose dominant joint could not be classified into a region (baked as 255). */ verticesUnclassified: number; /** Vertex count per region name, for a sanity check against the mesh's expected proportions. */ regionCounts: Readonly>; } /** * Bakes `_REGION` onto every skinned primitive in `document`, mutating it in place. Returns a report for the * caller to log/verify; throws only if a skinned mesh has no skin (never expected for a HELIX canonical body). */ export declare function bakeBodyRegions(document: Document): BakeBodyRegionsReport;