Terrain · class
Terrain
Explained in Terrain.
class Terrainimport { Terrain } from '@driftengine/terrain';Constructor
new
constructor(options: HeightfieldOptions)| Parameter | Type | Description |
|---|---|---|
options | HeightfieldOptions |
Properties
| Name | Type | Description |
|---|---|---|
widthreadonly | number | |
depthreadonly | number | |
spacingMreadonly | number | |
originreadonly | Float32Array<ArrayBuffer> | World position of sample (0, 0), copied because a caller reuses its vectors. |
heightsreadonly | Float32Array | The samples, copied for the same reason and because this is read every frame. |
Accessors
| Name | Type | Description |
|---|---|---|
extentXget | number | How far the field reaches along x, metres. One less cell than it has samples. |
extentZget | number |
Methods
sample
sample(ix: number, iz: number): numberOne sample, by grid index, clamped to the field rather than wrapping or answering NaN.
| Parameter | Type | Description |
|---|---|---|
ix | number | |
iz | number |
heightAt
heightAt(x: number, z: number): numberThe height of the drawn surface at a world position.
| Parameter | Type | Description |
|---|---|---|
x | number | |
z | number |
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): Float32ArrayThe surface normal at a world position, as a central difference over the samples.
| Parameter | Type | Description |
|---|---|---|
x | number | |
z | number | |
out | Float32Array |
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.