-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera-switch.html
103 lines (84 loc) · 3.41 KB
/
camera-switch.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello, WebVR! - A-Frame</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-animation-component/dist/aframe-animation-component.min.js"></script>
<script>
AFRAME.registerComponent('cursor-listener', {
init: function () {
var camera = document.querySelector('a-camera');
var firstCameraEl = document.querySelector('#firstCamera');
var secondCameraEl = document.querySelector('#secondCamera');
var cursor = document.createElement('a-cursor');
cursor.setAttribute('color', 'white');
console.log('camera: ' + camera);
if (camera.getAttribute('active')){
console.log('camera true');
camera.appendChild(cursor);
}
this.el.addEventListener('click', function (evt) {
console.log(camera.getAttribute('id'));
if (camera.getAttribute('id') === 'firstCamera') {
console.log('case 1');
camera = document.querySelector('a-camera');
secondCameraEl.setAttribute('camera', 'active', true)
secondCameraEl.setAttribute('rotation', '0 145 0');
secondCameraEl.appendChild(cursor);
} else {
console.log('case 1');
firstCameraEl.setAttribute('camera', 'active', true)
firstCameraEl.appendChild(cursor);
}
})
}
})
</script>
</head>
<body>
<a-scene>
<a-assets>
<audio id="click-sound" crossorigin="anonymous" src="https://cdn.aframe.io/360-image-gallery-boilerplate/audio/click.ogg"></audio>
</a-assets>
<a-box cursor-listener sound="on: click; src: #click-sound" position="-1 2 -3" color="#4CC3D9" shadow>
<a-animation attribute="position"
from="-1 2 -3"
to="-1 2.1 -3"
repeat="indefinite"
direction="alternate">
</a-animation>
</a-box>
<a-box cursor-listener sound="on: click; src: #click-sound" position="0 0.75 -3" color="#EF2D5E" shadow>
<a-animation attribute="position"
from="0 0.85 -3"
to="0 0.75 -3"
repeat="indefinite"
direction="alternate">
</a-animation>
</a-box>
<a-box cursor-listener sound="on: click; src: #click-sound" position="1.25 1.5 -3" color="#FFC65D" shadow>
</a-box>
<a-box
cursor-listener=""
sound="on:click;src:https://cdn.aframe.io/360-image-gallery-boilerplate/audio/click.ogg"
position="1.6 1.1 -4"
color="#4CC3D9"
shadow="" material="color:#862aff">
<a-animation attribute="position" from="0.6 1.1 -4" to="0.6 1.2 -4.0" repeat="indefinite" direction="alternate">
</a-animation>
</a-box>
<a-plane position="0 0 -4" rotation="-90 0 0" width="8" height="8" color="#9eef37" shadow></a-plane>
<a-sky color="black"></a-sky>
<a-entity position="0 0 0">
<a-camera id='firstCamera' active="true">
</a-camera>
</a-entity>
<a-entity position="2 1 -8">
<a-camera id='secondCamera' active="false">
</a-camera>
</a-entity>
</a-scene>
</body>
</html>