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.
js suggest the way to rotate an object around a point using three. js is to create a parent object at the position you want to rotate around, attach your object, and then move the child. Then when the parent is rotated the child rotates around the point.
Introduction to JavaScript rotate() canvas API The rotate() method allows you to rotate a drawing object on the canvas. The rotate() method accepts a rotation angle in radians. If the angle is positive, the rotation is clockwise. In case the angle is negative, the rotation is counterclockwise.
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 ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With