/** * MIRRORED, byte for byte, in helix-creator-cli `src/bakedPack/hxb.ts`. Change both together. * * HXB1 — the PACKED baked-field container. The reader of the JSON keyframe store (`tod/keyframes.ts`) stays for * every artifact published before this; HXB1 is what `helix.visuals.bake..bin` files carry, and what a bake is * packed into by `scripts/pack-baked-field.mjs`. * * WHY IT EXISTS. The JSON artifact is 11.5 MB raw / 4.1 MB brotli for Hyperspace and sits on the first-playable path, * yet 8.5 of those 8.6 MB are the visibility GEOMETRY (octahedral depth tiles + occlusion volume) that the stock * sampler never reads — and Hyperspace plays on the stock sampler on every tier. The lighting itself is 104 KB of * float32. So the container splits by who needs what: * * field the SH keys + practicals, float16, coarse level first and refinement cells after. ALL a stock tier needs. * geometry depth / params / mask / occlusion / offsets / validity. Fetched only when a visibility tier boots. * low the same lighting on a coarser lattice (resampled), for phones: no refinement, no geometry. * * FILE LAYOUT (little endian): * * "HXB1" u32 headerBytes header JSON (UTF-8) payload * * The header lists every section as `{ o, n }` into the payload, in the order they were written, so a streaming * reader can act on each section the moment its bytes land. `ph: 0` sections are the first-playable set; everything * else is refinement and may arrive after the world is already lit. * * SH CHUNKS. A volume's lattice is refined in `levels` steps: level `l` holds the probes whose index is a multiple of * `2^(levels-1-l)` on every axis (the last index of an axis is always included, so the sets are nested and the box * edge is always sampled). Level 0 is ONE chunk — the coarse field. Level `l > 0` is split into `cell`-sized blocks * of probes, ordered by distance from the header's `focus`, and carries only the probes level `l - 1` did not have. * Inside a chunk: `[channel][coefficient 0..26][probe]` float16, channel = key (in hour order) then practicals. * * GEOMETRY SECTIONS are float16 where the value tolerates it, lane-planar and byte-shuffled, then deflate-raw. * The second depth lane is stored as the VARIANCE `E[d²] - E[d]²` rather than `E[d²]`, and the reader adds back the * square of the DECODED mean. The sampler computes `moments.y - mean²` from the pair it is handed, so what survives * is the variance itself (to float16 precision), whatever float16 did to the mean: two half-rounded large numbers * would have left it a difference of two errors. */ import type { ProbeVolumeMetadata } from './packTypes.js'; export declare const HXB_MAGIC = "HXB1"; export declare const HXB_VERSION = 1; /** Floats per probe, mirrored — this module stays free of the GL side so a Node tool can bundle it. */ export declare const HXB_SH_FLOATS = 27; export type HxbKind = 'field' | 'geometry' | 'low'; export type HxbCodec = 'raw' | 'deflate'; export type Vec3 = [number, number, number]; export interface HxbKeyInfo { h: number; e: number; a: number; } export interface HxbGeometryInfo { octPadded: number; paramTexels: number; maskCells: Vec3; /** Floats per depth texel the source carried (3 now, 2 on an artifact older than the miss lane). */ depthChannels: number; occlusion: { voxels: Vec3; scale: Vec3; offset: Vec3; packed: boolean; } | null; offsets: boolean; validity: boolean; } export interface HxbVolumeInfo { volume: ProbeVolumeMetadata | null; firstProbe: number; blendMetres: number; padMin: Vec3; padMax: Vec3; /** Refinement levels of an SH volume (1 = the coarse level is the whole lattice). 0 on a geometry file. */ levels: number; /** Probes per refinement block, per axis. */ cell: Vec3; geometry: HxbGeometryInfo | null; } export type HxbSectionType = 'sh' | 'depth' | 'params' | 'mask' | 'occ' | 'offsets' | 'validity'; export interface HxbSection { t: HxbSectionType; vol: number; /** Refinement level (sh only). */ lvl?: number; /** Block index per axis (sh refinement only; level 0 is one chunk with no block). */ blk?: Vec3; /** 0 = first-playable, 1 = refinement / optional. */ ph: 0 | 1; /** Payload offset and stored length. */ o: number; n: number; /** Decoded length in bytes. */ raw: number; c: HxbCodec; /** Element encoding of the decoded bytes. */ e: 'f16' | 'f32' | 'u8' | 'occ8'; } export interface HxbHeader { v: typeof HXB_VERSION; kind: HxbKind; /** Content id of the lighting: the field and its geometry file carry the same one, so a stale pair is refused. */ bakeId: string; probeCount: number; keys: HxbKeyInfo[]; practicals: boolean; volumes: HxbVolumeInfo[]; /** Where refinement starts: nearest blocks first. World-space metres. */ focus: Vec3; sections: HxbSection[]; /** Payload bytes in total — a truncated download is caught by this, not by a parse error three sections later. */ bytes: number; } /** IEEE half, round to nearest even; saturates at +-65504 instead of overflowing to infinity. */ export declare function toHalf(value: number): number; export declare function fromHalf(h: number): number; export declare const probeIndex: (nx: number, ny: number, ix: number, iy: number, iz: number) => number; /** Stride of level `l` of `levels` on every axis. */ export declare const levelStride: (levels: number, level: number) => number; /** True when index `i` of an axis of `n` probes belongs to the lattice at `stride`. */ export declare const onStride: (i: number, n: number, stride: number) => boolean; /** The axis indices a level holds. */ export declare function axisSet(n: number, stride: number): number[]; export declare const blocksPerAxis: (n: number, cell: number) => number; /** * The probes of one chunk, in chunk order (z, then y, then x). Level 0 (`block` null) is every probe on the * coarsest lattice; level `l > 0` is the probes in `block` that are on level `l` and not on level `l - 1`. */ export declare function chunkProbes(dims: Vec3, levels: number, level: number, cell: Vec3, block: Vec3 | null): number[]; /** The number of levels that brings the coarsest lattice at or under `coarseProbes` probes (1 = no refinement). */ export declare function levelsFor(dims: Vec3, coarseProbes: number, maxLevels?: number): number; /** Lane-major to byte-planar: all low bytes, then all high bytes — what makes float16 data deflate. */ export declare function shuffle16(bytes: Uint8Array): Uint8Array; export declare function unshuffle16(bytes: Uint8Array): Uint8Array; export declare function f16Bytes(values: ArrayLike): Uint8Array; export declare function f16Floats(bytes: Uint8Array): Float32Array; export declare function writeContainer(header: HxbHeader, payload: Uint8Array): Uint8Array; /** Bytes before the header JSON, and the header JSON's own length, from the first 8 bytes. Null = not HXB1. */ export declare function readPreamble(first8: Uint8Array): number | null; export declare function parseHeader(bytes: Uint8Array): HxbHeader; /** Sniffs a buffer: HXB1 magic, or false (a JSON store starts with `{`). */ export declare function isHxb(bytes: Uint8Array): boolean;