What it does
The landform is data. Name a preset, hills, mountains, dunes, plateau or island, or pass your own function
from a world point to a height, and nothing else in the pack cares which: a level can come from a seed, a hand-written
function or a file. featureSize is in world units, so growing size gives you more hills rather than the same hills
made bigger, which is what makes a large terrain feel large. An after function reshapes the result on top of a
preset: a continental shelf, a river valley cut through hills, a levelled building site.
What makes it read as ground rather than a coloured surface is the colormap, baked once over the whole terrain. Colour comes from height bands with soft edges, blends towards each band's cliff colour on slopes, and is jittered at two scales so flat ground never looks airbrushed, with a fine turf mottle in the grass. Close up, the renderer lays a world-space grain over sandy ground that fades itself out with distance. The colour is baked, so it costs nothing per frame.
The mesh is cut into chunks that each cull on their own and join without seams. heightAt interpolates over the same
two triangles per quad that the mesh draws, so a tree, a crate or a character placed with it sits exactly on the
surface, and normalAt uses the same normals the shading does. With edits, biome masks and footprint checks, the
terrain is an authoring tool as well as a backdrop.
Features
- Five landforms or your own —
hills,mountainswith sharp crests, wind-alignedduneswith slip faces, flat-toppedplateauand anislandwhose edges go under water, or aheightfunction of your own. - A baked colormap — four surfaces (
grass,sand,snow,rock) or your own colour bands, cliffs drawn on slopes, and apaintcallback for your own ground classes such as beach, dirt or vegetation. - Queries that match the render —
heightAt,normalAt,slopeAt,raycastandplace, all of which answer exactly headless as well as drawn. - Saved edits —
raise,flatten,road,valleyand seededlandformpatches, applied in order, withundo,redo, and a JSON-safesaveandload. - Biome masks — feathered
forest,lake,mountain,hillsandpathregions that tint the ground and thatbiomeAtreports to foliage and editor tools. - Building footprints —
foundationsamples a rotated rectangle and returns an upright base height and the relief beneath it. - Distance detail —
detail: 'walk'or'overview'coarsens far chunks, with skirts over the gaps and morphed transitions, while every query keeps the full-resolution surface. - Endless ground —
wrap: truemakes the terrain a torus that repeats on both axes, so a camera can fly on in one direction and never meet an edge. - Ground that changes in play — render a
Heightfieldyou own, write its heights, andrefreshonly the region that changed.
Good for
- Exploration and walking games — hills or mountains with a first-person character standing on
heightAt. - Driving and vehicle games —
normalAtaligns a car or a tank to the slope, and aroadedit cuts an even route through the hills. - Strategy games and city builders —
flattenpads andfoundationchecks for buildings on uneven ground. - God games that reshape the land — spells that raise a volcano or split an island, through a shared heightfield
and
refresh. - Flight over endless ground — a wrapped terrain with no edge, in the style of Magic Carpet.
- Island and coastal scenes — the
islandlandform with water shoaling against its beaches. - Level editors — edits with undo and redo, saved and loaded as JSON.
Make it yours
A build takes the size, the grid resolution, the landform, its amplitude, base height, feature size and seed, the
surface or your own colour bands, the colormap resolution, the turf and grain strength and the chunk count.
A procedural world is a seed and a preset; a designed level is a height function or a list of edits on top of one,
kept separately so you can regenerate it. setDetailTexture swaps the procedural grain for your own 256×256 image,
blended in three projections so cliffs do not stretch it.
Three quite different terrains from the same pack: a 400-unit grass island with a road and a flattened pad for a village, walked in first person; a wrapped mountain range, much larger, flown over endlessly with the fog kept inside half its size; and a strategy map whose own rules write the heights each turn and repaint only the ground that moved.
A quick look
A mountain range, then a valley, a road and a level building pad cut into it, and a footprint checked:
game.terrain.build({ shape: 'mountains', size: 800, featureSize: 120, seed: 7 });
game.terrain.edit([
{ kind: 'valley', points: [{ x: 0, z: -80, y: 3 }, { x: 20, z: 80, y: 7 }], width: 15, feather: 20 },
{ kind: 'road', points: [{ x: -30, z: 0, y: 12 }, { x: 30, z: 20, y: 16 }], width: 5, feather: 4 },
{ kind: 'flatten', x: 30, z: 20, radius: 12, value: 16, feather: 3 },
]);
const site = game.terrain.foundation(30, 20, 10, 8); // an upright base for a 10 × 8 building
const saved = game.terrain.save(); // JSON-safe, for an editor's save
Works with
world-3d— the 3D world it builds into;procgensupplies its noise.rig-fps— give its floor the terrain'sheightAtto walk the ground, and itscanMovecheck for slope and step limits.forest-3dandgrass-3d— trees and grass planted on its height, with forests masked by its biomes.water-3d— seas and lakes that shoal against its beaches.terrain-world-3d— for landscapes too large to hold in one height array, streamed in tiles.voxels-3d— for caves, overhangs and ground the player digs through.
Good to know
- A heightfield has no overhangs, caves or arches; compose rock meshes or
voxels-3dfor those. - The whole height grid stays in memory with one mesh per chunk; for bounded paging across a very large world, use
terrain-world-3d. - Edits are an authoring step, not per-frame sculpting, and history keeps up to 32 batches. Ground that changes in
play goes through
refresh, which keeps no history. colormapResis capped at 2048 and goes into the shared atlas with your other art, and there is no splat-mapped material stack beyond the colormap and detail texture.- A
lakemask does not dig a basin or make water: flatten or carve one, and compose a water pack.






