-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpizzajohn.html
331 lines (278 loc) · 9.46 KB
/
pizzajohn.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!DOCTYPE html>
<html lang="en">
<head>
<title>The First Pizza John for Virtual Reality</title>
<!--
webVR Pizza John experience
uses three.js, Mozilla's webVR basics, and Andrea Hawksley's webVR navigation.
-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background-color: #000;
color: #fff;
margin: 0px;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<audio id='music' src="media/pizzajohn.ogg" autoplay=true loop=true/>
</body>
<!--
three.js 3d library
-->
<script src="js/lib/three.min.js"></script>
<!--
library for fast quaternion rotation
-->
<script src="js/lib/gl-matrix.js"></script>
<!--
VRControls.js acquires positional information from connected VR devices and applies the transformations to a three.js camera object.
-->
<script src="js/vr/PhoneVR.js"></script>
<script src="js/vr/VRControls.js"></script>
<!--
VREffect.js handles stereo camera setup and rendering.
-->
<script src="js/vr/VREffect.js"></script>
<script>
/*
Setup three.js WebGL renderer
*/
var renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0x330000, 1 );
/*
Append the canvas element created by the renderer to document body element.
*/
document.body.appendChild( renderer.domElement );
/*
Create a three.js scene
*/
var scene = new THREE.Scene();
/*
Create a three.js camera
*/
var camera = new THREE.PerspectiveCamera( 110, window.innerWidth / window.innerHeight, 1, 10000 );
/*
Apply VR headset positional data to camera.
*/
var controls = new THREE.VRControls( camera );
/*
Apply VR stereo rendering to renderer
*/
var effect = new THREE.VREffect( renderer );
effect.setSize( window.innerWidth, window.innerHeight );
/*
define interaction variables
*/
var mouseY = 1;
var mouseX = 1;
var clicky = 0;
// create main particles: adapted from aerotwist.com's particle creation tutorial
var particleCount = 500,
particles = new THREE.Geometry(),
pMaterial = new THREE.PointCloudMaterial({
color: 0xFFFFFF,
size: 50,
map: THREE.ImageUtils.loadTexture(
"media/pizzajohn.png"), //pizzajohn modified from Valerie's pizza john design
blending: THREE.AdditiveBlending,
transparent: true
});
for (var p = 0; p < particleCount; p++) {
var pX = Math.random() * 800 - 500,
pY = Math.random() * 500,
pZ = Math.random() * 800 - 500,
particle = (
new THREE.Vector3(pX, pY, pZ)
);
particle.velocity = new THREE.Vector3(
Math.random(),
-Math.random()*2,
Math.random());
particles.vertices.push(particle);
}
var particleSystem = new THREE.PointCloud(
particles,
pMaterial);
particleSystem.sortParticles = true;
scene.add(particleSystem);
//pizza particles, created solely to use the texture. Don't know why that works.
var pizzicles = new THREE.Geometry();
var partCount = 12;
for (var p = 0; p<partCount; p++){
var part = (new THREE.Vector3(-Math.random()*100,0,-Math.random()*100));
part.velocity = new THREE.Vector3(0,0,0);
pizzicles.vertices.push(part);
}
var pizza = new THREE.PointCloud(
pizzicles,
new THREE.PointCloudMaterial({
color: 0xffffff,
size: 50,
map: THREE.ImageUtils.loadTexture("media/pizza.png"), //modified from Jyoti Das https://www.flickr.com/photos/jyotidas/5479387505/
blending: THREE.AdditiveBlending,
transparent: true
}));
/*
Request animation frame loop function
*/
function animate() {
//animate pizza particles
// for (var p = 0; p<partCount; p++){
// //update velocity
// pizzicles.vertices[p].velocity.y -= (pizzicles.vertices[p].y+10)/1000 + Math.random()/100;
// pizzicles.vertices[p].velocity.z += (Math.random() - .5)/200;
// pizzicles.vertices[p].velocity.x += (Math.random() - .5)/200;
// //update position based on velocity
// pizzicles.vertices[p].y += pizzicles.vertices[p].velocity.y;
// pizzicles.vertices[p].z += pizzicles.vertices[p].velocity.z;
// pizzicles.vertices[p].x += pizzicles.vertices[p].velocity.x;
// }
var pCount = particleCount;
if(clicky===0){
particleSystem.material=pMaterial;//reset to pizzajohns
}
if(clicky===1){
particleSystem.rotation.y -= mouseX/50000 - .01;
}
while (pCount--) {
// get the particle
var particle =
particles.vertices[pCount];
// check if we need to reset
if (particle.y < -310) {
particle.y = 500;
particle.x = 800*Math.random() - 500;
particle.z = 800*Math.random() - 500;
particle.velocity.y = -Math.random();
} else if (particle.y > 510){
particle.y = -300;
particle.x = 800*Math.random() - 500;
particle.z = 800*Math.random() - 500;
particle.velocity.y = -Math.random();
}
// update the velocity
if(clicky===0){
particle.velocity.y -= (Math.random() * .01);
particleSystem.material.color.setRGB((mouseX/400)+.5,(mouseX/600)+.5,(mouseY/200)+.5);
} else if (clicky === 1 ) {
particle.velocity.y += (Math.random() * .01) -(mouseY/10000 - .03); //click for mouse interaction
}
particle.y += particle.velocity.y;
particle.z += particle.velocity.z;
particle.x += particle.velocity.x;
//click again to make particles happy
if(clicky === 2){
particle.velocity.y += Math.random()*(Math.sin(particle.y/10))/2;
particle.velocity.z += Math.sin(particle.z/100)/5;
particle.velocity.x += Math.sin(particle.x/200)/5;
color = Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + Math.floor(Math.random()*10)+ Math.floor(Math.random()*10) + Math.floor(Math.random()*10) + Math.floor(Math.random()*10);
renderer.setClearColor( 0x440000 + mouseX/10, 1 );
}
//particles slowly center on you:
if(clicky === 3){
particle.velocity.z = -((particle.z+(mouseX/100))/1000);
particle.velocity.x = -((particle.x+(mouseX/100))/1000);
particle.y += particle.velocity.y;
particle.z += particle.velocity.z;
particle.x += particle.velocity.x;
particleSystem.material.color.setRGB((mouseX/400),(mouseY/400),(mouseX/200));
}
//particles get more or less random bouncy based on mouse:
if(clicky===4){
particle.velocity.y += (mouseY/500)*Math.random()*(Math.sin(particle.y/((mouseY/100)+.00001)))/2+.00001;
particle.velocity.z += (mouseX/1000)*Math.sin(particle.x/((mouseX/10000)+.00001))/5 - .001;
particle.velocity.x += (mouseX/1000)*Math.sin(particle.z/((mouseX/20000)+.00001))/5 -.001;
particleSystem.material.color.setRGB((mouseX/600),(mouseY/200),(mouseX/200));
}
//go back to standard velocities, plus a little wiggle:
if(clicky===5){
particle.velocity.x = Math.random();
particle.velocity.y = -Math.random()*2;
particle.velocity.z = Math.random();
particleSystem.material=pizza.material;
particleSystem.material.color.setRGB(1,1,1);
renderer.setClearColor( 0x000000 + mouseX/10, 1 );
}
}
/*
Update VR headset position and apply to camera.
*/
controls.update();
/*
Render the scene through the VREffect.
*/
effect.render( scene, camera );
requestAnimationFrame( animate );
}
/*
Kick off animation loop
*/
animate();
//links
function link(){
window.location="http://vihart.github.io/webVR-playing-with/";
}
//listen for mouse movement to get mouseX and mouseY
document.body.addEventListener( 'mousemove', function (event) {
mouseY = event.clientY;
mouseX = event.clientX;
});
//listen for click
document.body.addEventListener( 'click', function(){
clicky = (clicky + 1) % 6;
})
/*
Listen for double click event to enter full-screen VR mode
*/
document.body.addEventListener( 'click', function() {
effect.setFullScreen( true );
});
/*
Listen for keyboard events
*/
function onkey(event) {
event.preventDefault();
if (event.keyCode == 90) { // z
controls.zeroSensor(); //zero rotation
} else if (event.keyCode == 70 || event.keyCode == 13) { //f or enter
effect.setFullScreen(true) //fullscreen
} else if (event.keyCode == 32) {//space
link();
} else if (event.keyCode == 80) {//p
var music = document.querySelector('#music');
if (music.paused){
music.play();
} else{
music.pause();
}
}
};
window.addEventListener("keydown", onkey, true);
//hold down keys to do rotations and stuff
function key(event, sign) {
var control = controls.manualControls[String.fromCharCode(event.keyCode).toLowerCase()];
if (!control)
return;
if (sign === 1 && control.active || sign === -1 && !control.active)
return;
control.active = (sign === 1);
controls.manualRotateRate[control.index] += sign * control.sign;
}
document.addEventListener('keydown', function(event) { key(event, 1); }, false);
document.addEventListener('keyup', function(event) { key(event, -1); }, false);
/*
Handle window resizes
*/
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
effect.setSize( window.innerWidth, window.innerHeight );
}
window.addEventListener( 'resize', onWindowResize, false );
</script>
</html>