new NavMesh()
Constructs a new navigation mesh.
Members
-
epsilonContainsTest :Number
-
The tolerance value for the containment test.
- Default Value:
- 1
-
epsilonCoplanarTest :Number
-
The tolerance value for the coplanar test.
- Default Value:
- 1e-3
-
graph :Graph
-
The internal navigation graph of this navigation mesh representing neighboring polygons.
-
mergeConvexRegions :Boolean
-
Whether convex regions should be merged or not.
- Default Value:
- true
-
regions :Array.<Polygon>
-
The list of convex regions.
-
nullable spatialIndex :CellSpacePartitioning
-
A reference to a spatial index.
- Default Value:
- null
Methods
-
clampMovement(currentRegion, startPosition, endPosition, clampPosition) → {Polygon}
-
This method can be used to restrict the movement of a game entity on the navigation mesh. Instead of preventing any form of translation when a game entity hits a border edge, the movement is clamped along the contour of the navigation mesh. The computational overhead of this method for complex navigation meshes can be reduced by using a spatial index.
Parameters:
Name Type Description currentRegion
Polygon The current convex region of the game entity.
startPosition
Vector3 The original start position of the entity for the current simulation step.
endPosition
Vector3 The original end position of the entity for the current simulation step.
clampPosition
Vector3 The clamped position of the entity for the current simulation step.
-
clear() → {NavMesh}
-
Clears the internal state of this navigation mesh.
-
findPath(from, to) → {Array.<Vector3>}
-
Returns the shortest path that leads from the given start position to the end position. The computational overhead of this method for complex navigation meshes can greatly reduced by using a spatial index.
Parameters:
Name Type Description from
Vector3 The start/source position.
to
Vector3 The end/destination position.
-
fromPolygons(polygons) → {NavMesh}
-
Creates the navigation mesh from an array of convex polygons.
Parameters:
Name Type Description polygons
Array.<Polygon> An array of convex polygons.
-
getClosestRegion(point) → {Polygon}
-
Returns the closest convex region for the given point in 3D space.
Parameters:
Name Type Description point
Vector3 A point in 3D space.
-
getNodeIndex(region) → {Number}
-
Returns the node index for the given region. The index represents the navigation node of a region in the navigation graph.
Parameters:
Name Type Description region
Polygon The convex region.
Returns:
Number -The respective node index.
-
getRandomRegion() → {Polygon}
-
Returns at random a convex region from the navigation mesh.
-
getRegionForPoint(point, epsilon) → {Polygon}
-
Returns the region that contains the given point. The computational overhead of this method for complex navigation meshes can be reduced by using a spatial index. If no convex region contains the point, null is returned.
Parameters:
Name Type Default Description point
Vector3 A point in 3D space.
epsilon
Number 0.001 Tolerance value for the containment test.
-
updateSpatialIndex() → {NavMesh}
-
Updates the spatial index by assigning all convex regions to the partitions of the spatial index.