@relu-interactives/spatial-ecs
@relu-interactives/spatial-ecs / components / TerrainComponent
Class: TerrainComponent ​
Defined in: components/Terrain.ts:69
Ground you can sculpt and paint: a heightmap drawn in chunks that get simpler with distance, painted in up to four colour layers, with a physics collider and an optional occluder role (hills hide what's behind them).
Its shape comes from dataPath (a .terrain file the editor writes when you sculpt or paint) or, without one, from noise: the same settings always make the same terrain, so a big world can start with no file at all. The entity's origin is the terrain's centre; it spans size metres on X and Z.
Add GrassComponent and ScatterComponent to the same entity for grass, trees and rocks on it. Scripts read the ground with this.world.terrain?.heightAt(x, z).
Extends ​
Constructors ​
Constructor ​
new TerrainComponent(options?): TerrainComponent;Defined in: components/Terrain.ts:94
Parameters ​
| Parameter | Type |
|---|---|
options | TerrainOptions |
Returns ​
TerrainComponent
Overrides ​
Properties ​
| Property | Type | Default value | Description | Defined in |
|---|---|---|---|---|
size | number | 256 | Metres per side. | components/Terrain.ts:71 |
resolution | number | 257 | Height samples per side (65 to 2049). More is finer and heavier. | components/Terrain.ts:73 |
dataPath | string | "" | A .terrain file with sculpted heights and paint. Empty: made from noise. | components/Terrain.ts:75 |
noise | TerrainNoise | undefined | - | components/Terrain.ts:76 |
layers | TerrainLayer[] | undefined | - | components/Terrain.ts:77 |
autoPaint | boolean | true | Painted by height and slope instead of by hand (only without a file). | components/Terrain.ts:79 |
paintRules | TerrainPaintRule[] | undefined | - | components/Terrain.ts:80 |
chunkQuads | number | 64 | Grid squares per chunk side. Each chunk is one draw. | components/Terrain.ts:82 |
lodDistance | number | 80 | Metres from the camera at which chunks drop to half detail, then quarter at twice that, and so on. 0: always full. | components/Terrain.ts:84 |
flatShading | boolean | false | Faceted, low-poly shading. | components/Terrain.ts:86 |
castShadow | boolean | false | - | components/Terrain.ts:87 |
receiveShadow | boolean | true | - | components/Terrain.ts:88 |
collider | boolean | true | A physics heightfield collider (fixed) that follows the terrain. | components/Terrain.ts:90 |
occluder | boolean | true | Hills hide what's behind them (occlusion culling). | components/Terrain.ts:92 |

