Navigation · interface
NavGraph
A graph to path over: nodes somewhere in the world, edges between them, and a cost per edge.
Explained in Navigation.
interface NavGraphimport type { NavGraph } from '@driftengine/nav';In depth
A graph rather than a navigation mesh, and that is a decision rather than a first step. A mesh is what you build when walkable space is an arbitrary region and an agent may cross it anywhere; a graph is what you build when the ways through a world are already a network — roads, corridors, rails, docking lanes, the connections between rooms. Consumers of this engine keep arriving with the second: one reported that they extract a road graph from their world already and that their agents still walk straight at the target and wedge against a wall on the way, about once every two minutes of play. A mesh would have asked them to throw that away and start from geometry.
What it costs is honest and worth saying at the top: an agent on a graph travels along edges, so it takes corners the graph has and none it does not. Open ground crossed by two nodes is crossed in one straight line. If a world's walkable space genuinely is a region, this is the wrong structure and a mesh is the row that is still open.
Structure of arrays, CSR adjacency, everything typed. The search below runs inside a frame budget against a graph a consumer may rebuild when the world changes, so nothing here holds an object per node and nothing allocates during a query.
Properties
| Name | Type | Description |
|---|---|---|
positionsreadonly | Float32Array | xyz per node, in world units. |
nodeCountreadonly | number | |
edgeStartreadonly | Uint32Array | CSR offsets: node i's edges are [edgeStart[i], edgeStart[i + 1]). Length nodeCount + 1. |
edgeTargetreadonly | Uint32Array | The node at the far end of each edge. |
edgeCostreadonly | Float32Array | What each edge costs to traverse. Distance unless the caller said otherwise. |