I try to apply a "local rotation" to a mesh in THREEJS.
I want to rotation to be applied around the geometry center but it is applied around the geometry "origin" (0, 0, 0).
Assumption:
- I can not modify the geometry.
What I do right now:
mesh3D.position.copy(worldPosition);
mesh3D.rotation.setFromRotationMatrix(localRotation);
mesh3D.updateMatrixWorld(true);
Is the only solution to use a pivot somehow? I'd also like to avoid that as it changes the object children hierarchy...
Thanks
To rotate about a point that isn't the object origin, this general order of operations applies:
In your case, the original point is the geometric center.
The example below is a triangle where the object origin and one corner is at the scene origin, but the triangle rotates about its geometric center. Change
matRot = new THREE.Matrix4().makeRotationX(0.01);
to usemakeRotationY
/makeRotationZ
to see it working in other directions.Note that these transformations are applied to the object's local matrix, so any child objects will be transformed as well, following their parent.
three.js r85