Reputation: 2454
I've modified this single spinning cube so that it contain 3 cubes in an Object3D
http://jsfiddle.net/VsWb9/1243/
In the above example it uses the first cube. I need it to rotate on a single axis at the exact center of the object.
The object3D code
geometry = new THREE.CubeGeometry(50, 50, 50);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Object3D();
mesh1 = new THREE.Mesh(geometry, material);
mesh1.position.x = 50;
mesh2 = new THREE.Mesh(geometry, material);
mesh2.position.x = 100;
mesh3 = new THREE.Mesh(geometry, material);
mesh.add(mesh1);
mesh.add(mesh2);
mesh.add(mesh3);
scene.add(mesh);
Here is the rotation
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
EDIT: Just to say that this is an example to demonstrate the problem, my actual code object contains many different sized shapes.
Upvotes: 7
Views: 14548
Reputation: 166
You may define the coordinates of the center.
mesh.position.set( center.x, center.y, center.z );
mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation( -center.x, -center.y, -center.z ) );
Upvotes: 15
Reputation: 5236
The really easy way is to just position your cubes slightly differently, so instead of setting
mesh1.position.x = 50;
mesh2.position.x = 100;
and leaving mesh3 to default to an x of 0, you can set them like this:
mesh1.position.x = -50;
mesh3.position.x = 50;
Which will make the center box also be at the center of the scene.
jsFiddle showing it working.
Upvotes: 1