import { type Document } from '@gltf-transform/core'; /** * MEASURED hide coverage: which of the body regions a garment is granted to hide does it actually enclose? * * ── WHY ──────────────────────────────────────────────────────────────────────────────────────────────────── * A character add-on's `hide` op collapses the base body's triangles for whole `_REGION` labels. Conform used * to emit the slot's FULL platform grant whatever the garment covered, so short sleeves hid the whole upper * arm, cropped trousers the whole shin, and every hem that lands inside a region seam rendered a sawtooth * (the engine drops a triangle when >= 2 of its 3 corners are hidden; labels interleave across a band several * cm wide where two regions meet). The rule here: hide a granted region ONLY when the garment occludes it. * * ── THE METRIC ───────────────────────────────────────────────────────────────────────────────────────────── * Bind pose. For every body vertex v with outward normal n, v is OCCLUDED when a garment surface is crossed by * a ray along n starting `backoffM` behind the skin and reaching `standoffM` in front of it (60 mm: the * "fabric within 60 mm" measure of `run/open-alpha-qa/wearables-import/coverage-derivation`; 20 mm behind so a * garment that sits a few mm inside the skin — which the conform push-out fit then corrects — still counts as * covering it). A region's coverage is the occluded fraction of its vertices; it is hidden at >= 98 %. * * Two lessons from that earlier work are built in rather than rediscovered: * - NEAREST-surface-within-60-mm is the wrong question: fabric 45 mm ABOVE a vertex (a hem above the ankle) * is within 60 mm and covers nothing. Casting along the NORMAL makes a hem above the skin point a miss. * - A ray that lands exactly on a shared edge or vertex can slip between two triangles in floating point, so * each vertex also casts four rays tilted by `coneDeg` (0.5 deg, <1 mm of lateral reach) — enough to rescue * an edge hit, far too little to bridge a hem. (An 8 deg cone, ~11 mm, was tried and credited vertices up to * a centimetre below a hem as covered: Warehouse Uniform's right shin read 100 % instead of 96 %.) * * Every garment LOD (scene) is measured separately — each LOD is drawn alone and the hide op is shared by all * of them — and a region's coverage is the MINIMUM across LODs, so a region is hidden only if no LOD leaves a * void. Body vertices come from the first scene (highest LOD) of the base body, face mesh included. */ export declare const DEFAULT_COVERAGE_THRESHOLD = 0.98; export declare const DEFAULT_STANDOFF_M = 0.06; export declare const DEFAULT_BACKOFF_M = 0.02; /** Half-angle (degrees) of the tilted-ray fan. 0.5 deg is ~0.7 mm at the far end of the reach: it only rescues a * ray that lands exactly on a shared edge or vertex, and cannot bridge a hem (an 8 deg cone could, ~11 mm). */ export declare const DEFAULT_CONE_DEG = 0.5; export interface HideCoverageOptions { /** How far in front of the skin a garment surface may be and still occlude the vertex. Default 0.06 m. */ standoffM?: number; /** How far behind the skin the ray starts, so a garment sitting just inside the skin still counts. Default 0.02 m. */ backoffM?: number; /** Half-angle of the tilted-ray fan, degrees. Default 0.5. 0 = normal ray only. */ coneDeg?: number; /** Restrict the measurement to regions matching these globs. Default: every region the body has. */ regions?: readonly string[]; /** Which base-body LOD scene supplies the vertices and region labels. Default 0. */ bodyLod?: number; } export interface RegionCoverage { region: string; /** Body vertices carrying this region label (highest-LOD body). */ vertices: number; /** Occluded fraction, 0..1 — the minimum across LODs. */ fraction: number; /** Largest number of NOT-occluded vertices of this region at any single LOD. */ bareVertices: number; /** Occluded fraction at each LOD (body LOD k drawn with garment LOD k). */ perLod: number[]; /** Bounding box (metres, bind pose) of the not-occluded vertices at the LOD with the most of them; null when none. */ bareBounds: { min: [number, number, number]; max: [number, number, number]; } | null; } export interface HideCoverageReport { standoffM: number; backoffM: number; coneDeg: number; /** LOD levels measured (body LOD k is paired with garment LOD k). */ lods: number; /** Where the body's region labels came from. `_REGION` is the baked, published classification. */ regionSource: '_REGION' | 'dominant-joint'; /** Vertices whose region could not be placed (never counted toward any region). */ unclassifiedVertices: number; regions: RegionCoverage[]; /** * Per body LOD, what the hole-edge check needs (see `pruneHoleEdges`). Not enumerable, so JSON dumps of a * report stay small; absent on a hand-built report, in which case the check is skipped. */ lodSurfaces?: LodSurface[]; } /** One body LOD as the engine's hide op sees it: labelled vertices, triangles, and which vertices a garment covers. */ export interface LodSurface { regions: Array; triangles: Uint32Array; occluded: Uint8Array; } /** * Per-region occlusion of the base body by `garment`. Both documents must be in their authored (bind) pose. * See the file header for the metric and why it is built this way. */ export declare function measureHideCoverage(garment: Document, body: Document, options?: HideCoverageOptions): HideCoverageReport; /** `measureHideCoverage` on two GLB files (meshopt-compressed renditions included). */ export declare function measureHideCoverageFiles(garmentPath: string, bodyPath: string, options?: HideCoverageOptions): Promise; export interface DerivedHide { slotType: string; threshold: number; /** The slot's platform grant, expanded to the concrete regions the body has. */ granted: string[]; /** Granted regions the garment occludes (>= threshold). */ hidden: string[]; /** Granted regions left visible, each with the measured occluded fraction (and `holeEdge` when the region met the * threshold but hiding it would have left a bare triangle corner at its hole edge — see `pruneHoleEdges`). */ visible: Array<{ region: string; fraction: number; holeEdge?: boolean; }>; /** `hidden` collapsed to the grant's own globs where both sides are hidden (`body_thigh_*`). */ hideNodes: string[]; /** The `ops` array to hand to `publish-version --ops` (empty when nothing may be hidden). */ ops: Array<{ v: 'hide'; nodes: string[]; }>; coverage: HideCoverageReport; } /** Collapse concrete regions back to the grant's globs: `body_thigh_l` + `body_thigh_r` -> `body_thigh_*`. */ export declare function collapseRegionsToGlobs(hidden: readonly string[], grantGlobs: readonly string[]): string[]; /** * HOLE-EDGE CHECK. The region fraction alone lets a handful of bare vertices through (98 % of 363 torso vertices * is seven of them), and those are exactly the ones on a hem: the engine collapses every triangle with >= 2 * corners in a hidden region, so a collapsed triangle whose third corner (or any corner) is NOT under the * garment opens a notch in the skin the fabric does not cross — the black sawtooth under a jacket hem or a * collar (Bomber Jacket, Clare Top, Casual Blazer, Black Shorts). So after the threshold: collapse triangles * with the engine's rule at every LOD, and while any corner of a collapsed triangle is bare, drop the hidden * region carrying the most such corners and recompute. A region dropped here is left visible (the push-out fit * then handles its skin); a vertex facing the body itself already counts as covered. Returns the regions * dropped. Skipped when the report carries no surfaces (a hand-built one). */ export declare function pruneHoleEdges(hidden: string[], coverage: HideCoverageReport): string[]; /** The regions of `slotType`'s platform grant that `coverage` shows the garment fully occludes. */ export declare function deriveHideFromCoverage(slotType: string, coverage: HideCoverageReport, threshold?: number): DerivedHide; /** One human line per granted region, for terminal output. */ export declare function formatDerivedHide(derived: DerivedHide): string;