I am using Raycasting and trying to point my camera at the hit point of an Object3D’s face. All of that works and is ok right now. The problem is when the Object3D is rotated on the X, Y or/and Z-axis that comes the problems. So I managed to do the following in order to adjust for the X and Y rotations:
var axis1 = new THREE.Vector3(1, 0, 0);
var quaternion1 = new THREE.Quaternion();
quaternion1.setFromAxisAngle(axis1, Math.PI);var axis2 = new THREE.Vector3(0, 1, 0);
var quaternion2 = new THREE.Quaternion();
quaternion2.setFromAxisAngle(axis2, Math.PI);WORLD_POINT = OBJECT3D.localToWorld(intersectingData[‘normal’].applyQuaternion(quaternion1).applyQuaternion(quaternion2)).clone().add(intersectingData[‘point’]);
(intersectingData is what is returned from the Raycaster.)
I guess I could add another quaternion tranformation to handle the Z-axis rotation. I’m trying to see if there is a cleaner way to do this and get the final world coordinate/point needed.
I just tested that also whenOBJECT3D has no rotation at all and the code does not work anymore as no quaternion transformations are needed. I could do a test to see if which rotation is needed, but there has to be a batter way.