voxolith
API reference@voxolith/gen-terrainFunctions

generateTerrain()

Generate a region of ground and water: layered-noise hills, a meandering river carving its valley, lakes wherever the ground dips below the water level, and a surface role per column by slope, height and nearness to water (grass, dry grass, rock, sand, gravel, mud). The height map is sampled...

function generateTerrain(
   params?: Partial<TerrainParams>, 
   seed?: number, 
   build?: TerrainBuild
): Terrain;

Defined in: index.ts:317

Generate a region of ground and water: layered-noise hills, a meandering river carving its valley, lakes wherever the ground dips below the water level, and a surface role per column by slope, height and nearness to water (grass, dry grass, rock, sand, gravel, mud). The height map is sampled once into heights; everything else is answered on demand, so a chunked world fills bricks as it streams them. Pure in (params, seed, position).

Parameters

ParameterTypeDefault valueDescription
params?Partial<TerrainParams>{}Overrides of DEFAULT_TERRAIN; river merges field by field.
seed?number1Seeds the height and tone noise; the same seed gives the same region.
build?TerrainBuild{}heights to adopt instead of sampling them (rebuilding a terrain on a worker from a TerrainInit).

Returns

Terrain

The region: heights, roles, per-column queries, fillBrick and pick.

Example

import { generateTerrain } from "@voxolith/gen-terrain";

const terrain = generateTerrain({ width: 256, depth: 256, relief: 14 }, 42);
const { base } = palette.allocate(terrain.roles, "terrain"); // the world's PaletteAllocator
const cells = new Uint8Array(512);
if (terrain.fillBrick(cells, 0, 8, 0, base)) {
  // write `cells` as the 8^3 brick at (0, 8, 0)
}
const hit = terrain.pick(eye, dir, { water: true });

On this page