Skip to content

sandip-narwade/three-pathfinding

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

three-pathfinding

Navigation mesh toolkit for ThreeJS, based on PatrolJS.

Quickstart

Installation

npm install --save three-pathfinding

Example

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);

API

Table of Contents

Path

Defines an instance of the pathfinding module, with one or more zones.

setZoneData

Sets data for the given zone.

Parameters

getGroup

Returns closest node group ID for given position.

Parameters

  • zoneID string
  • position THREE.Vector3

Returns number

getRandomNode

Returns a random node within a given range of a given position.

Parameters

Returns Node

getClosestNode

Returns the closest node to the target position.

Parameters

  • position THREE.Vector3
  • zoneID string
  • groupID number
  • checkPolygon boolean (optional, default false)

Returns Node

findPath

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.

clampStep

Clamps a step along the navmesh, given start and desired endpoint. May be used to constrain first-person / WASD controls.

Parameters

  • start THREE.Vector3
  • end THREE.Vector3 Desired endpoint.
  • node Node
  • zoneID string
  • groupID number
  • endTarget THREE.Vector3 Updated endpoint.

Returns Node Updated node.

createZone

(Static) Builds a zone/node set from navigation mesh geometry.

Parameters

  • geometry THREE.Geometry

Returns Zone

Zone

Defines a zone of interconnected groups on a navigation mesh.

Properties

Group

Defines a group within a navigation mesh.

Node

Defines a node (or polygon) within a group.

Properties

Thanks to

About

Navigation mesh utilities for three.js, based on PatrolJS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%