Skip to content

Terrain beta ​

Class of @v12-engine/engine

ts
export declare class Terrain

Heightfield 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 ​

ts
constructor(
    width: number, 
    depth: number, 
    heights: Float32Array, levels?: Uint8Array, surface?: TerrainSurface);

Constructs a new instance of the Terrain class

blocked ​

ts
readonly blocked: Uint8Array;

What scenery keeps off each cell, row by row: 1 building there, 2 walking and building (see MapDoodad.blocks)

bounds ​

ts
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 ​

ts
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 ​

ts
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 ​

ts
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 ​

ts
cellLayer(layer: string): Uint8Array;

A layer of cells, made empty when it is not there yet

cells ​

ts
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 ​

ts
contains(x: number, z: number): boolean;

Whether a point is inside the map

depth ​

ts
readonly depth: number;

Cells along the map, north-south

hasDeepWater ​

ts
get hasDeepWater(): boolean;

Whether any cell is deep water: what boats go on

heightAt ​

ts
heightAt(x: number, z: number): number;

Height at any point, interpolated over the same triangles buildMesh produces.

heights ​

ts
readonly heights: Float32Array;

Height per vertex, row by row, (width + 1) by (depth + 1)

inPlay ​

ts
inPlay(cx: number, cz: number): boolean;

Whether a cell is in the part of the map play happens in (bounds)

levelAt ​

ts
levelAt(x: number, z: number): number;

Level of the cell a point is in

levels ​

ts
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 ​

ts
normalAt(x: number, z: number, out: {
        x: number;
        y: number;
        z: number;
    }): void;

Surface normal (unnormalized y is always positive).

raycast ​

ts
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 ​

ts
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 ​

ts
slopeAt(x: number, z: number): number;

Steepness in radians, 0 = flat.

tiles ​

ts
readonly tiles: Uint8Array;

Paint per cell, row by row

vertexHeight ​

ts
vertexHeight(ix: number, iz: number): number;

The height at a vertex, its indices clamped to the map

vertsX ​

ts
readonly vertsX: number;

Height samples across the map: width + 1

vertsZ ​

ts
readonly vertsZ: number;

Height samples along the map: depth + 1

water ​

ts
readonly water: Uint8Array;

WATER_* per cell, row by row

waterAt ​

ts
waterAt(x: number, z: number): number;

WATER_* of the cell a point is in

waterHeightAt ​

ts
waterHeightAt(x: number, z: number): number;

The height of the water's surface at a point, over the same triangles as the ground

waterHeights ​

ts
readonly waterHeights: Float32Array;

Height of the surface of the water per vertex

width ​

ts
readonly width: number;

Cells across the map, east-west