import type { HeightGrid } from '../../terrain'; /** The sample strides the engine draws a fine tile at (`TerrainTileSet.strideFor`); the coarse layer is the stride-8 lattice. */ export declare const TERRAIN_LOD_STRIDES: readonly [1, 2, 4, 8]; /** A road more than this far under the ground at its own spot is a tunnel or a deep trench, not a road that sank. */ export declare const ROAD_COVERED_METRES = 3; /** A road surface more than this above the ground at its own spot is a deck or a ramp; terrain beside it is not carved for it. */ export declare const ROAD_ELEVATED_METRES = 3; /** Share under at least this much counts as sunk. */ export declare const SUNK_THRESHOLDS_METRES: readonly [0.05, 0.5]; /** * A road more than ROAD_COVERED_METRES under the ground, with no roof over it, is an OPEN CUT (a sunken highway or interchange), not a tunnel: * the ground over it is carved away. One deeper than this is a bored tunnel whose roof the capture did not model, and keeps its hill. */ export declare const OPEN_CUT_MAX_DEPTH_METRES = 16; /** An open cut is opened only when its floor is this far above the sea (or whatever `floorMetres` names): below it the cut would flood. */ export declare const OPEN_CUT_ABOVE_WATER_METRES = 0.25; export interface RoadSurfaces { /** World xyz of every vertex of an up-facing surface triangle (a vertex of none is dropped). */ positions: Float32Array; indices: Uint32Array; /** * x, y, z of the centre of every down-facing triangle of the same roads (a deck's underside, a tunnel's roof). With it the carve opens * a road that sits in a cut (no roof over it); without it a road under ground stays covered, as it always was. */ roofs?: Float32Array; /** `CITY_SURFACE` kind per triangle (restyled cells carry it); absent means every triangle is a road to shoulder. */ kinds?: Uint8Array; /** * 1 per triangle that is the top of a structure (a concrete deck, a tunnel's roof slab, a girder), 0 for a road. A structure's top under the * ground is the roof of whatever it covers, never a floor with open sky over it, so the carve does not open the hill down to it. Absent * means no triangle is known to be one. */ structure?: Uint8Array; } export type RoadCover = 'on-ground' | 'deck' | 'tunnel' | 'open-cut'; /** * Sorts every up-facing road triangle by what the ground does over it, against the ground as drawn (`grid`, stride 1), BEFORE any carve: * on the ground, a deck above it, or more than ROAD_COVERED_METRES under it. Under the ground, anything over the road (a tunnel's roof, a * bridge deck across the cut) makes it covered and leaves the ground alone: carving there could cut a street or a hill out from over a * tunnel. Open sky over it, down to OPEN_CUT_MAX_DEPTH_METRES, makes it an open cut. Without `roofs` a covered road is a tunnel (the old behaviour). */ export declare function classifyRoadCover(grid: HeightGrid, surfaces: RoadSurfaces, floorMetres?: number): RoadCover[]; /** Reads the up-facing road surface triangles of a baked road folder (`render/`), in world metres. */ export declare function readRoadSurfaces(roadsDir: string, log?: (message: string) => void): Promise; /** The terrain AS DRAWN at (x, z) when the field is drawn at `stride`: the lattice quad split (a, c, b) / (b, c, d) the engine's grids use. */ export declare function drawnHeight(grid: HeightGrid, stride: number, x: number, z: number): number; export interface SinkLodStats { stride: number; /** Road vertices counted (those not covered). */ vertices: number; /** Counted vertices with the drawn terrain this far or more above the road, by `SUNK_THRESHOLDS_METRES`. */ sunk5cm: number; sunk50cm: number; share5cm: number; share50cm: number; /** The deepest a counted vertex sits under the drawn terrain. */ worstMetres: number; } export interface RoadSinkReport { /** Vertices of up-facing road surfaces. */ roadVertices: number; /** Excluded: more than ROAD_COVERED_METRES under the ground drawn at stride 1 (tunnels and trenches). */ covered: number; /** Counted, but more than ROAD_ELEVATED_METRES above the ground (decks and ramps). */ elevated: number; lods: SinkLodStats[]; } /** Share of road vertices under the drawn terrain at each stride. Tunnels and deep trenches are excluded, decks are counted (they never sink). */ export declare function measureRoadSink(grid: HeightGrid, surfaces: RoadSurfaces, strides?: readonly number[]): RoadSinkReport; export interface CarveOptions { /** Metres a held corner sits under the surface (default TERRAIN_CONFORM_CLEARANCE_METRES). */ clearanceMetres?: number; /** A corner this far from the surface's floor is left alone (default 3 m, the fine conform's own: measured on Granit, 6 m and 12 m clear a few more vertices at the price of pits up to 8 and 14 m deep). */ maxDeviationMetres?: number; strides?: readonly number[]; /** The water level the scene draws over the terrain: a road under the ground whose floor is not above it is not opened (it would flood). */ floorMetres?: number; } export interface CarveStats { /** Fine-lattice samples lowered, and by how much at most and at the 99th percentile. */ samplesLowered: number; maxLoweredMetres: number; p99LoweredMetres: number; /** Fine-lattice samples lowered by at least each of 0.1, 0.25, 0.5, 1, 2 and 4 m. */ loweredOver: Record; /** Per stride, samples of that lattice the pass held. */ heldByStride: Record; /** Surface triangles used per stride (decks and covered surfaces are not). */ trianglesUsed: number; trianglesSkipped: number; /** Of the used triangles, those of roads in an open cut (the ground over them was opened), and of the skipped, those of tunnels. */ openCutTriangles: number; tunnelTriangles: number; } /** * Lowers `grid` (MUTATED) so that no road surface sinks under the terrain at ANY stride. Coarse to fine; at each stride the * lattice is conformed with `holdOnly`, and a surface that is a deck or a tunnel at its own spot is left out. */ export declare function carveRoadCorridors(grid: HeightGrid, surfaces: RoadSurfaces, options?: CarveOptions): CarveStats; /** Every `stride`-th sample of the grid as a grid of its own (a copy). */ export declare function decimate(grid: HeightGrid, stride: number): HeightGrid; /** Metres beside a road surface's edge over which the ground is brought flush with it (a car leaves or joins the road on the level). */ export declare const SHOULDER_FLAT_METRES = 2; /** Beyond the flat, the ground may depart from the road's height by this much per metre (1:5, 11 deg) until it meets the land as it was. */ export declare const SHOULDER_SLOPE = 0.2; /** A road edge more than this from the ground beside it (an abutment, a retaining wall) is not shouldered: the change would be a new embankment. */ export declare const SHOULDER_MAX_CHANGE_METRES = 3; export interface ShoulderOptions { flatMetres?: number; slope?: number; maxChangeMetres?: number; /** Metres the shouldered ground sits under the road edge (default TERRAIN_CONFORM_CLEARANCE_METRES). */ clearanceMetres?: number; /** The water level the scene draws: ground under it is never filled to the land, so a shore road does not grow a bank into the sea (it gets a ramp from its edge up to the lip, and only where the ramp stands above the water). */ floorMetres?: number; } /** The surfaces a car or a walker leaves the road from; structure (wall and barrier tops, girders) never pulls the ground up to it. */ export declare const SHOULDER_SURFACES: ReadonlySet; export interface ShoulderStats { /** Outer edges (road surface meeting no other road surface) of on-ground roads, metres. */ edgeMetres: number; samplesRaised: number; samplesLowered: number; maxRaisedMetres: number; maxLoweredMetres: number; /** Samples under a shouldered road surface brought to it (`setGridToSurfaces`). */ underRoad: number; } /** * Shoulders the ground to its roads (MUTATES `grid`): every sample within reach of an on-ground road surface's outer edge is held between * `edgeY - clearance - slope * (d - flat)` and `edgeY - clearance + slope * (d - flat)`, `d` its horizontal distance to the nearest edge and * `edgeY` the road's height at the nearest point of it. Within `flat` the ground meets the road edge; beyond it the ground rises or falls back * to the land at `slope`. A CS2 road sits a slab's height (measured on Pacifica: 0.16-0.6 m on 44 % of its edges) above the terrain the game * exports, and the carve only ever LOWERS the ground under a road, so before this every road was a kerb a car could not climb, with a dip * of carved cells beside it that the slope rule painted as a stair-stepped dirt band. Run it BEFORE `carveRoadCorridors`: the carve then holds * every cell a road crosses under the road again, so a shoulder can never rise through a deck. * * With a water `floorMetres`, ground under the water is never filled to the land, with one exception: where the road edge itself stands * on land (the ground around the edge point reaches the water) and the bed beside it lies under the water, the bed rises on the ramp from * the lip (`edgeY - clearance - slope * (d - flat)`), kept only while the ramp stands above the water, so the bank reaches no further than * `flat + (lip - floor) / slope` from the edge and a shore road no longer ends in a vertical face down to the bed (Pacifica x07, 0.75 m). * An edge over a channel (a low bridge, a quay over deep water) keeps its bed: the water still passes. */ export declare function shapeRoadShoulders(grid: HeightGrid, surfaces: RoadSurfaces, options?: ShoulderOptions): ShoulderStats; /** How far under its own lowest road point a sample may go to take a share of a neighbour's hold (`holdGridUnderSurfaces`). */ export declare const HOLD_SHARE_SLACK_METRES = 1; export interface ExactHoldOptions { clearanceMetres?: number; /** A sample is never lowered further than this under where it started. */ maxDeviationMetres?: number; /** Triangles facing up less than this are not held to (walls, kerb faces). */ minUpFacing?: number; } export interface ExactHoldStats { constraints: number; samplesLowered: number; passes: number; /** What is left over the road after the last pass (clamped samples), metres. */ worstOverMetres: number; } /** * Lowers the lattice only as far as its DRAWN surface must go to stay `clearance` under every up-facing road triangle: the terrain * and the road are both piecewise linear, so their difference peaks where the two triangulations' edges meet (a road vertex, a * lattice sample inside a road triangle, a road edge crossing a lattice row, column or diagonal), and each of those points is a * constraint on the three samples of the drawn triangle it falls in. A violated constraint lowers its three samples by the least * squares share of the excess (each by its weight), pass after pass, until nothing is over. * * It replaces holding every corner of every crossed cell under the road's LOWEST point in that cell, which is exact but far too * deep on a lattice: on a 5 % grade a stride-8 cell (32 m) held its upper posts 1.6 m under the road, and on the full grid those * posts are pits beside the road (Pacifica: 31k samples carved more than 1 m, a trench and a lip along a third of the road edges). */ export declare function holdGridUnderSurfaces(grid: HeightGrid, surfaces: RoadSurfaces, options?: ExactHoldOptions): ExactHoldStats; /** Sets every sample an up-facing triangle covers to `clearance` under it (the lowest where several do), raised or lowered by at most `maxChange`. */ export declare function setGridToSurfaces(grid: HeightGrid, surfaces: RoadSurfaces, clearance: number, maxChange: number, minUpFacing?: number): number;