Editor Tool Utilities – Polygon Drawing
Manages interactive user-drawn polygons on the map. Supports adding nodes by clicking, inserting nodes on edges, dragging nodes, deleting nodes, and rendering the polygon with terrain-conforming edges
Manages interactive user-drawn polygons on the map. Supports adding nodes by clicking, inserting nodes on edges, dragging nodes, deleting nodes, and rendering the polygon with terrain-conforming edges.
Public API
| Function | Signature | Description |
|---|---|---|
M.getPolygon | () → table | Returns the current polygon (array of vec3 nodes) |
M.isPolygonValid | () → bool | Returns true if the polygon has more than 2 nodes |
M.clearPolygon | () | Clears all polygon nodes |
M.handleUserPolygon | (doubleClickCallback) | Main per-frame handler: renders polygon, processes mouse events for add/insert/drag/delete, calls callback on double-click completion |
Code Examples
local polygon = require('editor/toolUtilities/polygon')
-- Each frame in your editor tool's onEditModeUpdate:
polygon.handleUserPolygon(function(completedPolygon)
-- Called when user double-clicks to finish the polygon
log('I', 'polygon', 'Polygon completed with ' .. #completedPolygon .. ' nodes')
-- Use the polygon for terrain painting, mask export, etc.
processPolygon(completedPolygon)
end)
-- Query the current polygon state
local poly = polygon.getPolygon()
if polygon.isPolygonValid() then
log('I', 'polygon', 'Valid polygon with ' .. #poly .. ' nodes')
end
-- Clear the polygon to start over
polygon.clearPolygon()
-- User interaction model:
-- Click free space → adds new node at end
-- Click on edge → inserts node at that edge position
-- Click on node → selects and starts dragging
-- Hold drag → moves the node
-- Delete key → removes selected node
-- Double-click (3+ pts) → completes polygon, calls callback, clears
-- Alt key → toggles translation gizmo on/offSee 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 – Perlin Noise
Classic 2D Perlin noise implementation with a static permutation table for deterministic, repeatable noise generation.
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.