Navigation mesh toolkit for ThreeJS, based on PatrolJS.
npm install --save three-pathfinding
const Path = require('three-pathfinding');
const pathfinder = new Path();
// Create level.
const ZONE = 'level1';
pathfinder.setZoneData(ZONE, Path.createZone(this.navMesh.geometry));
// Find path from A to B.
const groupID = pathfinder.getGroup(ZONE, a);
const path = pathfinder.findPath(a, b, ZONE, groupID);
Defines an instance of the pathfinding module, with one or more zones.
Sets data for the given zone.
Parameters
Returns closest node group ID for given position.
Parameters
zoneID
stringposition
THREE.Vector3
Returns number
Returns a random node within a given range of a given position.
Parameters
Returns Node
Returns the closest node to the target position.
Parameters
Returns Node
Returns a path between given start and end points. If a complete path cannot be found, will return the nearest endpoint available.
Parameters
startPosition
THREE.Vector3 Start position.targetPosition
THREE.Vector3 Destination.zoneID
string ID of current zone.groupID
number Current group ID.
Returns Array<THREE.Vector3> Array of points defining the path.
Clamps a step along the navmesh, given start and desired endpoint. May be used to constrain first-person / WASD controls.
Parameters
start
THREE.Vector3end
THREE.Vector3 Desired endpoint.node
NodezoneID
stringgroupID
numberendTarget
THREE.Vector3 Updated endpoint.
Returns Node Updated node.
(Static) Builds a zone/node set from navigation mesh geometry.
Parameters
geometry
THREE.Geometry
Returns Zone
Defines a zone of interconnected groups on a navigation mesh.
Properties
Defines a group within a navigation mesh.
Defines a node (or polygon) within a group.
Properties