terrainHeightsBand()
Sample the rows z0 <= z < z1 of the height map, the unedited values generateTerrain samples into heights there. Bands are independent, so workers can each sample one and the host stitches them (heights.set(band, z0 width)) and passes the result to generateTerrain(params, seed, { heights }): byte...
function terrainHeightsBand(
params: Partial<TerrainParams>,
seed: number,
z0: number,
z1: number
): Int16Array;Defined in: index.ts:282
Sample the rows z0 <= z < z1 of the height map, the unedited values generateTerrain
samples into heights there. Bands are independent, so workers can each sample one and the
host stitches them (heights.set(band, z0 * width)) and passes the result to
generateTerrain(params, seed, { heights }): byte for byte the terrain it would sample itself.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | Partial<TerrainParams> | Overrides of DEFAULT_TERRAIN (completed with completeTerrainParams). |
seed | number | The terrain's seed. |
z0 | number | First row (clamped to the map). |
z1 | number | One past the last row (clamped to the map). |
Returns
Int16Array
(z1 - z0) * width heights, x + (z - z0) * width; width from terrainSize.
Example
const { width, depth } = terrainSize(params);
const heights = new Int16Array(width * depth);
const mid = depth >> 1; // each band could come from its own worker
heights.set(terrainHeightsBand(params, seed, 0, mid), 0);
heights.set(terrainHeightsBand(params, seed, mid, depth), mid * width);
const terrain = generateTerrain(params, seed, { heights });terrainHeight()
The height function on its own: pure in (x, z), for a world that streams columns without ever sampling the whole map. Gives exactly the values generateTerrain samples into heights, before any editing.
terrainInit()
A terrain as plain data, to rebuild the same Terrain elsewhere (a worker) without regenerating it: its complete params, seed and a copy of its current heights (so the init can be transferred while the terrain stays usable).