import type { Document } from '@gltf-transform/core'; /** * COLLAPSING A GARMENT'S CROSS-LOD MATERIAL DUPLICATION DOWN TO A LOW ADDON CAP. * * `importCharacter`'s LOD loop bakes or re-resizes each LOD level's textures independently (a * genuine quality choice — LOD2 gets a smaller texture than LOD0, not a shared one), so the SAME * named material can carry genuinely different texture bytes per LOD. `mergeLods` combines every * level's scene into one document but does not (and should not) fold those apart-by-design variants * back together: gltf-transform's own `dedup()` correctly leaves them alone, since the textures * really do differ. For most add-on slots that is fine — 2-3 materials per LOD level is well under * budget. It stops being fine for a slot with a LOW material cap (mask/footwear's real-world 2-4 * material ceiling): 2 unique per-LOD materials across 3 LODs is 6 material slots, well over. * * A real per-material texture atlas (baking every LOD's variant of one named material into a single * texture) is the quality-preserving fix and is future work. This is the pragmatic one already * proven out by hand across the male wearables pilot: rebind every primitive in the document onto * whichever material covers the MOST triangles — not the biggest texture, which a small decorative * accent (e.g. stitching detail) can carry more of than the garment's own main body — and prune the * rest. A lower LOD loses its own downsized texture and reuses the higher-detail one instead, which * costs nothing in quality (strictly better) and only a little more texture memory (already-loaded, * shared, not duplicated). */ export interface UnifyMaterialOptions { /** Hard ceiling on materials in the output. Only acts when the document is already over it. */ readonly maxMaterials: number; /** * Whether every LOD scene samples the SAME texture coordinates. True (default) on the plain route, where * each LOD is a simplification of one UV layout, so rebinding a lower LOD onto LOD0's material is lossless. * FALSE on the rebake route: each level is re-unwrapped and re-baked into its OWN atlas, so a lower LOD's * UVs index into a different image than LOD0's. Rebinding it onto LOD0's material makes it sample garbage * (measured on a live cargo-pants add-on: 28% of LOD1/LOD2 triangles landed on pure-black background * texels of LOD0's atlas). With this false, every scene is unified onto its OWN dominant material, so the * result is at most one material per LOD; only if even that is over the cap does it fall back to the * cross-LOD rebinding (and says so in `crossSceneFallback`). */ readonly shareAcrossScenes?: boolean; } export interface UnifyMaterialResult { materialsBefore: number; materialsAfter: number; /** Name of the material every primitive was rebound onto, or null when already within budget (no-op). */ dominant: string | null; /** Primitives whose material assignment actually changed. */ rebound: number; /** * Alpha-MASK materials folded into an OPAQUE dominant by promoting the dominant to MASK (their cutout survives). * Only done when both bind the same base-colour texture, which is how the rebake route builds a shared atlas * whose alpha channel already carries the cutout and is 255 on every opaque chart. */ cutoutsPromoted: number; /** Primitives of a MASK/BLEND material rebound onto a material that could not keep their cutout: they now draw solid. */ cutoutsFlattened: number; /** `shareAcrossScenes: false` was requested but per-scene unification still exceeded the cap, so LOD scenes were rebound across scenes. */ crossSceneFallback: boolean; } /** * Rebinds primitives onto a dominant-by-triangle-count material when the document carries more materials * than `options.maxMaterials`, then prunes the now-unused materials/textures. A no-op (untouched document) * when already within budget — the same "don't pay for what you don't need" convention `atlasMaterials` * uses for its own cap. * * By default ONE dominant material serves the whole document. With `shareAcrossScenes: false` (the rebake * route, where each LOD scene has its own atlas and UV layout) each LOD scene is unified onto its own dominant * instead; see the option's note. */ export declare function unifyDominantMaterial(document: Document, options: UnifyMaterialOptions): Promise;