Skip to content

@bendyline/molen-kernel/terrain ​

Molen headless deterministic simulation kernel (no DOM, no three.js).

ts
import { /* … */ } from '@bendyline/molen-kernel/terrain';

Interfaces ​

GroundField ​

The minimum a terrain source must provide to act as the world's ground.

Properties ​

cellSize? ​
ts
readonly optional cellSize?: [number, number];

Grid cell size (x, z) when the field is sampled; drives the default ray-march step.

Methods ​

normalAt() ​
ts
normalAt(x, z): Vec3;

Unit surface normal at a world XZ.

Parameters ​
x ​

number

z ​

number

Returns ​

Vec3

sampleHeight() ​
ts
sampleHeight(x, z): number;

Surface height at a world XZ (meters).

Parameters ​
x ​

number

z ​

number

Returns ​

number


TerrainHandle ​

The kernel-side terrain service: height/normal/slope queries and a heightfield ray cast.

Properties ​

field ​
ts
readonly field: GroundField;

Methods ​

heightAt() ​
ts
heightAt(x, z): number;
Parameters ​
x ​

number

z ​

number

Returns ​

number

normalAt() ​
ts
normalAt(x, z): Vec3;
Parameters ​
x ​

number

z ​

number

Returns ​

Vec3

raycast() ​
ts
raycast(
   origin, 
   dir, 
   maxDist
): TerrainRayHit | null;

Cast a ray against the surface: march along dir in fixed steps, then bisect the first above→below crossing. An origin already below the surface hits at distance 0. Returns null when the ray stays above the surface for maxDist.

Parameters ​
origin ​

Vec3

dir ​

Vec3

maxDist ​

number

Returns ​

TerrainRayHit | null

slopeAt() ​
ts
slopeAt(x, z): number;

1 - normal.y: 0 on flat ground, approaching 1 on cliffs.

Parameters ​
x ​

number

z ​

number

Returns ​

number


TerrainOptions ​

Properties ​

maxRaySteps? ​
ts
optional maxRaySteps?: number;

Cap on march steps per ray (default 4096).

rayStep? ​
ts
optional rayStep?: number;

Ray-march step in world units (default: half the field's cell size, else 1).


TerrainRayHit ​

Properties ​

distance ​
ts
distance: number;
normal ​
ts
normal: Vec3;
point ​
ts
point: Vec3;

Functions ​

groundFieldOf() ​

ts
function groundFieldOf(world): GroundField | undefined;

The ground field registered on a world (by installTerrain), if any.

Parameters ​

world ​

World

Returns ​

GroundField | undefined


installTerrain() ​

ts
function installTerrain(
   world, 
   field, 
   opts?
): TerrainHandle;

Register a ground field on a world and get the query handle. Systems installed BEFORE this call (character controller, kinematics with ground: 'terrain') resolve the field lazily at tick time, so install order does not matter.

Parameters ​

world ​

World

field ​

GroundField

opts? ​

TerrainOptions

Returns ​

TerrainHandle


terrainScriptApi() ​

ts
function terrainScriptApi(handle): object;

The script-api namespace for terrain (molen.terrain.*); pass via scripting extensions.

Parameters ​

handle ​

TerrainHandle

Returns ​

object

37 guides · 36 schema formats · 41 API entry points · 10 samples. API, CLI and schema pages are generated from the shipped build.