Skip to content

@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 ​

ts
new TerrainSystem(isEditor?): TerrainSystem;

Defined in: terrain/TerrainSystem.ts:78

Parameters ​

ParameterTypeDefault value
isEditorbooleanfalse

Returns ​

TerrainSystem

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
runsWhilePausedreadonlytruetrueKeep 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() ​

ts
update(world): void;

Defined in: terrain/TerrainSystem.ts:80

Parameters ​

ParameterType
worldWorld

Returns ​

void

Implementation of ​

EcsSystem.update


getTerrains() ​

ts
getTerrains(): number[];

Defined in: terrain/TerrainSystem.ts:105

Terrain entities with their ground ready.

Returns ​

number[]


getField() ​

ts
getField(entityId): Heightfield | null;

Defined in: terrain/TerrainSystem.ts:110

The heightfield of a terrain, once made. Change it through edit.

Parameters ​

ParameterType
entityIdnumber

Returns ​

Heightfield | null


heightAt() ​

ts
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 ​

ParameterType
worldWorld
xnumber
znumber

Returns ​

number | null


normalAt() ​

ts
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 ​

ParameterType
worldWorld
xnumber
znumber

Returns ​

Vector3 | null


edit() ​

ts
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 ​

ParameterType
entityIdnumber

Returns ​

Heightfield | null


adoptFile() ​

ts
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 ​

ParameterType
worldWorld
entityIdnumber
pathstring

Returns ​

boolean


save() ​

ts
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 ​

ParameterType
entityIdnumber

Returns ​

ArrayBuffer | null


status() ​

ts
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 ​

ParameterType
entityIdnumber

Returns ​

ts
{
  state: "loading" | "error" | "ready" | "missing";
  error?: string;
}
NameTypeDefined in
state"loading" | "error" | "ready" | "missing"terrain/TerrainSystem.ts:183
error?stringterrain/TerrainSystem.ts:183

onChange() ​

ts
onChange(listener): () => void;

Defined in: terrain/TerrainSystem.ts:191

Hear when a terrain's ground is ready or changed shape. Returns a remover.

Parameters ​

ParameterType
listener(entityId) => void

Returns ​

() => void


getStats() ​

ts
getStats(): {
  terrains: number;
  chunks: number;
  triangles: number;
  levels: number[];
};

Defined in: terrain/TerrainSystem.ts:197

Chunks drawn and their levels, for stats.

Returns ​

ts
{
  terrains: number;
  chunks: number;
  triangles: number;
  levels: number[];
}
NameTypeDefined in
terrainsnumberterrain/TerrainSystem.ts:197
chunksnumberterrain/TerrainSystem.ts:197
trianglesnumberterrain/TerrainSystem.ts:197
levelsnumber[]terrain/TerrainSystem.ts:197