/** * Refuse to conform/package a character add-on whose garment geometry * includes leftover base-body / underwear surfaces — the defect found live * on "Kombes Man" (`d3823cdf-dfac-4a81-a768-6817089d5144`) and "Female * Sweater Top" (`48d7871c-0a95-496f-b50b-9c87b2c64775`): an untextured grey * torso/bra shape baked into the garment's own GLB, visible under the actual * (textured) garment surface. Confirmed in two independent renderers (the * backend's `final-mesh-textured` CPU rasterizer AND the WebGPU studio * capture path) — a real defect in the mesh DATA, not a render bug. See * `run/open-alpha-qa/customizer-followups/thumbnails/scan2/SUMMARY.md` in the * workspace root for the original evidence. * * ── ROOT CAUSE ───────────────────────────────────────────────────────────── * Both items were almost certainly authored in Unreal with a base body / * underwear layer left visible under the garment for authoring convenience, * and the extraction/conform pipeline never stripped it before packaging the * add-on GLB. An add-on's web GLB must contain ONLY the garment surface: it * renders on top of the platform's own real host body at runtime, so a copy * of that body baked into the add-on is never correct, no matter how it got * there. * * ── WHY ISLANDS ARE GROUPED BY SHARED EDGE, NOT SHARED VERTEX ─────────────── * The first version of this file grouped triangles into "islands" by shared * VERTEX INDEX. That is too coarse: on the real Kombes Man overalls * primitive, a decimated LOD's simplifier had welded a handful of isolated * vertices between the (real, textured) overalls fabric and the (leftover, * untextured) duplicate leg geometry tucked inside it — an incidental point * of contact, not a shared surface — and vertex-based grouping fused them * into ONE island. Removing that island deleted real garment triangles along * with the leftover ones (confirmed by re-rendering the "fixed" GLB and * finding holes torn in the pant legs that were never there in the source). * * A second attempt went to the opposite extreme — classifying and removing * every triangle independently, from only its own 3 UV corners — and * OVER-removed instead: sampling only 3 texels is noisy enough (seam/padding * bleed) that thousands of genuinely textured pant-leg triangles individually * misread as "mostly untextured". * * Grouping by shared EDGE (both vertices of a triangle side, not just one) * is the fix that keeps both properties: two triangles that are part of the * same authored surface almost always share a full edge, so real garment * geometry stays one connected island; two triangles from DIFFERENT authored * surfaces that happen to have a single decimation-welded vertex in common do * NOT share an edge, so they are never merged. Classifying and stripping at * this island granularity gets a large, statistically stable sample of * texture reads per decision (tens to hundreds, not three) while never * bridging into real garment geometry. Verified against the real Kombes Man * regression: this produces a stripped GLB with the pant legs fully intact * and only the actual leftover-body islands removed (see * `bodyGeometryGuard.spec.ts`'s fixture-backed regression tests). * * ── WHY "SAME MATERIAL, DIFFERENT ISLAND" AND NOT A NAME CHECK ────────────── * Both live regressions disproved the obvious heuristic. Kombes Man's * body-vs-garment islands share ONE material name * (`MI_M_KombesMan_skinning1`) and Female Sweater Top's grey bra shares its * single primitive with the pink sweater fabric (many disconnected islands, * one draw call) — so neither "does the mesh/material name contain 'body'" * nor "which primitive is this" separates them. What DOES separate them, * confirmed by isolating and rendering flagged islands from both real items: * * 1. The island's DOMINANT skin region (by the SAME dominant-joint * classification `bakeBodyRegions.ts` bakes onto a canonical base body) * is a region this add-on's OWN slot type is already platform-granted to * HIDE (`bodyRegionHide.ts`'s `DEFAULT_HIDE_REGIONS_BY_SLOT_TYPE`) — i.e. * the island sits exactly where the base body's own skin already is, on * a slot that exists specifically to cover that skin. * 2. The island's own baked base-color texture, sampled at its own UVs * across many triangles, is overwhelmingly flat/untextured (low * saturation, mid value — the `graycheck.py` heuristic the original * evidence scan used) OR fully transparent (never properly unwrapped at * all) rather than real garment texture. * * A real garment surface skinned to, say, the torso joint (a snug crop top) * is expected and fine; a real garment island is NOT expected to be both * region-duplicate AND textureless at the same time — that combination is * the signature of body/underwear geometry nobody meant to ship. Requiring * BOTH signals together is what keeps this from flagging legitimate * dark/plain/grey-dyed garments (which are textured, just not colourful) or * legitimate underwear-slot items (whose own visible surface is the point, * not a duplicate of the host's hidden skin). * * ── MEASURED PRECISION (READ BEFORE TRUSTING THIS AS AN ORACLE) ────────────── * This check was tuned against the REAL catalogue, not a synthetic fixture: * every one of the 76 live published add-ons was downloaded and scanned, and * every flag it produced was then rendered and inspected by eye. * * signal flagged true false * region + untextured island (first cut) 19 2 17 * + item-level colored-fraction gate 10 2 8 * + minTotalFlaggedTriangles = 1000 (SHIPPED) 3 2 1 * * The one residual false positive is a sneaker whose sole bed and inner * lining read as one large untextured surface on `body_foot_*` (~1800 * triangles) — structurally indistinguishable from the real defect by ANY * texture- or region-based signal, because both are "a large untextured * surface where the body already is". Several stronger-sounding ideas were * tried AND REJECTED on evidence, not intuition: distance-to-host-body-surface * (a body copy is 13-30mm off the host after conform, and a real garment shell * is 20-34mm — no separation); UV-footprint area; material alphaMode; * primitive-level transparency. Each is documented at its rejection site. * * That measured residual is why this ships as a REFUSAL WITH A DOCUMENTED * OVERRIDE (`assertNoLeftoverBodyGeometryWithOverride`) rather than an * unconditional hard fail: a false positive blocks one creator's publish with * an itemized, actionable message they can clear, where a false negative ships * a visible body-shaped defect to every existing owner. The pre-fix * catalogue proved which of those failures actually happens. * * A name-pattern check is included too (`skin`/`torso` as a WHOLE word in a * mesh/node/material name) as a secondary, independent trip line, with a * looser texture bar — cheap, and it costs nothing to keep even though it * caught neither of the two real regressions here (their mesh/material names * carry no such marker; see `bodyGeometryGuard.spec.ts`'s regression * fixtures). */ import type { Document, Material, Primitive } from '@gltf-transform/core'; import { type HelixBodyRegion } from './bodyRegionHide'; export interface BodyGeometryFinding { nodeName: string; meshIndex: number; primIndex: number; islandIndex: number; triangleCount: number; dominantRegion: HelixBodyRegion | null; /** Fraction (0-1) of attempted texture samples across this island reading either flat/gray or fully transparent — i.e. no real authored pixel content. */ untexturedFraction: number; /** How many samples that fraction is actually computed from. A low count means low confidence — see `minSamplesAttempted`. */ samplesAttempted: number; matchedNamePattern: string | null; reason: 'region-and-texture' | 'name-pattern'; } export interface DetectLeftoverBodyGeometryOptions { /** The add-on's own declared slot type, e.g. `character.top@1` — determines which regions it is already platform-granted to hide. */ slotType: string; /** An island smaller than this many triangles is skipped (buttons, zippers, cuff bands, seam trims). Default 24. */ minTriangles?: number; /** Minimum untextured-sample fraction for the region+texture signal. Default 0.85. */ untexturedFractionThreshold?: number; /** Minimum untextured-sample fraction for the name-pattern signal (looser — the name already narrows it). Default 0.5. */ namePatternUntexturedFractionThreshold?: number; /** Minimum share of an island's CLASSIFIED (non-unclassified) vertex votes a single region needs to count as "dominant". Default 0.5. */ dominantRegionShareThreshold?: number; /** Cap on texture samples taken per island (perf bound on dense meshes). Default 300. */ maxSamplesPerIsland?: number; /** An island needs at least this many attempted texture samples before its `untexturedFraction` is trusted. Default 24. */ minSamplesAttempted?: number; /** * The ITEM must have at least this fraction of its own sampled surface * reading as genuinely authored texture (`colored`) before ANY island is * reported. Default 0.05. * * ── WHY THIS GATE EXISTS (MEASURED, NOT THEORISED) ────────────────────────── * Leftover body geometry is DEFINED by sitting under a real garment — it is * the duplicate that the garment covers. A garment that has essentially no * authored texture anywhere is just a plain/monochrome garment, and its * flat-grey surface IS the garment rather than a body copy beneath it. Without * this gate the region+texture signal fires on every plain grey item in the * catalogue — measured against all 76 live add-ons, it flagged 19, of which a * visual audit of every one showed 18 were ordinary plain-grey or dark * garments (an all-grey tee, an all-grey knit sneaker, a black boot, a brown * hair card, a Lakers-coloured short's dark trim). THIS GATE IS THE SINGLE * MEASUREMENT THAT SEPARATES THEM: it clears 14 of those 18 outright. * * See the class doc's "MEASURED PRECISION" section for the residual * false-positive rate this gate leaves and why the check ships as a * refusable-with-override trip line rather than a silent, always-fatal gate. */ itemColoredFractionFloor?: number; /** * The item's flagged islands must total at least this many triangles before * anything is reported. Default 1000. * * ── WHY (MEASURED) ────────────────────────────────────────────────────────── * Leftover BODY geometry is a body-sized surface; a garment's own dark trim, * inner lining, sole bed or padding is not. Measured against all 76 live * add-ons after the item-level colored gate above, the eight surviving * false positives (a boot's lining, a plaid skirt's underskirt, a shirt's * dark trim, a sneaker's bed, …) each totalled 65–543 flagged triangles, * while the two real regressions totalled 2158 and 1897. 1000 sits in the * empty gap between them and clears seven of those eight. * * The one residual false positive this does NOT clear (a sneaker whose bed * and lining read as one large untextured surface, ~1800 triangles) is * documented in the class doc's "MEASURED PRECISION" section and is the * reason `assertNoLeftoverBodyGeometry` ships with an explicit caller * override rather than being unconditionally fatal. */ minTotalFlaggedTriangles?: number; } export interface TriangleIsland { /** Starting index (into the primitive's index accessor) of each triangle belonging to this island. */ triangleStarts: number[]; vertices: Set; } /** * Group a primitive's triangles into connected surfaces by SHARED EDGE (both * vertices of a triangle side), not shared vertex — see file header for why * this is the correct granularity: it keeps one authored surface as one * island while never bridging two surfaces that merely happen to touch at a * single decimation-welded point. Exported for reuse by the strip tool. */ export declare function findTriangleIslands(prim: Primitive): TriangleIsland[]; export interface DecodedTexture { width: number; height: number; /** RGBA, row-major, top-first (glTF UV origin) — same convention as the backend's `mesh-rasterizer.mjs`. */ data: Buffer; } export declare function decodeMaterialBaseColor(material: Material): Promise; /** * Scan every skinned mesh primitive in `document` for triangle islands * (edge-adjacency — see file header) that look like leftover * base-body/underwear geometry. Returns every finding; callers decide * whether to throw (`assertNoLeftoverBodyGeometry`) or just report. */ export declare function detectLeftoverBodyGeometry(document: Document, options: DetectLeftoverBodyGeometryOptions): Promise; /** Human-readable summary for an error message / CLI report — one line per finding. */ export declare function describeFindings(findings: readonly BodyGeometryFinding[]): string; /** * Throws with a full, itemized report if `document` contains anything that * looks like leftover base-body/underwear geometry. This is the gate * `executeCharacterAddon` calls right after `importCharacter` produces the * add-on's final GLB — the add-on is not a valid deliverable until this * passes, exactly like `assertLooksLikeGlb`/`inspectBaseAvatarGlb` gate the * OTHER ways a character artifact can be malformed. */ export declare function assertNoLeftoverBodyGeometry(document: Document, options: DetectLeftoverBodyGeometryOptions): Promise; export interface AssertNoLeftoverBodyGeometryOptions extends DetectLeftoverBodyGeometryOptions { /** * Package the add-on even when the trip line fires. Use ONLY after a human * has looked at the item and confirmed the flagged surface is a legitimate * garment panel rather than a duplicate of the host body — see the class * doc's "MEASURED PRECISION" section for the residual false-positive class * this exists for. */ allowFalsePositive?: boolean; } /** * Same as `assertNoLeftoverBodyGeometry`, but records and swallows a * confirmed false positive instead of refusing — the escape hatch the bridge * exposes so a creator is never permanently blocked by the trip line. */ export declare function assertNoLeftoverBodyGeometryWithOverride(document: Document, options: AssertNoLeftoverBodyGeometryOptions): Promise;