import { type Heightfield, type SceneTerrainGrid, type SceneTerrainMaterial, type SceneTerrainMaterialRole, type SceneTerrainSplatLayers } from '@hypersoniclabs/helix-manifest'; import { type HeightGrid, type SampleField } from './grid'; import type { TerrainNormalMap } from './normals'; import type { TerrainPreset } from './presets'; /** The always-resident coarse layer takes every 8th fine sample, NEAREST so shared positions agree exactly; it spans 8 x the grid's spacing. */ export declare const COARSE_STRIDE_SAMPLES = 8; /** Splat pixels per tile side: one pixel per sample cell, whatever the cell measures. */ export declare const SPLAT_PIXELS_PER_TILE: number; export interface TerrainSplat { width: number; height: number; png: Uint8Array; } export interface TerrainFoldedRole { role: SceneTerrainMaterialRole; /** Share of the tile's total weight mass the dropped role carried, 0..1. */ mass: number; } export interface TerrainTile { tx: number; tz: number; field: Heightfield; splat: TerrainSplat | null; normals: TerrainNormalMap | null; layers: SceneTerrainSplatLayers | null; folded: TerrainFoldedRole[]; } export interface TerrainCoarse { metresPerSample: number; field: Heightfield; splat: TerrainSplat | null; normals: TerrainNormalMap | null; layers: SceneTerrainSplatLayers | null; folded: TerrainFoldedRole[]; } /** How a source posting at another spacing was brought onto the authoring grid. */ export type TerrainResample = 'cubic' | 'bilinear'; export interface TerrainProvenance { generated?: { seed: number; tilesX: number; tilesZ: number; preset: string; seaLevel: number | null; }; /** `metresPerSample` is the SOURCE posting; the grid carries the authored one. An f32 source declares no range. */ imported?: { file: string; format: string; sha256: string; metresPerSample: number; heightRange?: [number, number]; heightOffset?: number; resample?: TerrainResample; }; } export interface TerrainSource { grid: SceneTerrainGrid; tiles: TerrainTile[]; coarse: TerrainCoarse; material: SceneTerrainMaterial | null; preset: TerrainPreset | null; provenance: TerrainProvenance; } export interface TileTerrainOptions { /** Fine samples between two coarse ones; the coarse layer's metres per sample is this times the grid's. */ coarseStrideSamples?: number; provenance?: TerrainProvenance; } /** * Cuts a grid into 257-sample tiles that SHARE their boundary row and column, and builds the coarse layer beside them. * Heights are quantized per object against its own min and max, so a 257-sample tile keeps sub-centimetre steps. */ export declare function tileTerrain(grid: HeightGrid, options?: TileTerrainOptions): TerrainSource; /** The whole terrain's height range, taken over every tile so it covers samples the coarse layer skips. */ export declare function terrainHeightRange(source: TerrainSource): [number, number]; /** * Reassembles the full authoring field from the tiles, dequantized. The bake evaluates slope and curvature on this * rather than tile by tile, because one-sided differences at a tile edge would put a seam down the splat. */ export declare function gridFromTerrainSource(source: TerrainSource): HeightGrid; /** Reads a hole mask image onto a grid of `samplesX` x `samplesZ`: white is a hole, nearest-neighbour, any size accepted. */ export declare function holesFromMask(pngPath: string, samplesX: number, samplesZ: number): Promise; /** * Metres per texel of the coarse layer's splat and normal maps: the 2 m floor, never finer than one sample cell, and * coarse enough to fit the padded coarse extent in 2048 texels. Rounded UP to a whole number of samples, the map stride. */ export declare function coarseMapMetresPerTexel(grid: Pick, coarse: Pick): number; /** Encoded bytes of one heightfield, the form the source folder and the scene resource both ship. */ export declare function encodeTerrainField(field: Heightfield): Uint8Array; /** A decoded field as a plain sample grid, for slope and curvature work. */ export declare function fieldToSampleField(field: Heightfield): SampleField;