https://github.com/wanadev/babylon-navigation-mesh
A library to move on navigation mesh with BABYLON.js
https://github.com/wanadev/babylon-navigation-mesh
Last synced: 5 months ago
JSON representation
A library to move on navigation mesh with BABYLON.js
- Host: GitHub
- URL: https://github.com/wanadev/babylon-navigation-mesh
- Owner: wanadev
- License: mit
- Created: 2016-02-26T16:31:14.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-10T16:31:06.000Z (about 4 years ago)
- Last Synced: 2024-11-17T22:39:21.480Z (6 months ago)
- Language: JavaScript
- Size: 4.97 MB
- Stars: 73
- Watchers: 13
- Forks: 20
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Babylon-navigation-mesh
[](http://badge.fury.io/js/babylon-navigation-mesh)
[Demo](http://wanadev.github.io/babylon-navigation-mesh/)
A toolkit to navigate on a mesh with BABYLON.js. Largely inspired by [PatrolJS](https://github.com/nickjanssen/PatrolJS) for ThreeJS.
Babylon-navigation-mesh is a path finder for AI agents. It use the A star and Funnel algorithms to calculate a path on a navigation mesh.
## Usage
Add the npm package [babylon-navigation-mesh](https://www.npmjs.com/package/babylon-navigation-mesh) to your project:
npm install babylon-navigation-mesh --save
or clone:
git clone [email protected]:wanadev/babylon-navigation-mesh.git
npm install
npm run buildthen
var Navigation = require("babylon-navigation-mesh");
And create your object and the associated graph:
```javascript
var navigation = new Navigation();
var scene = engine.scene;var navmesh = scene.getMeshByName("Navmesh");
var zoneNodes = navigation.buildNodes(navmesh);
navigation.setZoneData('scene', zoneNodes);
```To calculate the path :
```javascript
var zone = navigation.getGroup('scene', agentPosition);
var path = navigation.findPath(agentPosition, dest, 'scene', zone);
```
And to project a position on the navmesh:```javascript
var newPosition = navigation.projectOnNavmesh(this.position, 'scene', navigation.getGroup('level', this.position));
```An article is available to create and use a navigation mesh [here](https://www.wanadev.fr/43-tuto-creer-et-utiliser-un-maillage-de-navigation-avec-babylon-js/) (french)
## Demo
