-
Notifications
You must be signed in to change notification settings - Fork 2
/
NavigationMeshExample.html
58 lines (49 loc) · 2.25 KB
/
NavigationMeshExample.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Superframe animation</title>
<script src="https://aframe.io/releases/1.0.0/aframe.min.js"></script>
<script src="https://recast-api.donmccurdy.com/aframe-inspector-plugin-recast.js"></script>
<script src="https://cdn.jsdelivr.net/gh/donmccurdy/[email protected]/dist/aframe-extras.js"></script>
<script src="node_modules/animejs/lib/anime.js"></script>
<script>
AFRAME.registerComponent('nav-pointer', {
init: function () {
const el = this.el;// On click, send the NPC to the target location.
el.addEventListener('click', (e) => {
const ctrlEl = el.sceneEl.querySelector('[nav-agent]');
ctrlEl.setAttribute('nav-agent', {
active: true,
destination: e.detail.intersection.point
});
}); // When hovering on the nav mesh, show a green cursor.
el.addEventListener('mouseenter', () => {
el.setAttribute('material', { color: 'green' });
});
el.addEventListener('mouseleave', () => {
el.setAttribute('material', { color: 'crimson' })
});
// Refresh the raycaster after models load.
el.sceneEl.addEventListener('object3dset', () => {
this.el.components.raycaster.refreshObjects();
});
}
});
</script>
</head>
<body>
<a-scene inspector-plugin-recast>
<a-gltf-model src="model/winter_scene/scene.gltf" position="0 0 -5"></a-gltf-model>
<a-gltf-model src="model/winter_scene/navmesh.glb" checkpoint nav-mesh visible="true"></a-gltf-model>
<a-entity position="0 0 5" movement-controls="constrainToNavMesh:true;">
<a-entity camera position="0 1.5 0" look-controls>
<a-cursor></a-cursor>
</a-entity>
</a-entity>
<!-- <a-box nav-agent color="red" position="0 0.7 0"></a-box> -->
</a-scene>
</body>
</html>