Gen Terrain Module
Procedural terrain and road lattice generation module for the gen editor.
Procedural terrain and road lattice generation module for the gen editor.
Overview
The terrain module provides tools for procedural terrain analysis and road network generation. It reads terrain heightmap data, manages road decals, generates lattice-based road layouts within regions, and provides debug visualization with colored markers. Works with TerrainBlock for height queries and the decal road system for road placement.
Module Table: T
| Field | Type | Description |
|---|---|---|
T.out | table | Output data |
T.out.aregion | table | Generated regions |
T.out.default | table | Default generation parameters |
Default Parameters
| Parameter | Default | Description |
|---|---|---|
M2S_MARG | 16 | Margin of lattice starts inside region |
LAT_SPACE | 15 | Lattice road spacing |
RAND_RATE | 0.2 | Grid randomization share |
WMI_TOMERGE | 1.24 | Width ratio to extend slice to highway |
SLICE_MIN | 20 | Minimum lattice slice length |
END_MIN | 8 | Minimum hanging end length |
Key Functions
| Function | Description |
|---|---|
T.inject(oD) | Injects the decal module dependency |
forZ(p) | Returns terrain height at a 2D position via core_terrain.getTerrainHeight |
toMark(list, cname, f, r, op, keepz) | Converts a point list to colored debug markers |
clear() | Deletes all generated decals and clears state |
Debug Marker Colors
| Color Name | RGB | Description |
|---|---|---|
red | (1,0,0) | Error/boundary markers |
green | (0,1,0) | Success/valid markers |
mag | (1,0,1) | Intersection markers |
cyan | (0,1,1) | Path markers |
yel | (1,1,0) | Warning/highlight markers |
white | (1,1,1) | Neutral markers |
blue | (0,0,1) | Info markers |
Terrain Access
-- The module reads terrain data on initialization:
local tb = extensions.editor_terrainEditor.getTerrainBlock()
local grid = tb:getSquareSize() -- Grid resolution
local tersize = tb:getObjectBox():getExtents() / grid -- Terrain size in grid units
local tfr = tb:getWorldBox().minExtents -- World-space origin
-- Height query at any point:
local height = core_terrain.getTerrainHeight(point)Dependencies
| Module | Path |
|---|---|
| Utils | /lua/ge/extensions/editor/gen/utils |
| Render | /lua/ge/extensions/editor/gen/render |
| Decal (injected) | /lua/ge/extensions/editor/gen/decal |
Usage Example
local T = require('/lua/ge/extensions/editor/gen/terrain')
-- Inject the decal module dependency
T.inject(D)
-- Mark points on the terrain for debugging
toMark({vec3(100,100,0), vec3(200,200,0)}, 'red')
-- Clear all generated content
clear()
-- Access generation parameters
local spacing = T.out.default.LAT_SPACE -- 15Exported Functions
T.decalDel(ind)
Deletes a generated road decal by index.
ind(number) - Index into internal adec array
T.onUpdate()
Per-frame update callback. Renders debug markers and region overlays.
T.inject(oD)
Injects the decal module dependency.
oD(table) - Decal module reference
T.clear()
Deletes all generated decals, resets terrain materials, and clears state.
Note:
onValandtestare internal (local) functions and are NOT exported on the module table.
See Also
- Gen Decal - Road/decal generation
- Gen Region - Urban region generation
- Gen Network - Road network topology
- Gen Render - Debug visualization
Gen Render Module
Debug rendering utilities for the gen editor framework - paths, points, labels, and circles.
Editor Gen Test
Internal test/debug module for the Building Architect Tool (BAT) procedural generation system. Contains test routines for mesh generation, DAE export, LOD creation, XML manipulation, and building geom