Skip to content

Instancing, terrain & splines

Three geometry features handle large or procedural content. Instancing and terrain are first-class mesh fields (instancer and generator — see Meshes); both are deterministic (seeded, no Math.random), so a scene renders identically every load.

Instancing draws many copies in one call; terrain is a procedural heightfield; splines are CatmullRom curves
Instancing, terrain, and splines.

Set a mesh’s instancer (+ instancerParams) to render many copies as a single InstancedMesh — one draw call. The built-in Grid instancer (packages/engine/src/scene/instancers/grid.ts) lays out a countX × countZ grid on the XZ plane (defaults 100×100 = 10,000 instances) with spacing and optional deterministic jitter (a seeded LCG). Register your own instancer to produce any per-instance matrix set.

Set a mesh’s generator to "Terrain" (+ generatorParams) for a procedural heightfield (packages/engine/src/scene/geometries/terrain.ts): a horizontal XZ plane displaced in +Y by a deterministic sum of sines. Params: width, depth (world size), segments (grid resolution), amplitude (max height), frequency (wave scale). Pair it with a trimesh collider so physics matches the visual surface.

The spline schema (packages/engine/src/scene/schema/spline.ts) defines a CatmullRomCurve3 from points (≥ 2 control points), with closed (loop), curveType (catmullrom / centripetal / chordal), tension (default 0.5, used only for catmullrom), and resolution (line segments). Use splines for paths, camera rails, or procedural placement.