I have a collection of "blocks" that are Three.js (r72) mesh objects (mostly created from extruded shapes)
This mesh's bounding box is a 1 x 1 x 1
cube, the XYZ axis helper is at 0,0,0
, and after this shape was created it was added to the scene at 1,1,0
.
So to clarify, the mesh's 0,0,0
is at the world 1,1,0
.
I want to rotate the object around the Z axis (Blue Axis) (e.g. in the XY plane) such that the curved face is facing me.
If I do so, it rotates around the Z axis, specifically at the mesh's origin point and I get this.
However this is NOT what I want at all.
I want to rotate the mesh around a Z-Axis, specifically the one that runs through the centroid of my mesh. e.g. an axis formed by the current world co-ordinates 1.5,1.5,0
to 1.5,1.5,1
.
Thus the resulting output would be (I had to fake this to get the desired image)
I am aware that I can create my initial shape/mesh so that the "insertion point"/origin is actually at the centroid (or bottom center) of my shape and thus this would "solve" my rotation issue but I do not want to do that as it will ruin the ability for me to place the blocks in a simple, logical manner.
I'm OK with whatever option works for this, whether applying a matrix transformation, or rotation.
The only ugly option I could come up with was to:
- Save the
orig.x, orig.y, orig.z
of the mesh's insertion point - Move the mesh to
((0,0,0) - (meshCentroid.x, meshCentroid.y, meshCentroid.z))
- Rotate the mesh around the World
Z Axis
- Move the mesh back
((orig.x, orig.y, orig.z) + (meshCentroid.x, meshCentroid.y, meshCentroid.z))
However this seems like extreme overkill, and won't work if I want to rotate around an arbitrary axis other than the one that passes through the centroid.
I'm aware that there are many similar questions already asked here, but all the one's I've found ruin the position point of the mesh in order to apply the rotation.