Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { Pathfinding } = require('three-pathfinding');
const pathfinder = new Pathfinding();
const ZONE = 'level';
/**
* nav
*
* Pathfinding system, using PatrolJS.
*/
module.exports = AFRAME.registerSystem('nav', {
init: function () {
this.navMesh = null;
this.agents = new Set();
},
/**
* @param {THREE.Geometry} geometry
*/
init: function() {
this.pathfinder = new Pathfinding();
},
loadMesh: function(mesh, zone) {
this.el.object3D.updateMatrixWorld();
const geometry = new THREE.Geometry().fromBufferGeometry(mesh.geometry);
geometry.applyMatrix(mesh.matrixWorld);
this.pathfinder.setZoneData(zone, Pathfinding.createZone(geometry));
}
});
setNavMeshGeometry: function (geometry) {
this.navMesh = new THREE.Mesh(geometry);
pathfinder.setZoneData(ZONE, Pathfinding.createZone(geometry));
Array.from(this.agents).forEach((agent) => agent.updateNavLocation());
},
setNavMeshGeometry: function setNavMeshGeometry(geometry) {
this.navMesh = new THREE.Mesh(geometry);
pathfinder.setZoneData(ZONE, Path.createZone(geometry));
Array.from(this.agents).forEach(function (agent) {
return agent.updateNavLocation();
});
},