Track Builder - Basic Centers
Generates center road surface mesh geometry for track segments in the track builder system.
Generates center road surface mesh geometry for track segments in the track builder system.
Overview
util_trackBuilder_basicCenters provides center road cross-section shapes (regular, flat, low, halfRegular) and compiles them into 3D mesh data. Uses a width-based LUT (look-up table) system so normals and vertices are precomputed per width step for performance.
Module path: lua/ge/extensions/util/trackBuilder/basicCenters.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
getMeshes | (segment) → table | Returns an array containing the center road mesh for the segment. |
clearShapes | () | Clears all precomputed LUT data for all shapes. |
Internals
Available Shapes
| Shape | Description |
|---|---|
regular | Full road profile with raised bumps on top and bottom edges (12 cross-points). |
halfRegular | Half-width version of regular (7 cross-points). |
flat | Simple flat rectangle (4 cross-points). |
low | Simplified low-profile road (6 cross-points). |
Width-Based LUT System
Unlike borders (which use fixed-width shapes), center meshes vary width per point. The system precomputes vertex positions and normals for each discrete width step:
computeNormals(segment, shape)- scans segment points for min/max width.- For each needed width (in
LUTDetail= 10 subdivisions per unit), computes:- Scaled vertex positions from cross-section points.
- Smooth or sharp normals depending on
crossPoints[i].sharp. - UV X coordinates relative to
uvCenterIndex.
- Cached in
shape.vertexLUT[scaledWidth].
UV Mapping
- U axis: Distance along the cross-section from center, scaled by
uv.width = 0.2. - V axis:
point.uvY * uv.height(along-track distance).
Each shape defines uvCenterIndex - indices whose UV X is treated as zero.
Mesh Compilation
compileMeshInfo(segment, shape):
- For each quality-filtered point, looks up the LUT entry for the point's width.
- Transforms vertices/normals into world space using the point's orientation.
- Builds face indices connecting consecutive cross-sections.
- Adds start/end caps if configured.
Quality Fallback
At quality level 4, all shapes fall back to low.
Output Format
{
verts = {{x,y,z}, ...},
uvs = {{u,v}, ...},
normals = {{x,y,z}, ...},
faces = {{v, n, u}, ...},
material = "track_editor_A_center",
tag = "center"
}How It Works
- Track builder assigns a
centerMeshshape name to each segment. getMeshes(segment)computes width-dependent normals, then compiles the mesh.- LUT caching means repeated widths are fast.
- Call
clearShapes()to reset caches when track parameters change.
Lua Examples
-- Used internally by track builder:
local centerMeshes = extensions.util_trackBuilder_basicCenters.getMeshes(segment)
-- Returns array: {centerMeshData}
-- Clear LUT cache after parameter changes
extensions.util_trackBuilder_basicCenters.clearShapes()Additional Exports
M.clearShapes- (undocumented)M.getMeshes- (undocumented)