This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app2.html
79 lines (67 loc) · 2.11 KB
/
app2.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
<!doctype html>
<html>
<body>
<script src="https://threejs.org/build/three.min.js"></script>
<script>
(async () => {
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.sortObjects = false;
// renderer.shadowMap.enabled = true;
// renderer.shadowMap.type = THREE.PCFShadowMap;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.matrixAutoUpdate = false;
const camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.1, 1000);
scene.add(camera);
const ambientLight = new THREE.AmbientLight(0x808080, 1);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 1);
directionalLight.position.set(1, 1, 1);
scene.add(directionalLight);
const cubeMesh = (() => {
const geometry = new THREE.BoxBufferGeometry(1, 1, 1)
.applyMatrix(new THREE.Matrix4().makeTranslation(0, 0.5, 0));
const materials = new THREE.MeshPhongMaterial({
color: 0x5c6bc0,
});
const mesh = new THREE.Mesh(geometry, materials);
return mesh;
})();
scene.add(cubeMesh);
const session = await navigator.xr.requestSession();
session.layers && session.layers.push(renderer.domElement);
session.requestAnimationFrame((timestamp, frame) => {
renderer.vr.setSession(session, {
frameOfReferenceType: 'stage',
});
const pose = frame.getViewerPose();
const viewport = session.baseLayer.getViewport(pose.views[0]);
// const width = viewport.width;
const height = viewport.height;
const fullWidth = (() => {
let result = 0;
for (let i = 0; i < pose.views.length; i++) {
result += session.baseLayer.getViewport(pose.views[i]).width;
}
return result;
})();
renderer.setSize(fullWidth, height);
renderer.setPixelRatio(1);
renderer.setAnimationLoop(null);
renderer.vr.enabled = true;
renderer.vr.setSession(session);
renderer.vr.setAnimationLoop(animate);
});
function animate() {
renderer.render(scene, camera);
}
// renderer.setAnimationLoop(animate);
})();
</script>
</body>
</html>