NikLever / ThreeJS-NavMesh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ThreeJS - Navigation Mesh

Screenshot Use RecastHelper to create a navigation mesh from ThreeJS geometry

  1. Add the threeJS library as folder three
  2. If you use npm install --save three, then change the importmap paths in example/index.html
  3. Import RecastHelper
import { RecastHelper  } from "../recast/RecastHelper.js";
  1. Create a new instance of RecastHelper. If the path to recast.wasm is not ../recast/recast.wasm then add the path as a parameter to the constructor.
const helper = new RecastHelper();
//If path const helper = new RecastHelper(PATH_TO_RECAST.WASM);
  1. Pass the scene or a Group and Params (optional) to the createNavMesh method of the helper
helper.createNavMesh(scene, {
  cellSize: 0.03,
  regionMinSize: 0.5,
  agentRadius: 0.3,
  agentHeight: 1.5
});

  1. createNavMesh is an async promise. Add a then. It will receive the created mesh.
helper.createNavMesh(scene, {
  cellSize: 0.03,
  regionMinSize: 0.5,
  agentRadius: 0.3,
  agentHeight: 1.5
}).then( (mesh) => { if (mesh){
  scene.add( mesh );
}
});

See the example for usage

About


Languages

Language:JavaScript 89.2%Language:HTML 10.8%