I rotate model to look at negative Z direction (with rotateY(Math.PI))
My model is now rotated one PI around Y axis. And everything looks ok.
But… I need my rotation to be 0 for all axes, because of the future transformations. I know I could edit model in Blender and rotate it to achieve this, but is there maybe a Three.js way to do this?
Have you tried changing the rotation of the geometry, rather than the mesh? If you apply a rotation to the geometry, you are then free to rotate the mesh as expected.
Another strategy is to add your model to an otherwise empty object3d.
Rotate your model within the object3d on load, from then on manipulate the position and orientation of the object3d.
I am not sure if this is what the original poster wanted, but here is how I use 2 linked meshes to rotate mesh2, compute and transfer the combined rotation to mesh1 and then zero out the mesh2 rotations. The Blender object is a child of mesh2 and also has a zero rotation at the end.
// IN INITIALIZATION
let DegRad = Math.PI/180; // Convert Degrees to Radians
let air_ = {
// Airplane Rotation
Dif: new THREE.Vector3(), // Change in Rotation (degrees)
Obj: makeMesh(), // Airplane Mesh
PBY: makeMesh(), // Pitch/Bank/Yaw Mesh
};
air_.Obj.rotation.order = "YXZ";
air_.PBY.rotation.order = "YXZ";
air_.Obj.add(air_.PBY); // air_.PBY is child of air_.Obj
let quaternion = new THREE.Quaternion();
// IN RENDER
// Use air_.Dif to make Bank, Pitch and Yaw changes (in degrees) to air_.Obj
air_.PBY.rotation.set(air_.Dif.x*DegRad,air_.Dif.y*DegRad,air_.Dif.z*DegRad);
air_.PBY.getWorldQuaternion(quaternion); // Get combined XYZ rotation
air_.Obj.setRotationFromQuaternion(quaternion); // Save result to air_.Obj
air_.PBY.rotation.set(0,0,0); // Zero Out air_.PBY Rotations (so values not doubled)
// Is the above what original poster meant by zeroing out rotation?
// SUBROUTINE
function makeMesh() {
let geometry = new THREE.BoxGeometry(0.01,0.01,0.01);
let material = new THREE.MeshBasicMaterial({color: 0xffffff});
let mesh = new THREE.Mesh(geometry, material);
return mesh;}
Note that, for these purposes, you can use a simple mesh instead of a object or a group.