Graphics Reference
In-Depth Information
1. Let's start simple and create the cube that we'll move around. We will detect
collisions between this cube and the cubes we define in step 2:
var cubeGeometry = new
THREE.BoxGeometry(2, 2, 2);
var cubeMaterial = new
THREE.MeshLambertMaterial({color:
0xff2255});
var cube = new THREE.Mesh(cubeGeometry,
cubeMaterial);
cube.name='cube';
scene.add(cube);
2. Now, let's create an array that will hold all the objects that we can collide with
and add some cubes to that array:
var cubes = [];
var cubeMaterial2 = new
THREE.MeshLambertMaterial({color:
0xff0000});
var cube2 = new THREE.Mesh(cubeGeometry,
cubeMaterial2);
cube2.position.set(5,0,0);
cube2.name='cube-red';
scene.add(cube2);
cubes.push(cube2);
...
var cubeMaterial5 = new
THREE.MeshLambertMaterial({color:
0xff00ff});
var cube5 = new THREE.Mesh(cubeGeometry,
cubeMaterial5);
cube5.position.set(-5,0,0);
cube5.name='cube-purple';
scene.add(cube5);
cubes.push(cube5);
Search WWH ::




Custom Search