forked from urish/web-ar-experiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcesium.html
76 lines (68 loc) · 3.09 KB
/
cesium.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web AR Experiment</title>
<script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>
<script src="https://rawgit.com/chenzlabs/three.ar.js/0f645a5/dist/three.ar.min.js"></script>
<script src="https://rawgit.com/chenzlabs/aframe-ar/0cf8d5a/dist/aframe-ar.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/cfe5f316/dist/aframe-extras.js"></script>
<script type="text/javascript">
AFRAME.registerComponent('shadow-material', {
init() {
this.material = new THREE.ShadowMaterial();
this.el.getOrCreateObject3D('mesh').material = this.material;
this.material.opacity = 0.3;
}
});
</script>
<!-- Prevent touch causing flicker on iOS. -->
<style> * { -webkit-tap-highlight-color: rgba(0,0,0,0); } </style>
</head>
<body>
<a-scene ar>
<a-camera ar-raycaster raycaster cursor="fuse:false"></a-camera>
<a-assets>
<a-asset id="cesium-man" src="https://cdn.rawgit.com/KhronosGroup/glTF-Sample-Models/29355d23/2.0/CesiumMan/glTF-Binary/CesiumMan.glb"></a-asset>
</a-assets>
<a-entity id="walker">
<a-entity gltf-model="#cesium-man" scale="0.15 0.15 0.15" rotation="0 -90 0" animation-mixer
shadow="cast: true">
</a-entity>
<a-plane width="0.5" height="0.5" position="0 0 0" rotation="-90 0 0"
color="white" shadow="receive: true" shadow-material></a-plane>
</a-entity>
<a-ring id="cursor" color="teal" radius-inner="0.02" radius-outer="0.03" position="0 -3 -3" rotation="-90 0 0"></a-ring>
</a-scene>
<script type="text/javascript">
function onSceneLoaded() {
const raycaster = document.querySelector('[ar-raycaster]');
const cursor = document.querySelector('#cursor');
raycaster.addEventListener('raycaster-intersection', (event) => {
cursor.setAttribute('position', event.detail.intersections[0].point);
});
const walker = document.querySelector('#walker');
const { stringify } = AFRAME.utils.coordinates;
let firstTime = true;
raycaster.addEventListener('click', () => {
const target = raycaster.components.cursor.intersection.point;
if (firstTime) {
walker.setAttribute('position', target);
firstTime = false;
} else {
const currentPosition = walker.object3D.position;
const distance = currentPosition.distanceTo(target);
walker.object3D.lookAt(target);
const animation = document.createElement('a-animation');
animation.setAttribute('attribute', 'position');
animation.setAttribute('to', stringify(target));
animation.setAttribute('dur', distance * 7000);
animation.setAttribute('easing', 'linear');
walker.appendChild(animation);
}
});
}
const scene = document.querySelector('a-scene');
scene.addEventListener('loaded', onSceneLoaded);
</script>
</body>
</html>