@relu-interactives/spatial-ecs
@relu-interactives/spatial-ecs / index / TerrainSystem
Class: TerrainSystem ​
Defined in: terrain/TerrainSystem.ts:72
Builds and draws terrains (TerrainComponent): makes the heightfield (from its file or its noise), splits it into chunks drawn simpler with distance, keeps a physics heightfield in step, and gives occlusion culling boxes for the solid ground under hills.
A default system, in the editor too (sculpting and painting go through edit). world.terrain is this system.
Implements ​
Constructors ​
Constructor ​
new TerrainSystem(isEditor?): TerrainSystem;Defined in: terrain/TerrainSystem.ts:78
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
isEditor | boolean | false |
Returns ​
TerrainSystem
Properties ​
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
runsWhilePaused | readonly | true | true | Keep ticking while the world is paused. Leave it unset for anything that moves the game on: such a system stops at world.pause() and picks up where it was at world.resume(). | terrain/TerrainSystem.ts:73 |
Methods ​
update() ​
update(world): void;Defined in: terrain/TerrainSystem.ts:80
Parameters ​
| Parameter | Type |
|---|---|
world | World |
Returns ​
void
Implementation of ​
getTerrains() ​
getTerrains(): number[];Defined in: terrain/TerrainSystem.ts:105
Terrain entities with their ground ready.
Returns ​
number[]
getField() ​
getField(entityId): Heightfield | null;Defined in: terrain/TerrainSystem.ts:110
The heightfield of a terrain, once made. Change it through edit.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
Heightfield | null
heightAt() ​
heightAt(
world,
x,
z): number | null;Defined in: terrain/TerrainSystem.ts:118
World-space ground height under (x, z): the highest terrain there, or null where there's none (or it hasn't loaded).
Parameters ​
| Parameter | Type |
|---|---|
world | World |
x | number |
z | number |
Returns ​
number | null
normalAt() ​
normalAt(
world,
x,
z): Vector3 | null;Defined in: terrain/TerrainSystem.ts:137
World-space ground normal under (x, z), or null where there's no terrain.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
x | number |
z | number |
Returns ​
Vector3 | null
edit() ​
edit(entityId): Heightfield | null;Defined in: terrain/TerrainSystem.ts:159
Change a terrain's ground: call methods on the heightfield it gives (raise, flatten, smooth, roughen, path, paint, autoPaint, generate) and the chunks, collider and occluders follow next frame. Null until the terrain is made. Save the result with save.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
Heightfield | null
adoptFile() ​
adoptFile(
world,
entityId,
path): boolean;Defined in: terrain/TerrainSystem.ts:168
Point a terrain at the file its current ground was just saved to, without loading it again: what the editor does after writing save(id) to disk. Returns false when the terrain isn't ready.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
entityId | number |
path | string |
Returns ​
boolean
save() ​
save(entityId): ArrayBuffer | null;Defined in: terrain/TerrainSystem.ts:178
The .terrain file for a terrain as it is now, for the editor to write.
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
ArrayBuffer | null
status() ​
status(entityId): {
state: "loading" | "error" | "ready" | "missing";
error?: string;
};Defined in: terrain/TerrainSystem.ts:183
Whether a terrain is ready, still loading, or failed (with why).
Parameters ​
| Parameter | Type |
|---|---|
entityId | number |
Returns ​
{
state: "loading" | "error" | "ready" | "missing";
error?: string;
}| Name | Type | Defined in |
|---|---|---|
state | "loading" | "error" | "ready" | "missing" | terrain/TerrainSystem.ts:183 |
error? | string | terrain/TerrainSystem.ts:183 |
onChange() ​
onChange(listener): () => void;Defined in: terrain/TerrainSystem.ts:191
Hear when a terrain's ground is ready or changed shape. Returns a remover.
Parameters ​
| Parameter | Type |
|---|---|
listener | (entityId) => void |
Returns ​
() => void
getStats() ​
getStats(): {
terrains: number;
chunks: number;
triangles: number;
levels: number[];
};Defined in: terrain/TerrainSystem.ts:197
Chunks drawn and their levels, for stats.
Returns ​
{
terrains: number;
chunks: number;
triangles: number;
levels: number[];
}| Name | Type | Defined in |
|---|---|---|
terrains | number | terrain/TerrainSystem.ts:197 |
chunks | number | terrain/TerrainSystem.ts:197 |
triangles | number | terrain/TerrainSystem.ts:197 |
levels | number[] | terrain/TerrainSystem.ts:197 |

