-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
226 lines (192 loc) · 8.85 KB
/
index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<title>rotor xr test</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="https://gilded-blue-seeker.glitch.me/style.css">
<script>
// WebXR requires HTTPS, so the site doesn't work if someone manually enters
// the URL and ends up using HTTP. To work around this, force redirect from
// http to https for non-localhost addresses.
if (window.location.protocol == "http:" &&
window.location.hostname != "localhost" &&
window.location.hostname != "127.0.0.1" &&
window.location.hostname != "[::1]") {
window.location = window.location.href.replace('http:', 'https:');
}
</script>
<!-- import the webpage's javascript files -->
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-extras.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-environment-component.min.js"></script>
<script src="dist/iphone-inline-video.min.js"></script>
<script>
//
AFRAME.registerComponent("alpha-video", {
init: function () {
this.materialLoaded = this.materialLoaded.bind(this);
// wait until the material is ready
this.el.addEventListener('loaded', this.materialLoaded)
}, materialLoaded: function () {
// grab the material
let material = this.el.getObject3D("mesh").material;
// swap the format
material.map.format = THREE.RGBAFormat;
material.map.needsUpdate = true;
},
remove: function () {
this.el.removeEventListener("loaded", this.materialLoaded)
}
})
// clickable
AFRAME.registerComponent("play-on-click", {
init: function() {
this.el.addEventListener("click", e => {
document.querySelector("#lyrics").play()
})
}
})
AFRAME.registerComponent('hide-in-ar-mode', {
// Set this object invisible while in AR mode.
init: function () {
let vid = document.querySelector("#lyrics");
this.el.sceneEl.addEventListener('enter-vr', (ev) => {
this.wasVisible = this.el.getAttribute('visible');
if (this.el.sceneEl.is('ar-mode')) {
this.el.setAttribute('visible', false);
vid.play();
}
});
this.el.sceneEl.addEventListener('exit-vr', (ev) => {
if (this.wasVisible) this.el.setAttribute('visible', true);
});
}
});
AFRAME.registerComponent('ar-shadows', {
// Swap an object's material to a transparent shadows-only material while
// in AR mode.
schema: {
opacity: {default: 0.3}
},
init: function () {
this.el.sceneEl.addEventListener('enter-vr', (ev) => {
this.wasVisible = this.el.getAttribute('visible');
if (this.el.sceneEl.is('ar-mode')) {
this.savedMaterial = this.el.object3D.children[0].material;
this.el.object3D.children[0].material = new THREE.ShadowMaterial();
this.el.object3D.children[0].material.opacity = this.data.opacity;
this.el.setAttribute('visible', true);
}
});
this.el.sceneEl.addEventListener('exit-vr', (ev) => {
if (this.savedMaterial) {
this.el.object3D.children[0].material = this.savedMaterial;
this.savedMaterial = null;
}
if (!this.wasVisible) this.el.setAttribute('visible', false);
});
}
});
//video handler
AFRAME.registerComponent('video-handler',{
init: function(){
let el = this.el;
let vid = document.querySelector("#lyrics");
vid.pause();
el.addEventListener('mouseenter',function(){
vid.play();
});
el.addEventListener('mouseleave',function(){
vid.pause();
});
}
});
</script>
</head>
<body>
<button id="play-button">play..</button>
<a-scene>
<a-assets timeout="30000">
<!-- Model source: https://sketchfab.com/3d-models/spinosaurus-2135501583704537907645bf723685e7
Model author: https://sketchfab.com/VapTor
Model license: CC Attribution -->
<a-asset-item id="spinosaurus" src="https://cdn.glitch.com/324a5290-5aa7-4efc-92d6-ae0736433b12%2Fspinosaurus.glb" response-type="arraybuffer"></a-asset-item>
<video id="lyrics" src="https://cdn.glitch.com/876e46c2-623d-40ab-942a-7f8ee4a825cc%2FlyricsProResWithAlpha%20HEVC.mp4?v=1611764308770"
preload="auto" loop="true" webkit-playsinline playsinline crossorigin="anonymous">
</video>
<audio id="track" src="https://cdn.glitch.com/d70cd89d-5883-430e-aa23-db6ffd90c2e4%2Fmusicclip.mp3?v=1611328885317" preload="yes"></audio>
</a-assets>
<!-- music and video autoplay here for demo.. need to improve -->
<script>
var vid = document.getElementById('lyrics');
var audio = document.getElementById('track');
var vidEnableInLine = document.querySelector('lyrics');
console.log(vid, track);
document.getElementById('play-button').addEventListener("click", function(e){
this.style.display = 'none';
vid.play();
//audio.play();
}, false);
</script>
<a-camera position="0 1.2 0"></a-camera>
<!-- Environment for 2D and VR viewing. It's auto-hidden in AR mode. -->
<a-entity environment="preset: tron; lighting: none; shadow: none; lightPosition: 0 2.15 0"
hide-in-ar-mode></a-entity>
<a-plane class="interactable" scale="2 2 2" position="0 1 -2" material="src: #lyrics; transparent: true;" alpha-video
play-on-click video-handler>
</a-plane>
<a-entity light="type: ambient; intensity: 0.5;"></a-entity>
<a-light type="directional"
light="castShadow: true;
shadowMapHeight: 1024;
shadowMapWidth: 1024;
shadowCameraLeft: -7;
shadowCameraRight: 5;
shadowCameraBottom: -5;
shadowCameraTop: 5;"
id="light"
target="dino"
position="-5 3 1.5"></a-light>
<!-- This shadow-receiving plane is only visible in AR mode. -->
<a-plane height="15" width="15" position="0 0 -3" rotation="-90 0 0"
shadow="receive: true"
ar-shadows="opacity: 0.3"
visible="false"></a-plane>
</a-scene>
<div id="text">
<h1>r test for VR/AR</h1>
<p>
Model: <a href="https://sketchfab.com/3d-models/spinosaurus-2135501583704537907645bf723685e7">Spinosaurus</a> by
<a href="https://sketchfab.com/VapTor">Vaptor-Studio</a>.
</p>
<p>
Size: <button id="btn_full">Full</button>
<button id="btn_half">1/2</button>
<button id="btn_quarter">1/4</button>
</p>
<p>
To try WebXR's experimental AR mode, use an <a href="https://developers.google.com/ar/discover/supported-devices">ARCore-compatible</a>
Android phone with Chrome v79+ and enable <b>WebXR AR Module</b> in chrome://flags.
</p>
<p>
Powered by <a href="https://aframe.io/blog/aframe-v1.0.0/">A-Frame v1.0.0</a>.
</p>
</div>
<script>
function setSize(scale) {
document.getElementById('dino').setAttribute('scale', {x: scale, y: scale, z: scale});
}
document.getElementById('btn_full').onclick = setSize.bind(this, 1);
document.getElementById('btn_half').onclick = setSize.bind(this, 0.5);
document.getElementById('btn_quarter').onclick = setSize.bind(this, 0.25);
</script>
<!-- include the Glitch button to show what the webpage is about and
to make it easier for folks to view source and remix -->
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
<script src="https://button.glitch.me/button.js"></script>
</body>
</html>