API ReferenceGE ExtensionseditortoolUtilities
Editor Tool Utilities – Ramer-Douglas-Peucker
Optimised iterative (stack-based) implementation of the Ramer-Douglas-Peucker algorithm for polyline simplification. Operates in-place on arrays of vec3 positions and parallel attribute arrays.
Optimised iterative (stack-based) implementation of the Ramer-Douglas-Peucker algorithm for polyline simplification. Operates in-place on arrays of vec3 positions and parallel attribute arrays.
Public API
| Function | Signature | Description |
|---|---|---|
M.rdpIndices | (nodes, startIdx, endIdx, tol, retList) → table | Core RDP: returns array of kept indices using line-segment distance |
M.simplifyNodes | (nodes, tol) → newCount | Simplifies nodes array in-place |
M.simplifyNodesWidths | (nodes, widths, tol) → newCount | Simplifies nodes + widths in-place |
M.simplifyNodesWidthsNormals | (nodes, widths, normals, tol) → newCount | Simplifies nodes + widths + normals in-place |
M.simplifyNodesVels | (nodes, velocities, tol) → newCount | Simplifies nodes + velocities in-place |
M.simplifyNodesWidthsVelVelLimits | (nodes, widths, velocities, velLimits, tol) → newCount | Simplifies nodes + widths + velocities + velocity limits in-place |
Code Examples
local rdp = require('editor/toolUtilities/rdp')
-- Simplify a polyline with default tolerance (6.0 meters)
local nodes = { vec3(0,0,0), vec3(1,0.01,0), vec3(2,0,0), vec3(3,0,0), vec3(10,5,0) }
local newCount = rdp.simplifyNodes(nodes)
-- nodes is now compacted in-place; excess entries set to nil
log('I', 'rdp', 'Reduced to ' .. newCount .. ' nodes')
-- Simplify nodes and their corresponding widths with custom tolerance
local widths = { 10, 10, 10, 10, 12 }
local count = rdp.simplifyNodesWidths(nodes, widths, 2.0)
-- Full simplification with all parallel arrays
local vels = { 13.5, 13.5, 15, 15, 20 }
local limits = { 30, 30, 30, 30, 30 }
local normals = { vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1), vec3(0,0,1) }
count = rdp.simplifyNodesWidthsVelVelLimits(nodes, widths, vels, limits, 4.0)
-- Get raw indices without in-place modification
local kept = rdp.rdpIndices(originalNodes, 1, #originalNodes, 3.0)
for _, idx in ipairs(kept) do
-- idx references the original array positions to keep
endSee Also
- Tool Utilities - Fit Polyline - Related reference
- Editor Tool Utilities – Geometry - Related reference
- Editor Tool Utilities – Gizmo - Related reference
- World Editor Guide - Guide