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
| Parameter | Type | Default value | Description |
|---|---|---|---|
params? | Partial<TerrainParams> | {} | Overrides of DEFAULT_TERRAIN; river merges field by field. |
seed? | number | 1 | Seeds 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
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 });fineTerrainInit()
Describe a fine terrain as data for a worker. top (default: the fine terrain's options.top) is evaluated on every coarse column once, so a closure over app state (a settlement's paths and yards) becomes a Uint8Array. Heights are copied as they are now: level before calling.
refineTerrain()
The same terrain k times finer, for a world at 20, 50 or 100 voxels per metre. Nothing is built up front: the result wraps coarse and fills any brick on demand, with a bicubic surface through the coarse column tops, organic boundaries between surface roles, grass blades on grassy ground and...