geometry offset, the object is offset grid coordinates, and, but the world still in the original location of the object: This object is very simple to achieve the effect of a rotation around the center point of the world coordinate:
1. how to achieve this object around the center point of the world coordinate rotation:
The idea is to achieve: a grid ( Geometry) first offset (Translate), generates a mesh (mesh) after the last rotation of the grid, codes are as follows:
var geo = new THREE.BoxGeometry(10,10,10);
geo.translate(50,0,50);
var mat = new THREE.MeshBasicMaterial({color:0xff0000});
var mesh = new THREE.Mesh(geo,mat);
mesh.rotateY(0.5 * Math.PI);
scene.add(mesh);
Let such an object around the center point of the world coordinate rotation is very convenient, in requestAnimation where the function, add the following code
ar r = 0.01;
function loop() {
renderer.render(scene,camera);
mesh.rotateY(r * Math.PI);
requestAnimationFrame(loop);
}
The effect achieved is as follows (add a few pictures at a certain time):
2. the mesh offset ,, is the world coordinates of the object changes, so let ,, rotation is a rotation in place:
var geo = new THREE.BoxGeometry(10,10,10);
var mat = new THREE.MeshBasicMaterial({color:0xff0000});
mesh = new THREE.Mesh(geo,mat);
// about x, z offset 30;
mesh.translateOnAxis(new THREE.Vector3(1,0,1),30);
scene.add(mesh);
Let it constantly spinning:
var r = 0.01;
function loop() {
renderer.render(scene,camera);
mesh.rotateY(r * Math.PI);
requestAnimationFrame(loop);
}
Results are as follows: