Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / FoliageSystem

Class: FoliageSystem ​

Defined in: terrain/FoliageSystem.ts:224

Grass, trees and rocks on terrains (GrassComponent, ScatterComponent). Both are built in chunks around the camera, nearest first and a few a frame, and dropped once far behind, so a huge terrain costs what's near.

  • Grass: one instanced mesh per chunk; the share of its blades drawn falls off with distance, so it thins out instead of ending in a line.
  • Scatter: per item and chunk, the model's meshes as instances up close, flat pictures of it (impostors) from its impostor distance, nothing past its cull distance. Impostors are pictured once per model with the game's renderer.

A default system, in the editor too. world.foliage is this system.

Implements ​

Constructors ​

Constructor ​

ts
new FoliageSystem(): FoliageSystem;

Returns ​

FoliageSystem

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/FoliageSystem.ts:225
holdWindpublic(() => boolean) | nullnullWhile this answers true the wind stops (grass holds its pose): the editor holds it unless its Play animations toggle is on. A paused game holds it too.terrain/FoliageSystem.ts:234

Methods ​

update() ​

ts
update(world, deltaTime?): void;

Defined in: terrain/FoliageSystem.ts:236

Parameters ​

ParameterTypeDefault value
worldWorldundefined
deltaTimenumber0

Returns ​

void

Implementation of ​

EcsSystem.update


getStats() ​

ts
getStats(): {
  grassChunks: number;
  blades: number;
  scatterChunks: number;
  instances: number;
  impostorChunks: number;
  impostorDraws: number;
};

Defined in: terrain/FoliageSystem.ts:281

What's drawn, for stats.

Returns ​

ts
{
  grassChunks: number;
  blades: number;
  scatterChunks: number;
  instances: number;
  impostorChunks: number;
  impostorDraws: number;
}
NameTypeDefined in
grassChunksnumberterrain/FoliageSystem.ts:282
bladesnumberterrain/FoliageSystem.ts:283
scatterChunksnumberterrain/FoliageSystem.ts:284
instancesnumberterrain/FoliageSystem.ts:285
impostorChunksnumberterrain/FoliageSystem.ts:286
impostorDrawsnumberterrain/FoliageSystem.ts:287

reset() ​

ts
reset(): void;

Defined in: terrain/FoliageSystem.ts:884

Forget pictured impostors and loaded models (tests, a renderer change).

Returns ​

void