Is there a way to retrieve the world rotation of an Object3D in three.js?
I am aware of how to obtain the world position of an Object3D using object.matrixWorld
, but I am unsure about how to acquire the world rotation of an object.
This information is crucial for the following issue I'm facing: I have a hierarchical structure of Objects laid out like this:
var obj1 = new THREE.Object3D();
obj1.x = 200;
obj1.rotation.x = 0.1;
scene.add(obj1);
var obj2 = new THREE.Object3D();
obj2.y = -400;
obj2.rotation.y = 0.21;
obj1.add(obj2);
var obj3 = new THREE.Object3D();
obj3.z = -200;
obj3.rotation.x = 0.1;
obj3.rotation.y = -0.1;
obj2.add(obj3);
My goal is to align my camera orthogonal to obj3 at a specific distance. When no rotations are applied to the objects, the solution looks something like this:
var relativeCameraOffset = new THREE.Vector3(0, 0, 500); // 500 represents the z-distance from my object
var cameraOffset = relativeCameraOffset.applyMatrix4(obj3.matrixWorld);
camera.position = cameraOffset;
If only the last child object is rotated, adding this line achieves the desired outcome:
camera.rotation = obj3.rotation;
However, when all parent elements are rotated, this approach fails. Therefore, I am seeking a method to determine the global "orientation" of my 3D object. Thank you.