import type { Document } from '@gltf-transform/core'; /** * EAR CLEARANCE — the head-zone conform stage that stops the base body's ears poking through headwear, masks * and hair, and moves the garment smoothly clear of them when they do. * * ── WHY ──────────────────────────────────────────────────────────────────────────────────────────────────── * The pose-aware fit (`poseAwareFit.ts`) cannot help here: on a thin head shell it measures hundreds of body * vertices "poking" at the forehead and the hairline and refuses its own result (Panama Hat: 408 → 979+ * violations). The visual-QA gate (2026-10-02) then failed Panama Hat and Bandana — "the ear pokes through the * brim / the ragged edge" — and a census of the 28 Base Male head-zone add-ons found the same defect in seven * more (Maska, Hell X Balaclava, Gamer Mask, Eye Hole Mask 1 and 2, Joker Mask, and the Bandana) with the ear * 3-9 mm OUTSIDE the cloth. Every one is the same shape: a close-fitting shell that wraps the ear with no * standoff, because nobody modelled the ear when the shell was authored around the skull. * * ── MEASURE ──────────────────────────────────────────────────────────────────────────────────────────────── * The ears are found from the BODY, not hard-coded: head-region triangles (dominant joint `head`) above the * head joint whose |x - centreX| exceeds 88% of the head's widest point are the ears (the lateral extremes of * the head; on Base Male 1.3.0 that is |x| > 86 mm, 9 000 samples at 3 mm). For every ear sample a horizontal * ray runs from the head axis through the sample; the OUTERMOST garment hit along it decides the clearance: * `clearance = tOutermost - distanceToSample` (positive = cloth outside the ear). A sample counts as a * poke-through only when the garment WRAPS it — the four rays 12 mm above, below, ahead of and behind it also * hit the garment — so a mask whose rear edge simply stops in front of the ear, or a cap that sits above it, * is not an ear defect. * * ── FIX ──────────────────────────────────────────────────────────────────────────────────────────────────── * Panama Hat's hand fix, generalised: a smooth, bounded, lateral push. Each poking sample asks for * `target - clearance` (capped), the garment's own vertices take a Gaussian-weighted maximum of those requests * (sigma 22 mm, a smooth ramp in |x| so nothing near the centre line moves), and the vertices move along the * horizontal radial direction from the head axis. The loop re-measures and repeats (<= 8 passes; a vertex never * moves more than `maxPushMm` in total). Only POSITION changes — skin weights, UVs, normals, materials and * topology are untouched. Every LOD level is fitted on its own; a POSITION accessor shared by two LODs moves once. * * ── GATE ─────────────────────────────────────────────────────────────────────────────────────────────────── * The fix is kept only when the poke count ends at ZERO (clearance >= `triggerMm` everywhere the garment * wraps an ear) in every LOD that had any; otherwise the garment document is left byte-for-byte untouched and * the report says why. A garment that already clears (or never covers the ears) is reported as such. */ export interface EarClearanceOptions { /** Clearance the fix aims for, in mm: the cloth ends at least this far outside the ear (default 4). */ targetMm?: number; /** A wrapped ear sample with less clearance than this is a poke-through (default 1.5). */ triggerMm?: number; /** Largest total move for any garment vertex, in mm (default 18). */ maxPushMm?: number; /** Falloff radius of the push, in mm (default 22). */ sigmaMm?: number; /** Measure -> push passes (default 8). */ iterations?: number; /** Ear sample spacing, in mm (default 3). */ sampleMm?: number; onProgress?: (message: string) => void; } export interface EarClearanceStats { /** Ear surface samples measured. */ samples: number; /** Samples with any garment hit along their ray. */ covered: number; /** Covered samples the garment wraps on all four sides. */ wrapped: number; /** Wrapped samples with less than `triggerMm` clearance. */ pokes: number; /** Smallest clearance among wrapped samples (and covered samples that clear), in mm; null when the garment covers no ear. */ minMm: number | null; p5Mm: number | null; } export type EarClearanceOutcome = 'improved' | 'unchanged-already-clear' | 'unchanged-no-improvement' | 'skipped'; export interface EarClearanceUnitReport { mesh: string; before: EarClearanceStats; after: EarClearanceStats; passes: number; maxMoveMm: number; verticesMoved: number; } export interface EarClearanceReport { outcome: EarClearanceOutcome; reason: string | null; ear: { samples: number; axisX: number; axisZ: number; earMinAbsX: number; } | null; settings: Required>; units: EarClearanceUnitReport[]; /** Worst-case (smallest min, summed pokes) across units. */ before: EarClearanceStats | null; after: EarClearanceStats | null; } /** Slots whose geometry can sit over the ears. Eyewear is included: temples/straps wrap the ear. */ export declare const EAR_RELEVANT_SLOTS: readonly ["headwear", "mask", "hair", "eyewear", "head-accessory"]; export declare function isEarRelevantSlotType(slotType: string): boolean; interface EarSamples { /** 3 per sample. */ points: Float64Array; axisX: number; axisZ: number; earMinAbsX: number; } export declare function findEarSamples(body: Document, sampleMm: number): EarSamples | null; /** Measure only — never touches `garment`. `outcome` is what `clearEars` would do. */ export declare function measureEarClearance(garment: Document, body: Document, options?: EarClearanceOptions): EarClearanceReport; /** Measure and, when the ears poke through, push the garment clear. Writes `garment`'s POSITION accessors ONLY when the outcome is 'improved'. */ export declare function clearEars(garment: Document, body: Document, options?: EarClearanceOptions): EarClearanceReport; export {};