API ReferenceGE ExtensionseditortoolUtilities
Tool Utilities - Fit Polyline
Fits a polyline to an unordered set of points by finding the optimal traversal order that maximises path smoothness and minimises distance.
Fits a polyline to an unordered set of points by finding the optimal traversal order that maximises path smoothness and minimises distance.
Public API
| Function | Signature | Description |
|---|---|---|
M.fitPoly | (components) → orderedComponents | Orders unordered components into a smooth polyline |
Code Example
local fitPoly = require('editor/toolUtilities/fitPoly')
-- Order unordered components (each has .obj with :getPosition())
local ordered = fitPoly.fitPoly(components)
-- Algorithm:
-- 1. Extract positions from component objects
-- 2. Try every point as starting point (brute force)
-- 3. For each start, greedily build path using scoring:
-- - Base score: 1/(distSq + 0.1) - closer is better
-- - Direction bonus: multiply by (1+dot) if dot > 0.5
-- - Sharp turn penalty: multiply by 0.1 if dot < -0.5
-- - Moderate penalty: multiply by (0.5 + dot*0.5) otherwise
-- 4. Maximum neighbor distance: 50m
-- 5. Evaluate path quality:
-- - Smoothness score (70% weight): rewards direction consistency
-- - Distance score (30% weight): penalizes total distance
-- - Direction reversals (dot < 0): heavy -2.0 penalty
-- - Sharp turns (dot < 0.5): penalty proportional to (1-dot)
-- - Smooth continuation (dot >= 0.5): reward = dot value
-- 6. Select path with highest combined score
-- 7. Append any unvisited points at end
-- Input: array of {obj = SceneObject} with :getPosition()
-- Output: same array reordered for smooth polyline traversal
-- Returns input unchanged if fewer than 2 components
-- Use case: ordering spline control points that were
-- placed without explicit ordering (e.g., from selection)See Also
- Editor Tool Utilities – Geometry - Related reference
- Editor Tool Utilities – Gizmo - Related reference
- Editor Tool Utilities – Material Selection Manager - Related reference
- World Editor Guide - Guide
Terraform - Core Engine
Core terraforming engine that modifies terrain heightmaps based on source geometry (roads, splines) using SDF-based falloff, optional noise, and blur smoothing.
Editor Tool Utilities – Geometry
Comprehensive geometry utility library for spline-editing tools. Provides Catmull-Rom interpolation, Frenet frame computation, mouse-hit detection, vector math, polygon operations, and spline manipula