import { type ImpostorFraming, type ImpostorShading } from './impostor'; import { type GBufferPasses } from './gbuffer'; import { type CardCensus, type CardVerdict } from './cardTruth'; import { type LevelTextureSpec, type WrittenLevel, type WrittenTexture } from './levelGlb'; import { type ItemModel } from './model'; import { type ItemLodProfile, type SimplifiedLevel } from './simplify'; import { TextureCache } from './textures'; /** The `helix.item-lod/1` Runtime Artifact: a small first-load file per level plus an octahedral impostor. */ export declare const ITEM_LOD_SCHEMA = "helix.item-lod/1"; /** * The generator's identity in a derivation key (`item-lod/`): bump it on any change that alters the bytes a compile writes, * because a ready or failed Runtime Artifact is terminal for its key. 1 was the first generator, 2 round 2 (zero to two * tagged levels, each strictly smaller), 3 round 3 (one draw per render state, vehicle LOD2 shell, a level over its cap is * omitted instead of failing the item, an impostor that is not smaller than the source is omitted). Round 4 stayed on 3: it only * stopped declaring extensions nothing in a level uses, which changes bytes solely for rows that never reached ready (a ready row * is never recompiled). The document schema stays `helix.item-lod/1`: the runtime reads the schema id and ignores this one. */ export declare const ITEM_LOD_COMPILER = "item-lod/3"; /** * The derivation-key contract each impostor shading is compiled under (the backend owns the key; this table is what its worker reads so the two cannot * drift). `item-lod/3` is the albedo rendition, `item-lod/4` the same document with a `lit/1` atlas, `item-lod/5` the `gbuffer/1` impostor: a different * layout (`hemi-oct/1`), three maps instead of one, and a bytes rule that keeps the impostor of any item over a few hundred triangles. A ready row is * terminal for its key, so a change to any of those bytes is a new contract, never an edit of /5. */ export declare const ITEM_LOD_COMPILER_FOR_SHADING: Readonly>; export declare const ITEM_LOD_GBUFFER_COMPILER = "item-lod/5"; /** * `item-lod/6`: `item-lod/5` (shading `gbuffer/1`) with card truth applied (`cardTruth: 'apply'`, see `cardTruth.ts`). An item whose card cannot be truthful (see-through * glass or water, a mirror, thin emissive parts) is compiled WITHOUT its impostor and with a mesh that is guaranteed to draw; every other item compiles to the same bytes as `/5`. * The backend queues it only for the items the `/5` compile reports as `cardTruth.suppress`, and serves it to the same clients as `/5`, ahead of it. */ export declare const ITEM_LOD_CARD_TRUTH_COMPILER = "item-lod/6"; /** True in a CLI that implements `cardTruth` (a worker checks this before it compiles `item-lod/6`, so an older CLI never writes a card under a contract that forbids it). */ export declare const ITEM_LOD_CARD_TRUTH = true; /** The runtime skips a level whose measured error is over this share of the bounds diagonal (`itemLod.ts` in the engine); a document with no level that passes it needs a model of at most this many triangles to draw. */ export declare const ITEM_LOD_LEVEL_ERROR_RATIO = 0.1; /** * Card truth prefers the item itself over an approximation: a level whose measured error is within this share of the bounds diagonal is faithful enough to stand in for it, and a source of at most * `ITEM_LOD_OWN_MODEL_MAX_TRIANGLES` triangles whose levels are not that close is drawn as itself (the Black Frame Glass Wall's 66 triangle LOD1 is 20 cm off a 30 cm wall: 2.4 percent of an 8.4 m diagonal, inside * the runtime's 10 percent rule, but not the wall). */ export declare const ITEM_LOD_FAITHFUL_ERROR_RATIO = 0.02; export declare const ITEM_LOD_OWN_MODEL_MAX_TRIANGLES = 4000; /** Caps the artifact must hold (SCENE-PIPELINE-DESIGN section 4.5). */ export declare const ITEM_LOD_CAPS: { readonly lod1TriangleRatio: number; readonly lod1TextureEdge: number; readonly lod2Triangles: number; readonly lod2TextureEdge: number; /** Vehicle LOD1 starting budget: max(this, vehicleLod1TriangleRatio of the source); it widens to the prop budget only to hold the error bound. */ readonly vehicleLod1MinTriangles: 5000; readonly vehicleLod1TriangleRatio: 0.1; /** A level is emitted only if it cuts at least this fraction of the triangles of the level above it. */ readonly minReduction: 0.5; }; export interface ItemLodSource { /** Null only for a local `--glb` compile, which has no Package behind it. */ packageId: string | null; version: string | null; manifestCid: string | null; /** The explicitly chosen variant, or null for the default model. */ form: string | null; modelCid: string; } export interface ItemLodLevel { /** Which tier this is. `levels` lists only the tiers that were emitted, nearest first, so read this, not the index. */ lod: 1 | 2; object: string; triangles: number; maxErrorM: number; /** File size of the level GLB, bytes. */ bytes: number; /** Longest texture edge in the level; 0 when the level has no textures. */ textureMaxEdge: number; /** * Primitives in the level's GLB, which is its draw calls per placement band: one per render state (opaque or alpha-blended, * lit or unlit) because the level's materials share one texture atlas. Absent on levels written by earlier compilers. */ drawCalls?: number; /** The triangle cap this level was held to. */ cap: number; /** Retained for artifacts written by the first compiler; a level that cannot reduce is now omitted instead. */ waived?: string; } export interface ItemLodImpostor { object: string; kind: 'octahedral'; views: 8; size: 512; format: 'ktx2-uastc'; /** Capture framing, scene space: the card centre and the orthographic half-width of every view. */ center: [number, number, number]; radius: number; bytes: number; /** * `lit/1`: the atlas holds the item's own shading under the generator's neutral rig at `bakeScale` of its radiance (the runtime scales the * light per channel against that rig). Absent: an albedo atlas, which the runtime lights flat (every artifact before this field). */ shading?: 'lit/1' | 'gbuffer/1'; bakeScale?: number; /** * How the 8 x 8 views are laid out. Absent: `oct/1`, the full-sphere octahedral layout of every artifact before `gbuffer/1`, half of whose views look * from under the ground. `hemi-oct/1`: the upper hemisphere only, its outer ring on the horizon (see `gbuffer.ts`). A `gbuffer/1` impostor always says it. */ layout?: 'hemi-oct/1'; /** * `gbuffer/1` only: the other maps. `object` and `bytes` above are the albedo map (sRGB RGB, alpha = coverage). `surface` is linear: R, G the view-space * normal x, y, B roughness, A metalness. `emissive` (present when the item glows or has a clear coat) is sRGB RGB = radiance x `scale`, A = clear coat; * `clearcoat` says whether that alpha is used. */ maps?: { surface: { object: string; bytes: number; }; emissive?: { object: string; bytes: number; scale: number; clearcoat: boolean; }; }; } export interface ItemLodArtifact { schema: typeof ITEM_LOD_SCHEMA; source: ItemLodSource; /** Which LOD1 triangle budget applied: props keep at most 25 percent, vehicles max(5000, 10 percent). */ profile?: ItemLodProfile; bounds: { min: [number, number, number]; max: [number, number, number]; }; /** [source, then one count per entry of `levels`], so `levels[i].triangles === triangles[i + 1]`. */ triangles: number[]; /** * Zero, one or two levels, nearest first. A tier that does not cut at least half the triangles of the level above it, or * cannot be made strictly smaller in bytes, is omitted: with `levels` empty the runtime goes from the full model straight * to the impostor. Each omission is explained in `warnings`. */ levels: ItemLodLevel[]; /** * The far representation past the last level. Null when it would not be smaller than the source model in bytes (a tiny * item's atlas costs more than the item): the runtime then keeps drawing the last level, or the model itself. */ impostor: ItemLodImpostor | null; /** Approximate GPU-resident bytes: vertex and index buffers plus transcoded textures with mips. A tier key is present only if that level is. */ estimatedBytes: { lod1?: number; lod2?: number; impostor?: number; }; /** Anything the compiler could not carry across (material extensions, morph targets, animation), then one note per omitted level. */ warnings: string[]; } export interface ItemLodObject { cid: string; bytes: Uint8Array; mediaType: 'model/gltf-binary' | 'image/ktx2'; /** `impostor` is the impostor's colour (or albedo) map; a `gbuffer/1` artifact adds `impostor-surface` and, when present, `impostor-emissive`. */ role: 'lod1' | 'lod2' | 'impostor' | 'impostor-surface' | 'impostor-emissive'; } export interface ItemLodReportLevel { triangles: number; cap: number; capMet: boolean; waived: string | null; maxErrorM: number; /** `maxErrorM` over every source vertex, sub-visible parts included. */ strictErrorM: number; bytes: number; textures: number; textureMaxEdge: number; residentBytes: number; droppedMaterials: number; notes: string[]; /** Primitives (draw calls per placement band) in the level's GLB. */ primitives: number; /** The material atlas shared by the level's primitives, when the item has more than one material recipe. */ atlas?: NonNullable; /** Which texture spec produced the level (0 is the full set; higher rungs trade texture detail for bytes). */ textureRung: number; /** Per texture: how it was made and what it cost. */ textureDetail: WrittenTexture[]; } export interface ItemLodOmission { lod: 1 | 2; reason: string; /** What the omitted tier would have been, so the decision can be audited. */ triangles: number; bytes: number | null; } export interface ItemLodReport { sourceTriangles: number; sourceBytes: number; materials: number; images: number; extensionsUsed: string[]; profile: ItemLodProfile; /** Null when that tier was omitted; see `omitted`. */ lod1: ItemLodReportLevel | null; lod2: ItemLodReportLevel | null; omitted: ItemLodOmission[]; /** What the capture came to; `omitted` is set when it was left out of the artifact because it was not smaller than the source. */ impostor: { bytes: number; coverage: number; omitted?: boolean; shading?: ImpostorShading; maps?: { surface: number; emissive: number | null; }; }; /** The card-truth verdict (gbuffer/1 compiles with `cardTruth` set): `suppress` is the rule's answer, `suppressed` is whether this artifact actually has no card. */ cardTruth?: { mode: 'apply' | 'observe'; suppress: boolean; suppressed: boolean; reasons: string[]; mesh: 'level' | 'own-model' | 'none'; census: CardCensus; thinEmissive: CardVerdict['thinEmissive']; }; caps: CapCheck; warnings: string[]; millis: { total: number; }; } export interface ItemLodBuild { artifact: ItemLodArtifact; artifactBytes: Uint8Array; artifactCid: string; objects: ItemLodObject[]; report: ItemLodReport; /** Human review images keyed by file name; never part of the artifact. */ previews: Array<{ name: string; bytes: Uint8Array; }>; } export interface CapCheck { ok: boolean; failures: string[]; /** Caps that do not apply, with the reason. */ waivers: string[]; } /** Checks the design's caps against an artifact. Waived levels pass but are listed. */ export declare function checkItemLodCaps(artifact: ItemLodArtifact): CapCheck; /** Structural validation of an artifact document. Does not check the caps; see `checkItemLodCaps`. */ export declare function validateItemLodArtifact(value: unknown): { valid: true; artifact: ItemLodArtifact; } | { valid: false; errors: string[]; }; export interface CompileItemLodOptions { source: ItemLodSource; /** * `vehicle` aims LOD1 at max(5000, 10 percent of the source) triangles, widening up to a quarter only if the measured error * would pass 10 percent of the longest extent; default `prop` (at most 25 percent). */ profile?: ItemLodProfile; /** * How the impostor atlas is shaded: `lit/1` (the default, what the artifact says in `impostor.shading`) or `albedo` (flat albedo, the * original capture, no `shading` field). An engine before the lit atlas draws every atlas as albedo and would draw a lit one about half * as bright, so the backend keeps an albedo rendition next to the lit one and serves each to the clients that can draw it. */ shading?: ImpostorShading; /** * Card truth (`gbuffer/1` only). `'apply'` leaves the impostor out (`impostor: null`, the reason in `warnings`) of an item whose card cannot be truthful (see `cardTruth.ts`) when a mesh is * guaranteed; `'observe'` changes nothing in the artifact and only records the verdict in `report.cardTruth` (what the backend reads to decide who gets an `item-lod/6` row). */ cardTruth?: 'apply' | 'observe'; /** `gbuffer/1` capture: the four G-buffer passes; defaults to the headless placements capture host. Injected by tests. */ captureGBuffer?: (captureGlb: Uint8Array, framing: ImpostorFraming, size?: number) => Promise; /** Atlas capture; defaults to the headless placements capture host. Injected by tests. */ captureAtlas?: (captureGlb: Uint8Array, framing: ImpostorFraming, size?: number, shading?: ImpostorShading) => Promise; onProgress?: (message: string) => void; } /** * Writes `simplified` with the first texture spec on the ladder whose file is strictly smaller than `aboveBytes`. * Returns what the last attempt measured when none is. */ export declare function writeSmallerLevel(model: ItemModel, simplified: SimplifiedLevel, cache: TextureCache, ladder: readonly LevelTextureSpec[], aboveBytes: number): Promise<{ written: WrittenLevel; rung: number; smaller: boolean; }>; /** Compile a static GLB into an item-lod/1 artifact and its objects. Deterministic: the same bytes give the same CIDs. */ export declare function compileItemLods(glb: Uint8Array, options: CompileItemLodOptions): Promise; /** * Which mesh the runtime draws at range when the item has no card, from the measured error of the emitted levels: `'level'` when a level is faithful (error at most 2 percent of the bounds * diagonal), else `'own-model'` when the source is small enough (at most 4000 triangles) for the runtime to draw the item itself from a document with no levels, else `'level'` when a level * at least passes the runtime's rule (at most 10 percent of the diagonal), else `'none'` (the card must stay). Older engines draw exactly this: with levels they draw a level that passes the * 10 percent rule (else the least-wrong one), with no levels and no impostor they draw the source model when it is at most 4000 triangles. */ export declare function meshGuarantee(levelErrors: readonly number[], diagonal: number, sourceTriangles: number): 'level' | 'own-model' | 'none'; export declare const itemLodObjectPath: (object: ItemLodObject) => string; /** `artifact.json` (the canonical bytes whose CID is `artifactCid`), `objects/.`, `report.json` and previews. */ export declare function writeItemLodOutput(directory: string, build: ItemLodBuild): Promise<{ artifactPath: string; files: string[]; }>;