-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstep1.html
87 lines (61 loc) · 2.14 KB
/
step1.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
<!DOCTYPE html>
<html>
<head>
<title>WebVR Tutorial: Step 1</title>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0, shrink-to-fit=no">
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<script src="lib/three.min.js"></script>
<script>
var scene, camera, renderer;
var numCubes = 100; // Number of cubes in the scene
var fieldRange = 1500; // The range in 3D space the cubes will be placed
var cubes = []; // Array to hold cube meshes
init();
animate();
function init() {
var material, geometry, mesh;
// This is your standard three.js set up
// Create a scene, camera and a renderer
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// Create a bunch of cubes
for (var i = 0; i < numCubes; i++) {
// Standard three.js to create a cube
// Each cube needs a material and geometry which is used to create a mesh
material = new THREE.MeshNormalMaterial();
geometry = new THREE.BoxGeometry( 50, 50, 50 );
mesh = new THREE.Mesh( geometry, material );
// Give each cube a random position
mesh.position.x = (Math.random() * fieldRange) - fieldRange/2;
mesh.position.y = (Math.random() * fieldRange) - fieldRange/2;
mesh.position.z = (Math.random() * fieldRange) - fieldRange/2;
// Add cube to scene
scene.add(mesh);
// Add mesh to global array for use later
cubes.push(mesh);
}
}
// Standard way to run an animation in JS
// Using requestAnimationFrame
function animate() {
requestAnimationFrame( animate );
// Every frame, update each cube's rotation
for (var i = 0; i < numCubes; i++) {
cubes[i].rotation.x += 0.01;
cubes[i].rotation.y += 0.02;
}
// Render the scene
renderer.render( scene, camera );
}
</script>
</body>
</html>