-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-scene.html
93 lines (72 loc) · 2.78 KB
/
example-scene.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
<!DOCTYPE html>
<html>
<title>HCAP + three.js example scene</title>
<body>
<h1>Tap or click to begin playback</h1>
<script src="https://threejs.org/build/three.min.js"></script>
<script src="holovideoobject-min.js"></script>
<script src="https://cdn.dashjs.org/v3.2.2/dash.mediaplayer.min.js"></script>
<script>
// Initialize canvas and WebGL:
container = document.createElement('div');
document.body.appendChild(container);
var canvas = document.createElement('canvas');
var context = canvas.getContext('webgl2');
if (!context) { // WebGL2 not available, fall back to WebGL1
context = canvas.getContext('webgl');
if (!context) {
alert('Unable to initialize WebGL. Your browser or machine may not support it.');
}
}
// Setup three.js renderer:
renderer = new THREE.WebGLRenderer({antialias: true, canvas: canvas, context: context});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.gammaOutput = true;
renderer.domElement.addEventListener('mousedown', onMouseDown, false);
renderer.domElement.addEventListener('touchstart', onMouseDown, false);
container.appendChild(renderer.domElement);
// Setup scene:
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 10, 2000);
camera.position.set(0, 300, 1000);
scene = new THREE.Scene();
scene.background = new THREE.Color(0x6495ed);
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set(-0.5, 0.5, 1).normalize();
scene.add(light);
// Add some test geometry:
var boxGeometry = new THREE.BoxBufferGeometry(200, 200, 200);
var boxMaterial = new THREE.MeshLambertMaterial({color: 0xff0000});
boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
boxMesh.position.set(150, 100, 0);
scene.add(boxMesh);
// Add HCap content:
hvo = new HoloVideoObjectThreeJS(
renderer,
function(mesh) {
mesh.position.set(-150, 0, 0);
mesh.rotation.set(0, -3.14, 0);
mesh.scale.set(0.2, 0.2, 0.2);
scene.add(mesh);
});
hvo.open("tennis-web/video.hcap", {autoloop:true, audioEnabled:true});
// Start animation loop:
animate();
function onMouseDown() {
if (hvo.state == HoloVideoObject.States.Opened ||
hvo.state == HoloVideoObject.States.Opening) {
hvo.play();
}
}
function animate() {
requestAnimationFrame(animate);
// animate box test geometry:
boxMesh.rotation.y += 0.01;
// update hologram to latest frame of playback:
hvo.update();
// let three.js render the scene:
renderer.render(scene, camera);
}
</script>
</body>
</html>