-
Notifications
You must be signed in to change notification settings - Fork 2
/
holoplay图像示例.html
76 lines (66 loc) · 2.6 KB
/
holoplay图像示例.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
<html>
<head>
<title>
holoplay.js tutorial
</title>
</head>
<body>
<!-- reference your own local copy of three.js -->
<script src="C:/Users/Jinli Duan/Downloads/Holoplayjs-1.0.3/holoplayjs/build/three.js"></script>
<script type="module">
// reference your own local copy of holoplay.js这里填写holoplay.js位置
import * as HoloPlay from 'C:/Users/Jinli Duan/Downloads/Holoplayjs-1.0.3/holoplayjs/build/holoplay.module.js';
// just a basic three.js scene, nothing special
const scene = new THREE.Scene();
// adding some lights to the scene
const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 1);
directionalLight.position.set(0, 1, 2);
scene.add(directionalLight);
const ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.4);
scene.add(ambientLight);
// adding three cubes to the scene in different locations
for (let i = 0; i < 3; i++) {
const box = new THREE.Mesh(
new THREE.BoxBufferGeometry(0.05, 0.05, 0.05),
new THREE.MeshLambertMaterial({color: new THREE.Color().setHSL(i / 3, 1, 0.5)}));
box.position.setScalar(i - 1).multiplyScalar(0.05);
scene.add(box);
}
// the holoplay camera should be used like a THREE.PerspectiveCamera
const camera = new HoloPlay.Camera();
// the holoplay renderer should act as your THREE.WebGLRenderer
const renderer = new HoloPlay.Renderer();
// add the renderer's canvas to your web page (it will size to fill the page)
document.body.appendChild(renderer.domElement);
// the update function gets called every frame, thanks to requestAnimationFrame()
function update(time) {
requestAnimationFrame(update);
// render() draws the scene, just like THREE.WebGLRenderer.render()
renderer.render(scene, camera);
}
requestAnimationFrame(update);
// HoloPlay.Buttons will emit events when the display's buttons are touched
const buttons = new HoloPlay.Buttons();
buttons.addEventListener('buttonPressed', (e) => {
switch (e.detail.name) {
case 'left':
camera.rotation.y -= 0.002;
break;
case 'right':
camera.rotation.y += 0.002;
break;
case 'square':
if (camera.position.z > 0.2) {
camera.position.z -= 0.01;
}
break;
case 'circle':
if (camera.position.z < 100) {
camera.position.z += 0.01;
}
break;
}
});
</script>
</body>
</html>