Navigation mesh toolkit for ThreeJS, based on PatrolJS. Computes paths between points on a 3D nav mesh, supports multiple zones, and clamps movement vectors for FPS controls. To learn how to create a navigation mesh using Blender, see Creating a Nav Mesh.
npm install --save three-pathfinding
const Pathfinder = require('three-pathfinding');
const pathfinder = new Pathfinder();
// Create level.
const ZONE = 'level1';
pathfinder.setZoneData(ZONE, Pathfinder.createZone(mesh.geometry));
// Find path from A to B.
const groupID = pathfinder.getGroup(ZONE, a);
const path = pathfinder.findPath(a, b, ZONE, groupID);git clone https://github.com/donmccurdy/three-pathfinding.git
cd three-pathfinding
npm install
npm run dev
The demo will start at http://localhost:9966/demo/demo.html.
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
- zoneIDstring
- positionTHREE.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
- startPositionTHREE.Vector3 Start position.
- targetPositionTHREE.Vector3 Destination.
- zoneIDstring ID of current zone.
- groupIDnumber 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
- startTHREE.Vector3
- endTHREE.Vector3 Desired endpoint.
- nodeNode
- zoneIDstring
- groupIDnumber
- endTargetTHREE.Vector3 Updated endpoint.
Returns Node Updated node.
(Static) Builds a zone/node set from navigation mesh geometry.
Parameters
- geometryTHREE.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
