-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvr.html
153 lines (123 loc) · 4.12 KB
/
vr.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>CharlieBot - WebCam VR Viewer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0px;
overflow: hidden;
}
#webglviewer {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
z-index: 100;
}
</style>
</head>
<body>
<div id="webglviewer"></div>
<canvas id="tempCanvas"></canvas>
<!--<script type="text/javascript" src="/webiopi.js"></script>-->
<script src="js/three.min.js"></script>
<script src="js/StereoEffect.js"></script>
<script>
var scene,
camera,
renderer,
element,
container,
effect,
canvas,
context;
init();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.001, 700);
camera.position.set(0, 15, 0);
scene.add(camera);
renderer = new THREE.WebGLRenderer();
element = renderer.domElement;
container = document.getElementById('webglviewer');
container.appendChild(element);
effect = new THREE.StereoEffect(renderer);
element.addEventListener('click', fullscreen, false);
canvas = document.getElementById('tempCanvas');
canvas.width = 512;
canvas.height = 288;
canvas.width = nextPowerOf2(canvas.width);
canvas.height = nextPowerOf2(canvas.height);
function nextPowerOf2(x) {
return Math.pow(2, Math.ceil(Math.log(x) / Math.log(2)));
}
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', function(evt) {
//TODO: Add functions for Servo Control through GPIO
console.log('Roll : %f',evt.alpha)
console.log('Yaw : %f',evt.beta)
console.log('Pitch : %f',evt.gamma)
// webiopi().ready(function(){
//webiopi().callMacro("pan_tilt_script.py",[evt.alpha,evt.beta]);
//webiopi.refreshGPIO(true);
//})
}.bind(this));
}
context = canvas.getContext('2d');
texture = new THREE.Texture(canvas);
texture.context = context;
var cameraPlane = new THREE.PlaneGeometry(512, 512);
cameraMesh = new THREE.Mesh(cameraPlane, new THREE.MeshBasicMaterial({
color: 0xffffff, opacity: 1, map: texture
}));
cameraMesh.position.z = -200;
scene.add(cameraMesh);
animate();
}
function animate() {
if (context) {
var piImage = new Image();
//piImage.crossOrigin = "anonymous";
piImage.onload = function() {
console.log('Drawing image');
context.drawImage(piImage, 0, 0, canvas.width, canvas.height);
texture.needsUpdate = true;
}
piImage.src = "stream?time="+new Date().getTime();
}
requestAnimationFrame(animate);
update();
render();
}
function resize() {
var width = container.offsetWidth;
var height = container.offsetHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
effect.setSize(width, height);
}
function update(dt) {
resize();
camera.updateProjectionMatrix();
}
function render(dt) {
effect.render(scene, camera);
}
function fullscreen() {
if (container.requestFullscreen) {
container.requestFullscreen();
} else if (container.msRequestFullscreen) {
container.msRequestFullscreen();
} else if (container.mozRequestFullScreen) {
container.mozRequestFullScreen();
} else if (container.webkitRequestFullscreen) {
container.webkitRequestFullscreen();
}
}
</script>
</body>
</html>