-
Notifications
You must be signed in to change notification settings - Fork 23
/
test_mp4.html
266 lines (244 loc) · 7.71 KB
/
test_mp4.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
<link rel="shortcut icon" href="" type="image/x-icon" />
<style>
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
#msgDlg {
text-align: center;
line-height: 40px;
font-size: 18px;
width:100%;
height: 40px;
background: white;
position: absolute;
z-index: 100;
opacity: 0;
}
#msgDlg.animate {
-webkit-animation-name: anime1;
-webkit-animation-duration: 2s;
-webkit-animation-timing-function: ease;
}
#msgDlg.animatestop {
-webkit-animation-name: none;
}
@-webkit-keyframes anime1 {
0% {
top: -40px;
opacity: 0;
}
10% {
top: 0;
opacity: 1;
}
90% {
top: 0;
opacity: 1;
}
100% {
top: -40px;
opacity: 0;
}
}
</style>
</head>
<body>
<div id="msgDlg"></div>
<script src="js/es6-promise-2.0.1.min.js"></script>
<script>
window.Promise = window.Promise || ES6Promise.Promise;
var isWebVRSupport = false;
if ('getVRDevices' in navigator) {
isWebVRSupport = true;
}
</script>
<script src="js/three.min_r71.js"></script>
<script src="js/VRControls.js"></script>
<script src="js/VREffect.js"></script>
<script src="js/webvr-polyfill.js"></script>
<script src="js/webvr-manager.js"></script>
<script src="js/websocket-messageparser.js"></script>
<script src="js/OculusRiftEffect.js"></script>
<script>
var msgDlg = document.getElementById('msgDlg');
msgDlg.addEventListener('webkitAnimationEnd', function () {
msgDlg.className = '';
}, false);
var video = document.createElement('video');
var renderer = null;
var camera = null;
var videoTexture = null;
var vrControls = null;
var vrEffect = null;
var oculusEffect = null;
var deviceType = '';
var isChrome = false;
var isVRMode = false;
var url = location.hostname + location.pathname;
var urlArgs = {};
location.search.substr(1).split('&').forEach(function (elm) {
var kvp = elm.split('=');
urlArgs[kvp[0]] = kvp[1];
});
function checkWebGLSupport() {
var gl = null;
try {
var cnv = document.createElement('canvas');
gl = cnv.getContext("webgl") || cnv.getContext("experimental-webgl");
}
catch (e) { }
var ret = !!gl;
gl = null;
return ret;
}
function checkBrowser() {
var ua = navigator.userAgent;
if (ua.indexOf('OPR') != -1) {
return 'opera';
} else if (ua.indexOf('Vivaldi') != -1) {
return 'vivaldi';
} else if (ua.indexOf('Firefox') != -1) {
return 'firefox';
} else if (ua.indexOf('Chrome') != -1) {
return 'chrome';
} else if (ua.indexOf('Trident') != -1) {
return 'iexplorer'
} else {
return '';
}
}
var browser = checkBrowser();
if (/Android|iPhone|iPad|iPod|Windows Phone/i.test(navigator.userAgent)) {
deviceType = 'Mobile';
} else {
deviceType = 'PC';
}
video.loop = true;
//if (deviceType === 'PC') {
// if (browser == 'chrome') {
// //video.src = '/media/MaryOculus.webm';
// video.src = 'media/4000x2000.webm';
// } else {
// video.src = 'media/4000x2000.mp4';
// }
//} else {
// if (isWebVRSupport) {
video.src = 'media/4000x2000.mp4';
// } else {
// video.src = 'media/1920x960.mp4';
// }
//}
window.addEventListener('keydown', function (event) {
if (event.keyCode == 90) { // z
controls.zeroSensor();
}
}, true);
var scene, camera, geometry, material, mesh, vrManager, animationId;
function panoramaViewer() {
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);
geometry = new THREE.SphereGeometry(100, 128, 128);
geometry.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
videoTexture = new THREE.Texture(video);
//videoTexture.generateMipmaps = false;
//videoTexture.magFilter = videoTexture.minFilter = THREE.LinearFilter;
//videoTexture.wrapS = videoTexture.wrapT = THREE.ClampToEdgeWrapping;
videoTexture.minFilter = THREE.LinearFilter;
//videoTexture.format = THREE.RGBFormat;
videoTexture.generateMipmaps = false;
videoTexture.repeat.x = 0.5;
material = new THREE.MeshBasicMaterial({ map: videoTexture, side: THREE.DoubleSide });
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
vrEffect = new THREE.VREffect(renderer);
vrEffect.setSize(window.innerWidth, window.innerHeight);
oculusEffect = new THREE.OculusRiftEffect(renderer, { scale: 1.0 });
vrManager = new WebVRManager(renderer, vrEffect);
vrControls = new THREE.VRControls(camera, null, deviceType == 'PC' ? window.normalModeInputDevice : null);
window.addEventListener('resize', function (event) {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
vrEffect.setSize(window.innerWidth, window.innerHeight);
}, false);
function animate() {
animationId = requestAnimationFrame(animate);
if (urlArgs.pg == 'oculus') {
vrControls.update(true);
videoTexture.needsUpdate = true;
oculusEffect.render(scene, camera, videoTexture);
} else {
vrControls.update(vrManager.isVRMode());
if (vrManager.isVRMode()) {
videoTexture.needsUpdate = true;
vrEffect.render(scene, camera, videoTexture);
} else {
videoTexture.offset.x = .5;
videoTexture.needsUpdate = true;
renderer.render(scene, camera);
}
}
}
animationId = requestAnimationFrame(animate);
}
function pausePoster() {
var div = document.createElement('div');
var span = document.createElement('span');
span.textContent = 'Oculus Riftに表示中';
var br = document.createElement('br');
var button = document.createElement('input');
button.type = 'button';
button.value = '中止';
button.onclick = function () {
vrEffect.vrHMD.wsStart();
}
div.appendChild(span);
div.appendChild(br);
div.appendChild(button);
var s = div.style;
s.height = '40px';
s.lineHeight = '40px';
s.textAlign = 'center';
document.body.appendChild(div);
}
//video.onpause = function (e) {
// console.log('pause');
//}
function mobilePlay() {
document.removeEventListener('click', mobilePlay, true);
event.preventDefault();
video.play();
// 再生した直後だとテクスチャーに表示されない場合があるため
// 時間をおいてビューワーを生成する
setTimeout(function () {
panoramaViewer();
}, 3000);
}
if (deviceType == 'Mobile') {
document.addEventListener('click', mobilePlay, true);
} else {
video.oncanplaythrough = function () {
video.oncanplaythrough = null;
if (urlArgs.pg == 'pause') {
vrEffect = new THREE.VREffect(null, null);
pausePoster();
} else {
video.play();
panoramaViewer();
}
}
}
</script>
</body>
</html>