import { type Csm2Mesh } from '../csm2'; import type { Cs2MaterialRecord, Cs2TextureRecord } from '../types'; import { type BuildingColors } from './buildingColors'; export declare const BUILDING_PROTOTYPES_SCHEMA: "helix.cs2-building-prototypes/1"; export type WallTintMode = 'auto' | 'off'; /** The stand-in for a missing `_ControlMask`: every texel is the red region (the scheme's main wall colour) at full weight. */ export declare const WALL_MASK: readonly [number, number, number, number]; /** True when some material of the bundle names a `_ControlMask` texture: the capture exported the masks, so no stand-in is needed. */ export declare function bundleHasControlMasks(materials: Iterable): boolean; /** An RGBA mask of `texels` texels, every one `WALL_MASK`. */ export declare function wallMask(texels: number): Uint8Array; export interface BuildingPrototypeOptions { /** The source-v2 bundle holding `meshes-v2/` and `materials-v2/` (the folder `city import cs2` reads). */ bundle: string; /** Where `buildings/` is written. */ out: string; /** Prefab name -> how many buildings place it (colourway count follows it). */ prefabs: ReadonlyMap; /** The captured per-instance ColorSets (`readBuildingColors(bundle)`); absent: the scheme stand-in colours every colourway. */ colors?: BuildingColors | null; /** Prefab name -> its buildings (city-source id and cs2 entity id), so colourways are chosen from the colours those instances wear. */ instances?: ReadonlyMap>; /** Name of the colourway assignment written under `buildings/` (default `colorways.json`; sharded runs write one each and merge them). */ colorwaysName?: string; /** A prototype above this many triangles is simplified per material group (default 20,000). */ maxTriangles?: number; /** Longest edge of a colour map (default 1024) and of a normal / ORM map (default 512). */ maxAlbedoEdge?: number; maxDataEdge?: number; /** Triangle budget and texture edge of the HLOD bake source (defaults 5,000 and 256). */ bakeTriangles?: number; bakeEdge?: number; /** * A folder holding the game's own authored LODs (`lod2/prefab-meshes-v2.json`, the CS2 LOD capture). A prefab with an authored LOD2 carries it * in its bake source as the HLOD shape (`HLOD_PROXY_EXTRA`): the distant building is CS2's clean low-detail shell, painted from the full model. */ lodDir?: string; /** Colourways per prefab never exceed this (default 4). */ maxVariants?: number; /** * Where the capture exported no `_ControlMask` (a whole bundle: Granit's source-v2 bundle has 6,514 materials and not one), `auto` (the default) * tints each surface material with the scheme's main wall colour as if the whole map were wall (`WALL_MASK`), so a converted city is coloured * and not a lifted grey. A bundle that carries control masks is untouched (the real mask decides what is wall). `off` keeps the grey. */ wallTint?: WallTintMode; /** A prefab wider than this (metres, X or Z) is cut into tiles of at most about this size (default 640; a streamed cell is limited to 1,024 m). */ maxSideM?: number; concurrency?: number; /** Name of the index written under `buildings/` (default `prototypes.json`); sharded runs write one each and merge them. */ indexName?: string; log?: (line: string) => void; } export interface PrototypeVariantRecord { k: number; uri: string; sha256: string; bytes: number; scheme: string; textures: string[]; /** glTF primitives (one draw call each) in this model; absent in an index written before the field existed. */ draws?: number; } export interface PrototypeRecord { prefab: string; instances: number; status: 'ok' | 'no-mesh' | 'no-geometry' | 'failed'; reason?: string; sourceTriangles: number; triangles: number; bounds?: { min: [number, number, number]; max: [number, number, number]; }; variants: PrototypeVariantRecord[]; /** The self-contained, small colourway the distant HLOD bake reads (`hlod.bakeResource`): embedded textures, a few thousand triangles. */ bake?: PrototypeVariantRecord & { triangles: number; proxy?: { kind: string; triangles: number; }; }; /** Material groups dropped (decals) and groups drawn as flat factors. */ dropped: number; flat: number; tinted: boolean; /** A prefab wider than `maxSideM` is cut into tiles, each its own record (`#`, `tileOf` the prefab): the base record lists them and holds no model. */ tiles?: string[]; tileOf?: string; } export interface PrototypeIndex { schema: typeof BUILDING_PROTOTYPES_SCHEMA; options: Record; totals: { prefabs: number; ok: number; failed: number; noMesh: number; glbs: number; textures: number; glbBytes: number; textureBytes: number; }; prototypes: PrototypeRecord[]; } /** CS2 DXT5nm -> plain RGB tangent-space normal: X from alpha, Y from green, Z rebuilt (never read from the blue channel). */ export declare function decodeDxt5nm(rgba: Uint8Array): Uint8Array; /** * HDRP mask map (R metallic, G occlusion, A smoothness) -> glTF ORM (R occlusion, G roughness, B metal). Roughness is floored at * ROUGHNESS_FLOOR: CS2 window maps carry smoothness 1.0, a perfect mirror, and a mirror facade reflects only the dark street canyon * (a whole tower read black from the ground), where the game's HDRP shows the sky through its own reflection probes. */ export declare const ROUGHNESS_FLOOR = 0.25; export declare function maskToOrm(rgba: Uint8Array): Uint8Array; /** * Resamples a straight (non-premultiplied) RGBA image channel by channel. `sharp` premultiplies by alpha for every resize, which is * right for a colour map and WRONG for a data map whose alpha is a payload: a DXT5nm normal keeps X in alpha, a `_MaskMap` keeps * smoothness there, a `_ControlMask` keeps a fourth region there. Premultiplying zeroed the red and blue regions of every control * mask (their alpha is 0 over most of the sheet), so only the few alpha-255 islands were ever recoloured: a patchwork of bands and * blotches on a facade that was otherwise left a dark grey. Downscales average the covered source area (a box filter); upscales * and `nearest` repeat the nearest texel, which is what a region mask wants. */ export declare function resampleStraight(rgba: Uint8Array, width: number, height: number, targetWidth: number, targetHeight: number, kernel?: 'box' | 'nearest'): Uint8Array; /** A PNG as straight RGBA (alpha is a payload, never coverage), fitted inside `edge` and never enlarged. */ export declare function readStraightRgba(file: string, edge: number, kernel?: 'box' | 'nearest'): Promise<{ data: Uint8Array; width: number; height: number; }>; /** * The captured colour maps hold LINEAR values. The exporter reads them back through a linear render target, which decodes the sRGB * authoring on the way (every record says `storageColorSpace: "linear"`; the byte histograms of the 2048 px colour sheets are * combed at the bright end exactly as an sRGB -> linear 8-bit conversion leaves them; the sheets average sRGB 14 to 90, i.e. albedo * 0.005 to 0.1 read as sRGB but 0.06 to 0.4 read as linear, which is what concrete, brick and plaster are). Everything downstream * (the KTX2 transfer flag, the tint maths, the engine) treats a colour map as sRGB, so the bytes are encoded to sRGB once, here. * Reading them as sRGB instead decoded them twice: every facade came out dark, and a 4x "exposure" lift papered over it. */ export declare function capturedLinearToSrgb(rgba: Uint8Array): Uint8Array; /** * The game's own maths, with the stand-in ColorSet: inside a control-mask region the (sRGB-encoded) base map is MULTIPLIED by the * scheme colour, `albedo * (1 + sum w_i (colour_i - 1))` in linear light (`tintAlbedo`), so a dark tile stays dark and a pale one pale * and the sheet keeps all its own detail; outside every region (a window, a door, painted trim) the captured albedo stays. Alpha is * untouched. `mask` is the straight control mask at the colour map's size: R, G, B are the three colour regions and its alpha is a * fourth region that carries no colour, so it is never read as coverage. */ export declare function tintFacade(albedo: Uint8Array, mask: Uint8Array, colours: readonly [number, number, number][]): Uint8Array; /** * The CS2 colour maps are dark detail sheets (sRGB means of 14 to 90) that the game's HDRP exposure brightens; HELIX lights are * calibrated for albedo around 0.2 to 0.5, so a map whose opaque pixels average below 0.2 linear is lifted by `0.2 / mean`, at most 4x. */ export declare function exposeAlbedo(rgba: Uint8Array): Uint8Array; /** Eases every texel below DARK_FLOOR toward DARK_FILL (a window map's opaque spandrels and curtains are RGB 14: whole towers read black). */ export declare function easeDarks(rgba: Uint8Array): Uint8Array; /** * CS2 window and curtain maps keep their COVERAGE in alpha (a curtain is opaque where it hangs and transparent over clear glass), and * the RGB under a transparent texel is 0. HELIX near models draw opaque, so the alpha was dropped and every clear pane read black * (whole glass towers and dark-base facades at street level). The map is composited over `fill` (linear RGB; default the mean of its * own opaque texels) so a transparent texel becomes the glass or the surrounding wall rather than black. Alpha is set to 255. */ export declare function flattenAlpha(rgba: Uint8Array, fill?: readonly [number, number, number]): Uint8Array; /** The glass a window map is composited over: a daylight facade pane, mid blue-grey (sRGB hex), not the black a transparent texel holds. */ export declare const WINDOW_GLASS_HEX = "#51697a"; /** A pane is glossy, not a mirror: at 0.08 a dielectric reflected only the dark street canyon and read black from the ground. */ export declare const WINDOW_ROUGHNESS = 0.2; export type MaterialClass = 'decal' | 'glass' | 'water' | 'window' | 'grass' | 'surface'; export declare function classifyMaterial(record: Cs2MaterialRecord | null, surfaceName?: string): MaterialClass; interface GroupPlan { /** Index into mesh.groups. */ group: number; /** The CSM2 group's global mesh index (what the captured per-instance ColorSets are keyed by). */ meshIndex: number; cls: MaterialClass; record: Cs2MaterialRecord | null; surface?: string; /** Texture records by role, null where the material captured none. */ albedo: Cs2TextureRecord | null; normal: Cs2TextureRecord | null; orm: Cs2TextureRecord | null; control: Cs2TextureRecord | null; /** No control mask was captured for this bundle: tint the whole surface with the scheme's wall colour (`WALL_MASK`). */ wall: boolean; /** Primitives with equal keys share one glTF material. */ key: string; } /** * Per-group simplification toward a triangle budget through the shared building LOD simplifier (`generateCsm2Lods`: border * locked, extreme vertices locked, an error limit relative to each group). A prefab at or under the budget is returned whole; * a mesh the simplifier refuses keeps its source triangles rather than failing the building. */ export declare function simplifyGroups(mesh: Csm2Mesh, groups: number[], maxTriangles: number, error?: { relativeError: number; maxErrorM: number; }): Promise>; /** * `[error multiplier, lock open borders, positions only, prune isolated components]` tried in turn by `simplifyGroups` (1 = the caller's limit). The later steps release the * borders and then drop the normals and UVs from the error: a prefab drawn as a triangle soup (a vertex per triangle corner, 1.7 vertices per * triangle on the 580,783-triangle Pacifica landmark tower) cannot collapse through its attribute seams at any error, and the last step lets the * simplifier prune whole isolated panels (a mesh of 230,000 separate quads has a floor of two triangles each until they may go). */ export declare const SIMPLIFY_STEPS: readonly (readonly [number, boolean, boolean, boolean])[]; /** What the bake source names its authored shell (`HLOD_PROXY_EXTRA`). */ export declare const PROXY_KIND = "cs2-lod2"; export interface ProxyShell { positions: Float32Array; indices: Uint32Array; } /** * The authored LOD2 as an HLOD shell, or null when it cannot stand in for the model: empty, non-finite, or not the same building (its bounds * must sit within 10% of the model's extent, at least 2 m, on every side; a LOD of a different variant or frame would paint the wrong place). */ export declare function authoredProxy(mesh: Csm2Mesh | null, bounds: { min: number[]; max: number[]; }): ProxyShell | null; /** A result within this multiple of the triangle budget is accepted. */ export declare const SIMPLIFY_OVERSHOOT = 8; /** * Cuts a mesh into a grid of tiles by triangle centroid when it is wider than `maxSideM` on X or Z, so no tile model is wider than a * streamed cell may be (an airport is 1.3 km across: one model, one cell, over the 1,024 m gate). Vertex arrays are shared; each tile * carries its own index list and groups. A mesh that already fits returns null. A triangle longer than a tile still spans it: the * caller measures the tile it actually built. */ export declare function splitMeshByTiles(mesh: Csm2Mesh, maxSideM: number): Csm2Mesh[] | null; interface Primitive { key: string; positions: Float32Array; normals: Float32Array; uvs: Float32Array; indices: Uint32Array; plan: GroupPlan; /** The ground of a flat (uncaptured) surface (`splitGroundFaces`): it takes the ground albedo (`flatGroundLinear`), not the wall's concrete. */ ground?: boolean; } /** A face whose normal is within ~26 degrees of straight up can be ground. */ export declare const GROUND_NORMAL_Y = 0.9; /** * ...and is ground when it lies at the prefab's base: CS2 places a prefab's origin on the terrain, so a lot, a yard or a quay deck sits * within a metre or so of y = 0 while a roof stands a storey or more above it. Measured on Granit's 252 uncaptured surfaces: 259k m^2 * of up-facing area lies at or below 1 m, 7k between 1 and 3 m, and the rest (roofs, 289k m^2) above. */ export declare const GROUND_MAX_HEIGHT_M = 1.5; /** Ground area (m^2) below which a flat surface is not split: a doorstep or a plinth stays concrete and costs no extra draw. */ export declare const GROUND_MIN_AREA_M2 = 200; /** * Triangle lists of a flat surface's faces, split into its ground (up-facing, at the prefab's base) and the rest, or null when the * ground is under `GROUND_MIN_AREA_M2`. `rest` is empty when the whole surface is ground (an apron, a car park). */ export declare function splitGroundFaces(positions: ArrayLike, indices: ArrayLike): { ground: number[]; rest: number[]; } | null; /** * The V a WINDOW pane reads its sheet at. The window sheets are stored upright, the head of the pane at the first row, while a pane's V rises * with its height (the higher vertex has the larger V in every one of the 1,000+ captured window groups, on every window sheet). Read * unflipped, a curtain or blind painted down from the head stands on the sill: a hard-edged band of vertical stripes across the BOTTOM of a * flat teal pane (Leonida build 18, F6, USSW_ResidentialHigh01_L3_3x4). `buildingWindowUv.spec.ts` measures it on a real prefab. */ export declare function windowV(v: number): number; /** * One primitive per material key: groups that share a material merge and vertices are compacted. UVs are written as captured: the * captured wall atlases are stored first-row-at-V=0, which is glTF's convention, so no V flip (a flip reads every wall from the wrong island). * A window pane is the exception: see `windowV`. */ export declare function buildPrimitives(mesh: Csm2Mesh, plans: GroupPlan[], indicesOf: Map): Primitive[]; /** * Colourways a prefab may keep: twice the stand-in's variant ladder, at most `maxVariants` and never more than it has buildings. The ladder alone * (1 below ten buildings, 2 below forty) cannot hold a block worn in nineteen colours, and the wall of the one a visitor stands at would wear a * stranger's. Draw calls are unchanged (a building still draws its own primitives); the cost is prototype files, and texture memory grows only * with the colourways streamed in at once. */ export declare function colourwayBudget(instances: number, maxVariants: number): number; export declare function buildBuildingPrototypes(options: BuildingPrototypeOptions): Promise; export {};