-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
43 lines (35 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const THREE = require('three');
Promise.all([
import('recast-navigation'),
import('recast-navigation/three')
]).then(([Recast, RecastThree]) => {
Recast.init().then(() => {
console.log(RecastThree);
const groundMesh = new THREE.Mesh(new THREE.BoxGeometry(5, 0.2, 5));
/**
* @type {import('recast-navigation').SoloNavMeshConfig}
*/
const config = {
borderSize: 0,
cs: 0.2,
ch: 0.2,
walkableSlopeAngle: 35,
walkableHeight: 1,
walkableClimb: 1,
walkableRadius: 1,
maxEdgeLen: 12,
maxSimplificationError: 1.3,
minRegionArea: 8,
mergeRegionArea: 20,
maxVertsPerPoly: 6,
detailSampleDist: 6,
detailSampleMaxError: 1,
};
const positions = groundMesh.geometry.attributes.position.array;
const indices = groundMesh.geometry.index.array;
const { navMesh } = Recast.generateSoloNavMesh(positions, indices, config);
const navMeshQuery = new Recast.NavMeshQuery({ navMesh });
const closestPoint = navMeshQuery.getClosestPoint({ x: 2, y: 1, z: 2 });
console.log(closestPoint.x, closestPoint.y, closestPoint.z);
});
});