Minimap Topographic Map
Generates and renders topographic contour lines from terrain heightmap data.
Generates and renders topographic contour lines from terrain heightmap data.
Overview
ui_apps_minimap_topomap scans the terrain heightmap, generates contour lines via marching squares, and builds a spatial index for efficient rendering on the minimap background.
Extension path: lua/ge/extensions/ui/apps/minimap/topomap.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
loadTopoMap | () → bool | Loads terrain, generates contours. Returns false on failure. |
isLoaded | () → bool | Whether the topo map has been generated. |
getHeightmapData | () → table | Returns raw heightmap grid data. |
getHeightmapBounds | () → table | Returns {minX, maxX, minY, maxY} bounds. |
getContourSegments | () → segment[] | Returns array of {level, x1, y1, x2, y2} segments. |
getContourQuadtree | () → kdtreebox2d | Returns spatial index for contour segments. |
drawContours | (td, w, h, scale, camPos, worldToMapXYZ) | Renders visible contour lines on the minimap. |
Internals
Loading Pipeline
loadTopoMap() executes three steps:
- Calculate bounds - Uses navgraph node positions to determine terrain area (capped at ±2000m)
- Scan heightmap - Samples
core_terrain.getTerrainHeight()on a 5m grid - Generate contours - Runs marching squares at 2.5m intervals, builds kd-tree index
Marching Squares
Classic cell-based contour extraction. For each grid cell, the four corner heights are compared against each contour level to determine edge intersections:
-- Cell corners classified as above/below contour level
local caseIndex = 0
if d00 >= zc then caseIndex = caseIndex + 1 end
if d10 >= zc then caseIndex = caseIndex + 2 end
if d11 >= zc then caseIndex = caseIndex + 4 end
if d01 >= zc then caseIndex = caseIndex + 8 end
-- Cases 0 and 15 = no intersectionEach intersection produces a line segment stored as {level, x1, y1, x2, y2}.
Rendering
drawContours queries the kd-tree for segments near the camera, transforms to minimap coords, and draws with brightness proportional to elevation:
local clr = color(128 + level*1.25, 128 + level*1.25, 128 + level*1.25, 255)
local thickness = 1 + (level%10 == 0 and 0.5 or 0) -- major contours thickerRendering is capped at 5000 segments per frame for performance.
Reset
Topo data is cleared on onClientEndMission and onClientStartMission, requiring re-generation per level.
How It Works
- Minimap calls
loadTopoMap()to generate contour data from terrain - Marching squares produces thousands of line segments at 2.5m elevation intervals
- Segments are indexed in a kd-tree for spatial queries
- Each frame,
drawContoursrenders nearby segments with elevation-based brightness - Major contour lines (every 10m) are rendered slightly thicker
Additional Exports
The following exports are available but not yet documented in detail:
M.drawContoursM.getContourQuadtreeM.getContourSegmentsM.getHeightmapBoundsM.getHeightmapDataM.isLoadedM.loadTopoMapM.onClientEndMissionM.onClientStartMission