Navigation · function

buildContours

One closed loop per region, holes bridged into it, simplified.

Explained in Navigation.

function buildContours(field: VoxelField, regions: RegionField, maxDeviation: number): Contour[]
import { buildContours } from '@driftengine/nav';

Parameters

ParameterTypeDescription
fieldVoxelField
regionsRegionField
maxDeviationnumber

In depth

This took the longest loop and dropped the rest until 2026-09-16, and the limitation was worse than it was written down as. It was stated as losing a pillar — an agent walking through a column in the middle of a room. What it actually did was claim ground: a ring's outer loop is the room's whole perimeter, so simplifying it gives a rectangle covering the pillar and whatever else the watershed carved out of the middle. Measured on ['..........', '....##....', '....##....', '..........'], the ring's polygon came out as the entire ten-by-four map, area 40 where the region is 32 — a navigation mesh asserting that a wall and a neighbouring region are both walkable by the same agent.

Holes are bridged rather than emitted separately. A hole as its own contour would become its own walkable polygon, which is the same defect pointing the other way. A bridge joins the inner loop to the outer along a segment traversed once each way, so the pair becomes one closed loop with a zero-width slit — weakly simple rather than simple, which is what ear clipping wants and what segmentsCross tolerates, since it requires a strict crossing and the two bridge edges are coincident.