Terrain · class

Terrain

Explained in Terrain.

class Terrain
import { Terrain } from '@driftengine/terrain';

Constructor

new

constructor(options: HeightfieldOptions)
ParameterTypeDescription
optionsHeightfieldOptions

Properties

NameTypeDescription
widthreadonlynumber
depthreadonlynumber
spacingMreadonlynumber
originreadonlyFloat32Array<ArrayBuffer>World position of sample (0, 0), copied because a caller reuses its vectors.
heightsreadonlyFloat32ArrayThe samples, copied for the same reason and because this is read every frame.

Accessors

NameTypeDescription
extentXgetnumberHow far the field reaches along x, metres. One less cell than it has samples.
extentZgetnumber

Methods

sample

sample(ix: number, iz: number): number

One sample, by grid index, clamped to the field rather than wrapping or answering NaN.

ParameterTypeDescription
ixnumber
iznumber

heightAt

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

The height of the drawn surface at a world position.

ParameterTypeDescription
xnumber
znumber
More

The triangle and not the bilinear patch, for the reason at the top of this file. The cell is split along its a-c diagonal — from the sample at (ix, iz) to the one at (ix + 1, iz + 1) — and heightfieldPatch emits exactly that split, so the two cannot disagree about where the ground is.

Clamped outside the field. A world has an edge and a query past it should answer the edge rather than extrapolate a slope into a place that has no samples.

normalAt

normalAt(x: number, z: number, out: Float32Array): Float32Array

The surface normal at a world position, as a central difference over the samples.

ParameterTypeDescription
xnumber
znumber
outFloat32Array
More

Continuous across every cell boundary, which is what stops two patches shading differently along the edge they share — the failure that reads as a crack in geometry that has none.