Editor Tool Utilities – Util
Common utility functions shared across spline-editing tools. Provides mouse interaction, raycasting, unit conversions, colour generation, spline helpers, GLTF export, and PNG debug output.
Common utility functions shared across spline-editing tools. Provides mouse interaction, raycasting, unit conversions, colour generation, spline helpers, GLTF export, and PNG debug output.
Public API
| Function | Signature | Description |
|---|---|---|
M.isMouseHoveringOverTerrain | () → bool | True if mouse is not over any ImGui window or gizmo |
M.mouseOnMapPos | () → vec3 | Raycasts camera-mouse ray to static geometry, returns hit point |
M.vertRaycast | (pos) | Modifies pos.z in-place by raycasting downward to terrain surface |
M.fastArrayCopy | (arr) → table | Shallow copies a simple array |
M.msToMph | (ms) → number | Converts m/s to mph |
M.msToKph | (ms) → number | Converts m/s to kph |
M.sumOverNonArrayTable | (t) → number | Sums all values in a non-array table |
M.getMeshBox | (meshPath) → table | Returns bounding box info {minExtents, maxExtents, center, extents} for a TSStatic shape |
M.getBlueToRedColour | (value, min, max) → color | Blue-to-red gradient colour by value |
M.getHueBasedColour255 | (t) → r, g, b | Hue-based colour (blue=0 to red=1) in 0-255 range |
M.hsvToRgb255 | (h, s, v) → r, g, b | HSV to RGB (0-255) conversion |
M.generateUniqueName | (baseName, prefix) → string | Generates a unique scene-tree name |
M.computeIdToIdxMap | (splines, map) | Fills a map of spline.id → array index |
M.getNumMaterials | () → number | Returns count of terrain materials |
M.getPolyLength | (pts) → number | Returns total length of a polyline |
M.getMinMaxWidth | (spline) → wMin, wMax | Returns min/max widths of a spline |
M.isWidthFixed | (nodes) → bool, width | True if all node widths are within tolerance |
M.filterClosePointsXY | (points, minDist) → table | Removes consecutive points closer than minDist in XY |
M.calculateAverageSpacingXY | (positions, minSpacing) → number | Estimates average XY spacing via Catmull-Rom simulation |
M.doesPathContainNode | (path, nodeKey) → bool, idx | Checks if a nav graph path contains a node key |
M.flipSplineDirection | (spline) | Reverses spline direction in-place |
M.goToSpline | (points) | Moves camera directly above the spline (top-down view) |
M.buildRibbonMeshFromPolyline | (points, widths, binormals) → table | Builds triangle mesh from ribbon polyline |
M.buildRibbonGLTF | (points, widths, binormals) → table | Generates embedded GLTF JSON for a ribbon mesh |
M.getSourcesSingle | (spline) → table | Returns sources (pos/width/binormal) from a single spline |
M.getAllSources | (splines) → table | Returns sources from all enabled splines |
M.hsvToRgb | (h, s, v) → r, g, b | HSV to RGB (0-1 range) |
M.flipBitmapY | (bmpIn) → GBitmap | Vertically flips a GBitmap |
M.writeMaskToPng | (mask, path) | Debug: writes binary mask to 16-bit PNG |
M.writePathsToPng | (paths, w, h, path) | Debug: writes vectorised paths to PNG |
M.writeWidthsToPng | (paths, widths, w, h, path) | Debug: writes width-visualised paths to PNG |
Code Examples
local util = require('editor/toolUtilities/util')
-- Check if mouse is over terrain (not over UI)
if util.isMouseHoveringOverTerrain() then
local mousePos = util.mouseOnMapPos()
-- Process mouse click on terrain
end
-- Conform a point to terrain surface
local pos = vec3(100, 200, 500)
util.vertRaycast(pos) -- pos.z is now terrain height + 0.05
-- Unit conversions
local mph = util.msToMph(30) -- 67.1 mph
local kph = util.msToKph(30) -- 108.0 kph
-- Get a blue-to-red colour for elevation visualisation
local col = util.getBlueToRedColour(elevation, 0, maxElevation)
-- Generate a unique name for a scene object
local name = util.generateUniqueName('Bridge', 'Road')
-- Get width range of a spline
local wMin, wMax = util.getMinMaxWidth(mySpline)
-- Move camera above a spline for overview
util.goToSpline(mySpline.nodes)
-- Export a ribbon as GLTF for external use
local gltf = util.buildRibbonGLTF(
spline.divPoints, spline.divWidths, spline.binormals)
local json = jsonEncode(gltf)
writeFile('/export/ribbon.gltf', json)
-- Get sources for mask export or terrain operations
local sources = util.getSourcesSingle(mySpline)
local allSources = util.getAllSources(allSplines)See Also
- Tool Utilities - Fit Polyline - Related reference
- Editor Tool Utilities – Geometry - Related reference
- Editor Tool Utilities – Gizmo - Related reference
- World Editor Guide - Guide
Editor Tool Utilities – Terrain Painter
Paints terrain materials underneath a spline by rasterising the spline polygon to the terrain grid. Supports revertable operations with stored undo data.
Editor Element Helper
Reusable form builder for editor UI - creates typed form elements (numeric, string, bool, transform, modelConfig, file, dropdown, vehicleFilter, zoneSelector, etc.) with automatic default data generat