three-pathfinding
Navigation mesh toolkit for ThreeJS, based on PatrolJS.
Installation
npm install --save three-pathfinding
Example
const ZONE = 'level1';
const zone = Path.buildNodes(this.navMesh.geometry);
Path.setZoneData(ZONE, zone);
const group = Path.getGroup(ZONE, a);
const path = Path.findPath(a, b, ZONE, group);
API
Table of Contents
buildNodes
Builds a zone/node set from navigation mesh.
Parameters
Returns Path.Zone
setZoneData
Sets data for the given zone.
Parameters
getGroup
Returns closest node group for given position.
Parameters
zoneID
stringposition
THREE.Vector3
Returns Path.Group
getRandomNode
Returns a random node within a given range of a given position.
Parameters
zoneID
stringgroup
Path.GroupnearPosition
THREE.Vector3nearRange
number
Returns Path.Node
getClosestNode
Returns the closest node to the target position.
Parameters
position
THREE.Vector3zoneID
stringgroup
Path.GroupcheckPolygon
boolean (optional, default false
)
Returns Path.Node
clampStep
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
Path.NodezoneID
stringgroup
Path.GroupendTarget
THREE.Vector3 Updated endpoint.
Returns Path.Node Updated node.
findPath
Returns a path between given start and end points.
Parameters
startPosition
THREE.Vector3targetPosition
THREE.Vector3zoneID
stringgroup
Path.Group
Returns Array<THREE.Vector3>
Thanks to