NavGrid
Defined in: ai/nav/NavGrid.ts:52
A uniform-cost square grid with a walkability mask. gy increases with world
+Y; a Y-down source (e.g. a tilemap) flips rows when it builds the grid, so
NavGrid itself stays direction-agnostic.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new NavGrid(
opts):NavGrid
Defined in: ai/nav/NavGrid.ts:71
Parameters
Section titled “Parameters”Returns
Section titled “Returns”NavGrid
Properties
Section titled “Properties”cellSize
Section titled “cellSize”
readonlycellSize:number
Defined in: ai/nav/NavGrid.ts:57
height
Section titled “height”
readonlyheight:number
Defined in: ai/nav/NavGrid.ts:56
originX
Section titled “originX”
readonlyoriginX:number
Defined in: ai/nav/NavGrid.ts:59
Cell (0,0)’s centre.
originY
Section titled “originY”
readonlyoriginY:number
Defined in: ai/nav/NavGrid.ts:60
originZ
Section titled “originZ”
readonlyoriginZ:number
Defined in: ai/nav/NavGrid.ts:62
The depth the grid lies at — carried onto every waypoint it hands back.
readonlyup:Vec3
Defined in: ai/nav/NavGrid.ts:54
The grid lies in x/y, so off it is toward whoever is looking at the scene.
Implementation of
Section titled “Implementation of”walkable
Section titled “walkable”
readonlywalkable:Uint8Array
Defined in: ai/nav/NavGrid.ts:64
Row-major walkability, 1 = walkable. Mutable via setWalkable.
readonlywidth:number
Defined in: ai/nav/NavGrid.ts:55
Methods
Section titled “Methods”cellToWorld()
Section titled “cellToWorld()”cellToWorld(
gx,gy):Vec3
Defined in: ai/nav/NavGrid.ts:170
Centre of cell (gx, gy) in world space.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”clearanceAt()
Section titled “clearanceAt()”clearanceAt(
gx,gy):number
Defined in: ai/nav/NavGrid.ts:161
Cells from here to the nearest thing that blocks — off the grid counts as blocked. An agent is a body: a path hugging a wall is walkable for the cell it was planned through and a wall for the half hanging over the next. Computed on first ask, dropped when walkability changes.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”number
clearCosts()
Section titled “clearCosts()”clearCosts():
void
Defined in: ai/nav/NavGrid.ts:151
Put every cell back to open-ground price, before the areas are re-marked.
Returns
Section titled “Returns”void
clearObstructions()
Section titled “clearObstructions()”clearObstructions():
void
Defined in: ai/nav/NavGrid.ts:124
Lift everything off the ground at once, before the obstacles are re-marked.
Returns
Section titled “Returns”void
costAt()
Section titled “costAt()”costAt(
gx,gy):number
Defined in: ai/nav/NavGrid.ts:136
What crossing a cell costs, against 1 for open ground. Cheap makes a route prefer it and dear makes it go round; it never blocks, because a price an agent will not pay when there is another way is still one it pays when there is not.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”number
describe()
Section titled “describe()”describe(
sink):void
Defined in: ai/nav/NavGrid.ts:223
Every walkable cell as a quad, and every edge where the walkable world stops. The corner array is reused between calls — see NavSurfaceSink.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”findWorldPath()
Section titled “findWorldPath()”findWorldPath(
from,to,opts?):Vec3[] |null
Defined in: ai/nav/NavGrid.ts:207
Plan a world-space route between two world points, or null when there is no way. The waypoints carry all three axes: on a flat surface the third is the plane the scene is drawn on, on a spatial one it is the ground the route walks over.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Vec3[] | null
Implementation of
Section titled “Implementation of”inBounds()
Section titled “inBounds()”inBounds(
gx,gy):boolean
Defined in: ai/nav/NavGrid.ts:92
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”boolean
index()
Section titled “index()”index(
gx,gy):number
Defined in: ai/nav/NavGrid.ts:88
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”number
isNavigable()
Section titled “isNavigable()”isNavigable(
p):boolean
Defined in: ai/nav/NavGrid.ts:214
Whether an agent may stand at a world point. Asked of a place the agent has not been routed to — a step sideways to get round another body — which is why it is not the same question as “is there a route here”.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”isWalkable()
Section titled “isWalkable()”isWalkable(
gx,gy):boolean
Defined in: ai/nav/NavGrid.ts:96
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”boolean
nearestWalkable()
Section titled “nearestWalkable()”nearestWalkable(
gx,gy,maxRadius?,clearance?):Cell|null
Defined in: ai/nav/NavGrid.ts:191
Nearest walkable cell to (gx, gy) by outward ring search, or null if the
whole grid is blocked. Used to snap a start/goal that lands on a wall onto
a usable cell before searching.
Parameters
Section titled “Parameters”number
number
maxRadius?
Section titled “maxRadius?”number = 8
clearance?
Section titled “clearance?”number = 0
Returns
Section titled “Returns”Cell | null
setCost()
Section titled “setCost()”setCost(
gx,gy,cost):void
Defined in: ai/nav/NavGrid.ts:141
Parameters
Section titled “Parameters”number
number
number
Returns
Section titled “Returns”void
setObstructed()
Section titled “setObstructed()”setObstructed(
gx,gy,obstructed):void
Defined in: ai/nav/NavGrid.ts:113
Put something in the way of a cell, or take it out again. The map’s own walkability is untouched: an obstacle is a thing standing ON the ground, and lifting it has to give back exactly the ground that was there.
Parameters
Section titled “Parameters”number
number
obstructed
Section titled “obstructed”boolean
Returns
Section titled “Returns”void
setWalkable()
Section titled “setWalkable()”setWalkable(
gx,gy,walkable):void
Defined in: ai/nav/NavGrid.ts:102
Parameters
Section titled “Parameters”number
number
walkable
Section titled “walkable”boolean
Returns
Section titled “Returns”void
worldToCell()
Section titled “worldToCell()”worldToCell(
p):Cell
Defined in: ai/nav/NavGrid.ts:179
Cell containing a world point. May be out of bounds — caller checks.