# `helix item lods`: the item-lod/1 Runtime Artifact

The document schema is `helix.item-lod/1` and stays so (a runtime reads the schema id); the generator's own identity, the
`compiler` of a derivation key, is `item-lod/3` (`ITEM_LOD_COMPILER`): bump it on any change that alters the bytes written, because a
ready or failed Runtime Artifact is terminal for its key. 1 was the first generator, 2 round 2, 3 round 3 (one draw per render
state, vehicle LOD2 shell, a level that cannot reach its cap is omitted, an impostor that is not smaller than the source is omitted).

Round 4 kept `item-lod/3`: it only stopped declaring glTF extensions that nothing in a level uses (a textureless level now declares geometry
extensions alone, which is what lets the platform's upload scan clear it without a person looking; see the change journal). No ready row is
recompiled, so the bytes of a row that never reached ready may change without a new key.

```sh
helix item lods <packageId>[@version]  [--out <dir>] [--variant <id>] [--profile prop|vehicle] [--api-url <url>] [--json]
helix item lods --item <itemIdOrSlug>                       # the Package an Item currently points at
helix item lods --glb ./model.glb                           # a local static GLB (no Package identity recorded)
```

It compiles a published prop, Device or vehicle Package Version into up to two cheaper models and an octahedral impostor, so a
runtime can show something real, from a small first-load file, before (or instead of) the full GLB. A tier that does not
actually make the model cheaper is left out (see "Omitted levels"). It is the creator's
local preview and check. The backend optimisation worker is the source of truth for the catalogue; both run this same
compiler (`src/itemLod/`).

Avatars, characters and skinned add-ons are out of scope: they are skinned and already ship three LODs inside one GLB.
A skinned model is refused with a message that says so.

## Output

```
<out>/artifact.json                 canonical JSON (RFC 8785); its sha256 is the artifact CID
<out>/objects/<sha256>.glb          LOD1 and LOD2, whichever were emitted
<out>/objects/<sha256>.ktx2         the impostor atlas
<out>/report.json                   per-level triangles, bytes, caps, notes (not part of the contract)
<out>/previews/impostor.png         a human-readable atlas (not part of the contract)
```

Objects are content addressed: the file name is the hex digest of its bytes, the artifact refers to it as
`cid:sha256:<hex>`. The same input produces the same bytes, so the same CIDs (the specs and the sample run check this,
including the headless capture).

## Artifact shape

```jsonc
{ "schema": "helix.item-lod/1",
  "source": { "packageId": "…", "version": "1.0.1", "manifestCid": "cid:sha256:…", "form": null, "modelCid": "cid:sha256:…" },
  "profile": "prop",                                                      // or "vehicle"
  "bounds": { "min": [x, y, z], "max": [x, y, z] },
  "triangles": [12902, 3127, 153],                                        // [source, then one count per entry of levels]
  "levels": [                                                             // 0, 1 or 2 entries, nearest first
    { "lod": 1, "object": "cid:sha256:…", "triangles": 3127, "maxErrorM": 0.0012, "bytes": 466308, "textureMaxEdge": 512, "cap": 3225, "drawCalls": 1 },
    { "lod": 2, "object": "cid:sha256:…", "triangles": 153,  "maxErrorM": 0.032,  "bytes": 55372,  "textureMaxEdge": 256, "cap": 300,  "drawCalls": 1 } ],
  "impostor": { "object": "cid:sha256:…", "kind": "octahedral", "views": 8, "size": 512, "format": "ktx2-uastc",
                "center": [x, y, z], "radius": 0.31, "bytes": 69830 },      // null when it is not smaller than the source model
  "estimatedBytes": { "lod1": 814494, "lod2": 89180, "impostor": 349526 },   // lod1 / lod2 / impostor keys exist only for what is emitted
  "warnings": [] }                                                        // material notes, then one "LODn omitted: ..." per omitted tier
```

- `source.form` is `null` for the default model and the variant id when `--variant` picked one. Package, version and
  manifest CID are all `null` together for a local `--glb` compile.
- `maxErrorM` is the **measured** two-sided surface distance between the source and the level (source vertices to the
  level's triangles, and back), taken over the materials the level kept. It is not the simplifier's own estimate, which
  mixes in normals and UVs. A source part (one connected piece of one material) whose bounding box is under 2 percent of the
  item's longest extent is sub-visible detail (a 1 cm switch, a bolt, stitching) that every level drops by design; it is
  left out of the source-to-level direction, because a missing button is not a metre of error when the next lamp is a metre
  away. `report.json` carries both numbers per level: `maxErrorM` (this one) and `strictErrorM` (every vertex counted). A
  larger part that is dropped always counts.
- `drawCalls` (optional, a positive count) is the number of primitives, so of draw calls, the level costs: one per render
  state (see "One draw per render state" below), two at most for an ordinary item. Levels written by the earlier rounds do
  not have it; a reader treats a missing value as unknown.
- `bytes` is the file size to transfer. `estimatedBytes` is the approximate GPU-resident size: quantized vertex and index
  buffers plus textures transcoded to a 1 byte per texel block format with mips (the impostor's 349526 is 512 x 512 x 4/3).
- `levels` lists only the tiers that were emitted. **Read `levels[i].lod` (1 or 2), not the index**: when LOD1 is omitted and
  LOD2 is not, `levels` has one entry whose `lod` is 2. `levels[i].triangles === triangles[i + 1]`. With `levels` empty the
  runtime goes from the full model straight to the impostor.
- `levels[n].waived` appears only on levels written by the first compiler (a tiny source kept whole). The current compiler
  omits such a level instead.
- `profile` records which LOD1 budget applied. A reader of an artifact without `profile` or `lod` (first compiler) can treat
  it as `prop` with two levels, LOD1 then LOD2.
- `impostor` is `null` (and `estimatedBytes.impostor` absent) when the capture, encoded, is not smaller in bytes than the source
  GLB: for a tiny item the atlas costs more to fetch than the model. A document may then have no levels and no impostor at all;
  the runtime draws the model. `report.json` still records the capture (`impostor.bytes`, `coverage`, `omitted: true`) and the
  preview `impostor.png` is still written.
- The impostor's `center` and `radius` are the capture framing: every view is orthographic, `radius` wide, centred there.

## What each level is

Each level is a self-sufficient GLB: its own geometry, materials and **its own textures, none larger than what they replace**,
so the smallest available level is a small first-load file and the runtime can upgrade to the full GLB later. A level is
drawn in **one primitive per render state** (usually one opaque and one alpha-blended), not one per source material.

| | triangles | textures | kept maps | geometry |
|---|---|---|---|---|
| LOD1, prop | at most 25 percent of the source | longest edge at most 512 px | base colour, normal, metallic-roughness, emissive, packed ORM | meshopt per material, border-locked first |
| LOD1, vehicle | starts at max(5000, 10 percent of the source), widens (by half, up to a quarter) only while its measured error is over 10 percent of the longest extent | longest edge at most 512 px | as a prop | as a prop |
| LOD2 | at most 300, and aimed at half of the level above | longest edge at most 256 px | base colour, emissive | meshopt, then vertex clustering when edge collapse stalls |
| LOD2, vehicle | as above | as above | as above | the best of the per-material result and the visible shell of the whole vehicle clustered on one grid (see "Vehicle LOD2"); omitted when still over 25 percent of the longest extent away |
| impostor | 8 x 8 = 64 views in one atlas | 512 px | albedo | octahedral, full sphere |

- Both levels are stored as quantized geometry (16-bit positions in a node transform, 16-bit normals, 16-bit UVs when they
  fit 0..1) with `EXT_meshopt_compression` and `KHR_mesh_quantization`, both required, the same family the scene HLOD cells
  use. `KHR_texture_basisu` and `EXT_texture_webp` are declared (required) only when a level actually carries such a texture.
- A level texture is resampled or reused, never re-encoded larger. A source image whose longest edge is within the level's
  cap (512 or 256) is **reused byte for byte** (PNG, JPEG, WebP or KTX2, whatever the source had). A larger one is resampled
  with Lanczos (each edge snapped to a power of two) and encoded as KTX2, choosing per texture the smallest of ETC1S
  (quality 128), RDO-tuned UASTC (scalar 2) and plain UASTC whose decoded pixels reach a PSNR floor against the resampled
  image: 30 dB for colour maps, 34 dB for normal, metallic-roughness and occlusion maps. Plain UASTC is always acceptable.
  If that is still larger than the source image (a compact JPEG or WebP downscaled to KTX2 can be), the coarser candidate that
  is no larger than the source and clears 25 dB (colour) or 30 dB (data) wins instead.
  Shared textures are encoded once per compile. `report.json` lists, per texture, the method, size and PSNR.
- LOD2 drops the normal, occlusion and metallic-roughness maps; the material's roughness and metalness factors are
  multiplied by the dropped map's mean so the overall response stays in range.
- Materials keep their alpha mode, cutoff, double-sidedness, emissive strength, `KHR_texture_transform`, vertex colours
  and a second UV set. Other material extensions (clearcoat, sheen, specular, volume, ...) are dropped and listed in
  `warnings`. `KHR_materials_transmission` becomes alpha blending so glass does not turn into a solid panel.
- Inputs may be Draco, meshopt, KTX2/Basis, WebP, PNG or JPEG; they are decoded first. Meshes are baked into scene space
  per material (node transforms, instancing and mirroring included). Animation and morph targets are ignored; the levels
  are the rest pose. Point and line primitives are ignored.

### One draw per render state: the material atlas

A vehicle has 20 to 40 materials, so drawing each as its own primitive meant 20 to 40 draw calls per level. Every level
now merges its groups by render state into **at most one opaque and one alpha-blended primitive** (a lit and an unlit one
each when an item mixes unlit and lit materials; double-sided is applied to a primitive when any of its materials is, and
`report.json` says so), and gives the primitives one material set backed by one atlas texture per slot.

- Materials that agree on everything but where they read their texture are one **recipe**: same base colour, metallic-roughness,
  occlusion, normal and emissive images, same factors, same alpha mode and cutoff, same wrap. A recipe covers the part of its
  texture that its vertices actually use (its UV footprint, with `KHR_texture_transform` and the UV set applied), padded by a
  gutter of real neighbouring texels (4 px at 512, 2 px at 256), so filtering never reads another recipe's pixels.
- A recipe's footprint is **plain** (the UVs stay inside one tile), **tiled** (they repeat: baked as the repeats, up to 36
  cells and 12 per axis, wrapping as the texture says), **mean** (it repeats a texture more finely than the atlas can hold: the
  texture's mean colour) or a **swatch** (a factor-only material, or a footprint under 1.5 texels: a 4 x 4 block of its colour).
  Palette textures (a 64 x 4 strip that a whole car reads colours from) are plain recipes and several of them share one rectangle.
- Factors are **baked into the texels**: the base colour factor is multiplied in linear light, the roughness and metalness
  factors scale the metallic-roughness channels, the occlusion strength and the normal scale are applied, the emissive colour
  and strength are folded into one emissive texture and one shared emissive strength, and a hard alpha cutoff is baked into the
  alpha channel as 0 or 1, so a `MASK` primitive always uses a cutoff of 0.5. Rectangles get a share of the atlas by the surface area they paint,
  capped at their own source resolution, packed (shelf packing) into the smallest power-of-two box that holds them: 512 px at
  most at LOD1, 256 px at most at LOD2.
- Atlas textures are baked at the rectangle's resolution and encoded like any level texture, with one change: the PSNR floor
  is **surface weighted**, every pixel counting for the area its rectangle paints. Without it a 56 x 8 colour strip painting
  most of a car was judged as 0.1 percent of the atlas and ETC1S blended the white body into pink.
  The never-larger rule compares an atlas texture with the sum of the distinct images it replaces.
- When every material of a level is one recipe, nothing is baked: the level keeps the source materials (and the byte-for-byte
  reuse of a texture already within the cap), merged into at most the same primitives. `report.json` per level carries
  `primitives` and an `atlas` summary (size, recipes, swatches, recipes folded to a mean colour); the level notes say when
  single-sided and double-sided materials were merged.
- If the recipes cannot be packed at the minimum rectangle size the level is omitted (`AtlasOverflowError`) rather than
  written with a smear.

### How the triangle budget is spent

1. Vertices that differ only by a near-equal normal (30 degrees) are merged before simplification. Exporters split vertices on
   every normal discontinuity, and meshopt cannot collapse across those splits: a smooth ball stalled at 53 percent until this
   step. Hard edges stay split.
2. Each material keeps at least a floor (48 triangles at LOD1, 12 at LOD2, or all of them when it has fewer); the rest of the
   budget is shared by triangle count at LOD1 and by surface area at LOD2, so the body panels of a car get the budget at LOD2
   rather than the engine bay.
3. LOD1 simplifies each material with meshopt's attribute-aware simplifier on the normal-welded mesh: UVs and normals steer
   the collapses and UV seams act as borders, so a triangle never spans two UV islands and the 512 px textures stay valid. If it
   stalls above the share the compiler retries without the border lock, then with `Prune`, then clusters vertices on a grid
   (merging only vertices of the same UV island and the same eighth of the texture, and a cluster takes the UVs of the vertex
   nearest its centre rather than their average, so a cell never lands between two UV islands and a triangle never reads
   the gap between them).
   LOD2 collapses the **position-welded** geometry instead: vertices that share a position are one vertex, so seams are interior
   edges. At a few hundred triangles the attribute-aware pass treats every seam as an open border and eats the surface along it
   (a UV sphere reduced to 285 triangles kept half its area; welded, the same sphere keeps 97 percent and measures 0.05 of its
   radius). Each surviving corner then takes the original vertex (wedge) at that position that agrees best with the triangle's
   other corners in UV and normal; LOD2 carries only a 256 px base colour, so a few smeared UVs there cost little. A share of 400
   triangles or fewer is spent per connected part, in proportion to its area (at least 12 triangles each, a box; the smallest
   parts are dropped when there are more than the share can draw, and a part that stalls above its share leaves the result to the
   clustering fallback): one pass over the whole material spends it on whichever collapses are cheapest, and with four wheels in
   one material it erases three of them.
4. If the floors alone do not fit, the smallest-area materials are dropped (listed in `report.json`) until the cap holds.
5. **Refinement (LOD1).** A budget shared by weight starves a thin or sparse material (a light strip of six separate parts, a
   row of books) which then collapses or clusters into the wrong place: the Audi R8's daytime-running-light strip sat 1.4 m from
   where it belongs in a 4.4 m car. While the measured error is over 10 percent of the longest extent, the groups that are
   furthest from the source are promised twice the triangles they got (up to 80 percent of the budget, worst first) and the others
   share the rest. A pass that does not lower the error by at least a tenth, drops a material or breaks the cap is discarded,
   and the level notes say `refined: ...`.

### Vehicle LOD2

A vehicle has dozens of materials, so the per-material LOD2 budget leaves the body a handful of triangles and an open shell
(measured error 56 to 96 percent of the extent in round 2). The vehicle profile also builds a **shell**: the triangles visible
from outside (the surface rasterised into a voxel grid, empty space flooded from the edge; seats and engine bays fall away,
windows keep the cabin sealed) are vertex-clustered on one grid shared by every material, as fine as 300 triangles allow, with
and without the visibility filter and on sixteen placements of the grid (where the cell walls fall decides which vertices
merge: the same budget lands 20 to 60 percent closer on some placements). The shell is written in flat colours (below), so its
cells are free to merge vertices of different UV islands. The candidate with the smallest **measured** error
wins, never one that breaks the 300 triangle cap. If the winner is still more than **25 percent** of the longest extent from
the source, the tier is omitted (the
runtime goes from LOD1 to the impostor): a 300 triangle car with a wheel missing is not a level worth shipping.

A shell's triangles join vertices from different UV islands of the single texture sheet most vehicle exporters use, so a
texture read across one triangle smears paint, glass and trim into one grey (a blue car came out white-grey). A shell level is
therefore written in **flat colours**: every material becomes one textureless material whose colour is the mean, in linear
light and weighted by area, of what its source triangles actually show (roughness, metalness and glow folded into factors the
same way). Such a LOD2 is a handful of swatches, 7 to 8 KB.

### Omitted levels

Each tier is measured against the level above it (the source for the first emitted tier; LOD1 for LOD2 when LOD1 is
emitted, else the source). It is **omitted** from `levels` and from the objects when:

1. it cuts under 50 percent of the triangles of the level above it (a 60 triangle Device cannot be cut to 15 without breaking
   its shape, so it has no mesh levels at all), or
2. its GLB cannot be made strictly smaller in bytes than the level above's file. For LOD1 the compiler first climbs a texture
   ladder: the full set; the normal, metallic-roughness and occlusion maps at 256 px; colour and emissive maps only (the
   dropped maps fold into the material factors). `report.json` records the rung used (`textureRung`). If even the smallest
   file is not smaller, the tier is omitted.

3. (vehicles) its measured error is over 25 percent of the longest extent even as the best 300 triangle shell, or
4. the simplifier could not reach its cap (a flat-shaded shape whose every face is its own UV island and normal stalls above it):
   a level over its cap fails the caps check, and a failed item is worse than a tier left out. The clustering fallback first
   relaxes its keys (UV island and texture eighth, then island only, then none) and a per-material floor never asks for more than
   that material's share, so this is the last resort rather than the usual outcome.

The **impostor** is held to the same test against the source: it is omitted when its encoded atlas is not smaller in bytes than
the source GLB (see "Artifact shape"). A compile never fails because of what it left out.

Every omission adds a warning (`LOD1 omitted: ...`) and an entry in `report.json` `omitted[]` with the triangles and bytes
the tier would have had. The invariant every emitted artifact holds: `source bytes > LOD1 bytes > LOD2 bytes`, with whichever
tiers exist.

### Caps

`checkItemLodCaps` and the command's summary check: LOD1 within its profile limit (25 percent of the source for a prop,
max(5000, 25 percent) for a vehicle, whose 10 percent start can widen to that when the error bound needs it; the
`warnings` then say so), LOD2 at most 300, each level cutting at least half the triangles above it and strictly
smaller in bytes than it, textures at most 512 and 256 px, impostor 8 views at 512 px. `--profile vehicle` is chosen
automatically for a Package of type `vehicle`; `compileItemLods(glb, { source, profile: 'vehicle' })` selects it for callers.

## Impostor

64 orthographic views on the octahedral full-sphere layout the tree impostors use (`oct(x, z)` over an 8 x 8 grid, view
`(x, y)` at tile `(x, y)`, rows bottom first), albedo only, encoded as UASTC KTX2 with mips. Colour is dilated into the
empty gutters so filtering shows no dark fringes. Transparent materials are drawn opaque (a glass tint is what survives at
range); cutouts keep their alpha test.

Capture runs in the shared placements capture host (`src/placements/captureHost.ts`): bundled headless Chromium, localhost
only, one browser at a time under the host slot cap, never the system Chrome. An `albedo` or `lit/1` impostor has no normal
map, so a runtime cannot light it for the scene it stands in; the `gbuffer/1` impostor below is that second object.

### `gbuffer/1`: a runtime-lit impostor (`item-lod/5`, `hemi-oct/1`)

`compileItemLods(glb, { source, shading: 'gbuffer/1' })` bakes what a light needs instead of a light: the surface, not its
shading. It is a contract of its own because it is neither read like `lit/1` nor laid out like it. `'gbuffer/1'` is listed in
`ITEM_LOD_SHADINGS` (phase 2), which is what lets a backend worker bake it under `item-lod/5`: the worker refuses a contract whose
shading the installed CLI does not list. The backend compiles `item-lod/5` next to `/4` and `/3` and serves it only to a read that
declares `gbuffer/1`; an engine before it keeps its `lit/1` or albedo rendition.

* **Layout `hemi-oct/1`** (`impostor.layout`): 8 x 8 views over the UPPER hemisphere only. Frame `(i, j)` has `u = 2i/7 - 1`,
  `v = 2j/7 - 1`, `x = (u + v)/2`, `z = (u - v)/2`, `y = 1 - |x| - |z|`, normalised. The outer ring of 28 frames lies exactly on the
  horizon (gaps of 9.5 to 16.2 degrees of azimuth) and the four corners look along the item axes. A viewer at or below the
  horizon reads the ring, so it is looked at from where it stands. The full-sphere `oct/1` layout the other shadings use
  spends half its frames below the ground and its nearest ring sat at 9.5 to 13 degrees ELEVATION: a car seen from 0.5 degrees
  was drawn from above, with roof and bonnet over-represented, which was the whole of the +7 to +25 percent over-brightness
  measured before the layout changed (a camera-elevation sweep of the same atlas; the lab reproduced it and the layout closes it).
* **Maps** (`impostor.maps`, one KTX2 UASTC object each, 512 px, mips): `impostor.object` is `A`, sRGB albedo with the
  coverage in alpha; `maps.surface` is `B`, linear: view-space normal x and y (z is rebuilt as `sqrt(1 - x² - y²)`), roughness,
  metalness; `maps.emissive` is `C`, sRGB, emissive radiance / 4 in RGB (`scale: 0.25`) and the clear coat amount in alpha
  (`clearcoat`), present only when at least 8 texels glow or are coated. View-space normals mean each baked view's own camera
  frame (x right, y up, z to the viewer); the engine turns them into item space per frame and then into the scene's view space.
* **Passes**: four captures per view (albedo, normal, material, emissive) of the source's own PBR values, written by small
  `ShaderMaterial`s that output the quantity instead of a colour; supersampled (`IMPOSTOR_SSAA`) and reduced, then each map
  dilated into the empty texels of its view cell so filtering at a silhouette mixes in no black. Rows are bottom first.
* **Artifact**: `impostor.shading: "gbuffer/1"`, `impostor.layout: "hemi-oct/1"`, `impostor.maps`, no `bakeScale`; `compiler`
  is `item-lod/5` (`ITEM_LOD_COMPILER_FOR_SHADING`). The schema id stays `helix.item-lod/1`; a reader that does not know
  `impostor.shading` must not draw the document, which is why the backend serves it only to a declaration.
* **Omission rule**: the `lit/1` rule (omit when the atlas is not smaller than the source GLB) would drop the impostor of a heavy
  item with small textures, which has no other far representation and whose far placements are two triangles each, because the
  impostor now carries up to three maps. A `gbuffer/1` impostor is omitted only when the source is at most 300 triangles AND
  the maps are at least twice the source bytes (`GBUFFER_MIN_TRIANGLES`, `GBUFFER_BYTES_SLACK`);
  `estimatedBytes.impostor` is the resident cost of all the maps, and `report.json` has `shading` and `maps`.
* **Measured** (2026-10-11, lab `run/impostor-gbuffer-2026-10-11`): the sedan baked on this Mac's SwiftShader capture host takes
  about 14 s for the impostor (23 s for the whole compile with both LODs): `A` 105 KB, `B` 131 KB, `C` 12 KB.

Tests: `src/itemLod/gbuffer.spec.ts` (layout, packing, dilation, KTX2 encode; two real-browser captures) and
`src/itemLod/artifact.spec.ts` "gbuffer/1 impostor" (artifact shape, validation, omission rule, the `lit/1` rule unchanged).

### Where a card is not truthful: `item-lod/6` (`cardTruth`)

A card stores a surface per texel and the scene lights it, so three kinds of item have no truthful card: **see-through glass or water**
(a card is a cutout: a pane is solid or stippled, never see-through), **a mirror** (an opaque material that is metallic and smooth reflects the
sky; the Black Frame Glass Wall's `MI_Glass_Opaque_01F` is metallic 0.949, roughness 0, and a card re-lights a few degrees of normal error into a
flat grey panel) and **thin emissive parts** (a neon tube 1.5 cm wide in a 3.6 cm texel: coverage 0.2 to 0.4, so the glowing area is a third too
small and dim). For those the far representation is a mesh.

`compileItemLods(glb, { shading: 'gbuffer/1', cardTruth: 'apply' })` (`src/itemLod/cardTruth.ts`) leaves the impostor out (`impostor: null`) of such an item
and says why in `warnings` (`"no card: mirror 42.7% of area (MI_Glass_Opaque_01F)"`). The document format does not change, so every engine
that reads item-lod documents already draws it (levels, or the item's own model). `cardTruth: 'observe'` changes nothing in the artifact and only records the
verdict in `report.cardTruth`; the backend compiles `item-lod/5` with it to learn which versions need a `/6` row. `helix item lods --shading gbuffer/1 --card-truth apply|observe`
runs the same locally. `ITEM_LOD_CARD_TRUTH` (export) is true in a CLI that has it; a worker checks it before compiling `/6`.

* **The rule.** The census is by surface area (sum of triangle areas of a material over every triangle; sampled, at most 2048 triangles per material, centroid UVs
  for texture-driven values). The card is dropped when any of: a translucent BLEND/transmission material (alpha between 0.03 and 0.9; a BLEND flag on a solid or an
  invisible decal is not glass) covers **at least 15 percent**; an opaque material with metallic at least 0.9 and roughness at most 0.1 covers **at least 30 percent**;
  or, from the capture, the glowing texels (emissive floor of the emissive map) with a coverage under 0.5 **outnumber** those at or over it (and are at least 1 percent
  of the covered texels). Glass and mirror need no capture, so the capture is skipped for them. Vehicles keep their card: their glass and lamps are a small share.
* **Thresholds are from the catalogue, not a guess.** Census of the 1,091 distinct models behind the 1,167 public item-lod versions on helix3 (2026-10-13): glass 15 models at
  0.21 to 1.00 and the next at 0.12 (a Lamborghini, a McLaren); mirror 3 at 0.33 to 0.88 and the next at 0.25 and 0.21 (glossy car paint, chrome trim); thin emissive 3 at 0.78 to 0.98
  of glowing texels and the next at 0.32 (a table lamp). `scripts/item-lod-card-census.mjs` (material census), `item-lod-thin-emissive.mjs` (capture census) and
  `item-lod-card-compile.mjs` (the `/6` compile, to count who gets a mesh) reproduce it.
* **A mesh is guaranteed or the card stays.** After the levels are measured: a level within 2 percent of the bounds diagonal is faithful and stays (the glass wall's 66 triangle LOD1 is 2.4 percent: 20 cm off a 30 cm wall, so it draws as itself); else a source of at most
  4,000 triangles is drawn as itself, so the failing levels are dropped and the document is a valid empty one (`levels: []`, `impostor: null`, as for a tiny item); else a level within the runtime's
  10 percent rule stays; else nothing can draw and the card is **kept**, with `"card kept: ..."` in `warnings`. `report.cardTruth.mesh` is `level`, `own-model` or `none`.
* **Rollout.** The backend (`docs/architecture/item-lod.md` there) queues `item-lod/6` only for versions the `/5` compile flags or the backfill lists, serves it ahead of `/5` to a
  read that declares `gbuffer/1`, and reverts with `ITEM_LOD_CARD_TRUTH_SERVE_ENABLED=false`.

Tests: `src/itemLod/cardTruth.spec.ts` (census of a mirror panel, a BLEND pane, transmission, a thin tube and a normal prop; `meshGuarantee`; the compile with `apply`, `observe`, lit and albedo).

## Textures that cannot be decoded

libvips builds differ: the same lossy WebP can decode on one host and answer `webp2vips: unable to read pixels` on another. Before
anything reads a raster texture, the compiler decodes each once (`src/itemLod/repair.ts`). One that fails is read leniently and
re-encoded as a PNG for the rest of the compile; one that still fails is dropped, and each material map that used it is baked from
the material's factors. Either way the artifact says so in `warnings` and the item compiles. The source GLB is never changed.

## Source resolution

`<packageId>@<version>` reads the Package Version from `GET /api/v1/continuum/public/packages/:id/versions/:version`, chooses
the model variant (`--variant`, else the balanced web profile, else the largest GLB) and downloads it from
`GET /api/v1/continuum/public/objects/:cid`, verifying the CID. `--item` follows an Item's `continuumPackagePin`. Packages of
type `character` and `addon` are refused up front.

## Programmatic entry

The compiler is a package subpath, for the backend optimisation worker and other callers (no CLI code is loaded):

```ts
import { compileItemLods, validateItemLodArtifact, checkItemLodCaps } from '@hypersoniclabs/helix-cli/item-lod';
import type { ItemLodArtifact, ItemLodBuild } from '@hypersoniclabs/helix-cli/item-lod';

const build: ItemLodBuild = await compileItemLods(glbBytes, { source: { packageId, version, manifestCid, form: null, modelCid }, profile: 'prop' /* or 'vehicle' */ });
// build.artifact (ItemLodArtifact), build.artifactBytes / build.artifactCid, build.objects[] ({ cid, mediaType, bytes, role }),
// build.report ({ caps: { ok, failures, waivers }, lod1 / lod2 (null when omitted), omitted[], per-texture detail })
```

`compileItemLods` throws `SkinnedModelError` for skinned input. The impostor capture needs the bundled headless Chromium
(`playwright`); pass `captureAtlas` to supply the 8 x 8 RGBA atlas yourself. `src/itemLod/packageExport.spec.ts` imports it by the
package name.

## Not in this command

The backend worker compiler registration and catalogue backfill, the engine's far-representation tiers, and the site's HD
toggle are separate lanes (SCENE-PIPELINE-DESIGN section 4.5).
