Terrain beta
Class of @v12-engine/engine
export declare class TerrainHeightfield ground. World space spans [0, width] x [0, depth] with one height sample per unit. Rendering, navigation and the simulation all read from this same data.
Next to the height, every cell has a level: the ground floor is 0, each cliff up is one more. The height is what things stand on and where the eye sees a cliff, the level is what the rules go by: who sees whom and who shoots uphill. Ramps belong to the lower level until halfway up.
Members
constructor
constructor(
width: number,
depth: number,
heights: Float32Array, levels?: Uint8Array, surface?: TerrainSurface);Constructs a new instance of the Terrain class
blocked
readonly blocked: Uint8Array;What scenery keeps off each cell, row by row: 1 building there, 2 walking and building (see MapDoodad.blocks)
bounds
bounds?: {
x: number;
z: number;
width: number;
depth: number;
};The part of the map play happens in, in cells, when it is not all of it (GameMap.bounds): nothing on foot goes outside it, nothing is built there, and the camera keeps to it. The edge beyond is scenery
buildMesh
buildMesh(walkable?: boolean): TerrainMesh;Builds the triangle mesh of the ground; walkable leaves out what nothing on foot may cross
Parameters
walkable: leaves out what nothing on foot may cross, for the navigation
buildWaterMesh
buildWaterMesh(): TerrainMesh;The deep water as a mesh, at its surface: where what goes on water can go (UnitTypeDef.naval). Under a bridge too. Empty where the map has no deep water
cellAt
cellAt(layer: string, x: number, z: number): number;The value of a layer of cells (cells) at a point: 0 off the ground, or where the layer is not there
cellLayer
cellLayer(layer: string): Uint8Array;A layer of cells, made empty when it is not there yet
cells
readonly cells: Record<string, Uint8Array>;The game's own layers of cells, by id (CellLayerDef): where the bushes are, what burns. A value per cell, row by row; a layer nobody has painted is not there, and reads 0 everywhere (cellAt)
contains
contains(x: number, z: number): boolean;Whether a point is inside the map
depth
readonly depth: number;Cells along the map, north-south
hasDeepWater
get hasDeepWater(): boolean;Whether any cell is deep water: what boats go on
heightAt
heightAt(x: number, z: number): number;Height at any point, interpolated over the same triangles buildMesh produces.
heights
readonly heights: Float32Array;Height per vertex, row by row, (width + 1) by (depth + 1)
inPlay
inPlay(cx: number, cz: number): boolean;Whether a cell is in the part of the map play happens in (bounds)
levelAt
levelAt(x: number, z: number): number;Level of the cell a point is in
levels
readonly levels: Uint8Array;Level per cell, row by row. The fog works out what is seen from them once: world.fog.levelsChanged() after writing to them in a running world
normalAt
normalAt(x: number, z: number, out: {
x: number;
y: number;
z: number;
}): void;Surface normal (unnormalized y is always positive).
raycast
raycast(ox: number, oy: number, oz: number, dx: number, dy: number, dz: number, maxDist?: number): {
x: number;
y: number;
z: number;
} | null;First intersection of a ray with the ground, or null.
replace
replace(other: Terrain): void;Becomes another terrain, of whatever size, in place: what holds on to this one (the camera, what draws the ground) sees the new one. For the editor, when a map is resized
slopeAt
slopeAt(x: number, z: number): number;Steepness in radians, 0 = flat.
tiles
readonly tiles: Uint8Array;Paint per cell, row by row
vertexHeight
vertexHeight(ix: number, iz: number): number;The height at a vertex, its indices clamped to the map
vertsX
readonly vertsX: number;Height samples across the map: width + 1
vertsZ
readonly vertsZ: number;Height samples along the map: depth + 1
water
readonly water: Uint8Array;WATER_* per cell, row by row
waterAt
waterAt(x: number, z: number): number;WATER_* of the cell a point is in
waterHeightAt
waterHeightAt(x: number, z: number): number;The height of the water's surface at a point, over the same triangles as the ground
waterHeights
readonly waterHeights: Float32Array;Height of the surface of the water per vertex
width
readonly width: number;Cells across the map, east-west