我正在使用 Three.js,我希望能够从场景中取出一个对象,然后用一个新对象替换它,但旋转与我删除的对象相同。
我记下要移除的对象的旋转,然后使用此函数设置新对象的旋转:
rotateToWorldAxis = function(object, xradians, yradians, zradians) {
axisX = new THREE.Vector3(0, 1, 0);
axisY = new THREE.Vector3(1, 0, 0);
axisZ = new THREE.Vector3(0, 0, 1);
rotationMatrix = new THREE.Matrix4();
rotationMatrix.setRotationAxis(axisX.normalize(), xradians)
object.matrix = rotationMatrix;
object.rotation.setRotationFromMatrix(object.matrix);
rotationMatrix = new THREE.Matrix4();
rotationMatrix.setRotationAxis(axisY.normalize(), yradians);
rotationMatrix.multiplySelf(object.matrix);
object.matrix = rotationMatrix;
object.rotation.setRotationFromMatrix(object.matrix);
rotationMatrix = new THREE.Matrix4();
rotationMatrix.setRotationAxis(axisZ.normalize(), zradians);
rotationMatrix.multiplySelf(object.matrix);
object.matrix = rotationMatrix;
object.rotation.setRotationFromMatrix(object.matrix);
}
x 和 y 旋转工作得很好,但 z 旋转并没有给出想要的结果。
如果有人能发现我做错了什么,或者我应该以另一种方式做,我将不胜感激?
谢谢