voxolith
API reference@voxolith/gen-terrainFunctions

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

ParameterTypeDescription
paramsPartial<TerrainParams>Overrides of DEFAULT_TERRAIN (completed with completeTerrainParams).
seednumberThe terrain's seed.
z0numberFirst row (clamped to the map).
z1numberOne 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 });

On this page