如何在轴世界上旋转一个物体three.js?

EnZ*_*nZo 15 javascript three.js

是否有可能轮换世界的轴而不是物体?

我需要做一些物体的旋转,但是在第一次旋转后,我不能像我想的那样做其他旋转.

如果无法在世界轴上进行旋转,我的第二个选择是在第一次旋转后重置轴.这有什么功能吗?

我无法使用,object.eulerOrder因为它在我object.eulerOrder="YZX"进行一些旋转后设置时会改变对象的方向.

Nei*_*eil 16

是的,您可以使用在three.js github问题上提供的函数来执行此操作:

// select the Z world axis
this.myAxis = new Vector3(0, 0, 1);

// rotate the mesh 45 on this axis
this.mesh.rotateOnWorldAxis(this.myAxis, Math.degToRad(45));

animate() {
// rotate our object on its Y axis, 
// but notice the cube has been transformed on world axis, so it will be tilted 45deg.
  this.mesh.rotation.y += 0.008;
}
Run Code Online (Sandbox Code Playgroud)

然后

// select the Z world axis
this.myAxis = new Vector3(0, 0, 1);

// rotate the mesh 45 on this axis
this.mesh.rotateOnWorldAxis(this.myAxis, Math.degToRad(45));

animate() {
// rotate our object on its Y axis, 
// but notice the cube has been transformed on world axis, so it will be tilted 45deg.
  this.mesh.rotation.y += 0.008;
}
Run Code Online (Sandbox Code Playgroud)

看我的例子 - http://jsfiddle.net/SCXNQ/156/

  • `getRotationFromMatrix(object.matrix,object.scale)` - >`setFromRotationMatrix(object.matrix)`和`multiplySelf` - >`multiply`.R71 (11认同)
  • 注意:使用`THREE.Math.degToRad(30)`将度数转换为弧度.比`30*Math.PI/180`更具可读性. (3认同)