-
Notifications
You must be signed in to change notification settings - Fork 4
/
Project2a-Multiple-Objects.html
72 lines (61 loc) · 2.02 KB
/
Project2a-Multiple-Objects.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
<html>
<head>
<title>Multiple Objects</title>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script>
// @author torinmb, PWhiddy
var controls;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
camera.position.z = 60;
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.dampingFactor = 0.25;
controls.zoomSpeed = 0.5;
controls.rotateSpeed = 0.5;
// controls.minDistance = 60;
var gridDimension = 10;
var halfgrid = gridDimension / 2;
var geometry = new THREE.BoxGeometry( 3, 3, 3);
// Create Objects in a loop
for (var i = 0; i < gridDimension; i++ ) {
for (var j = 0; j < gridDimension; j++) {
for (var k = 0; k < gridDimension; k++) {
var material = new THREE.MeshStandardMaterial( {
color: new THREE.Color( Math.random(), Math.random(), Math.random()) } );
var box = new THREE.Mesh( geometry, material );
box.position.x = (i-halfgrid) * 5;
box.position.y = (j-halfgrid) * 5;
box.position.z = (k-halfgrid) * 5;
scene.add( box );
}
}
}
var pointLight = new THREE.PointLight(0xdddddd, 0.5);
scene.add(pointLight);
pointLight.position.z = 12;
var hemisphereLight = new THREE.HemisphereLight(0x8899cc, 0x334455);
scene.add(hemisphereLight);
var render = function () {
requestAnimationFrame( render );
controls.update();
for (var i = 0; i < scene.children.length; i++ ) {
scene.children[i].rotation.x += 0.01;
}
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>