现在该怎么办three.getWorldRotation已经消失了

bee*_*eek 0 three.js aframe

在先前版本的Three.js中,我使用了 getWorldRotation()

  const sourceObject3D = sourceEntity.object3D

  // Rotation
  {
    const sourceAngle = three.Math.radToDeg(
      sourceObject3D.getWorldRotation().y
    )

    const prevAngle = three.Math.radToDeg(
      targetEntity.object3D.getWorldRotation().y
    )
Run Code Online (Sandbox Code Playgroud)

现在折旧了。

我试图用替换它 getWorldQuaternion()

var quaternion = new three.Quaternion()
sourceEntity.object3D.getWorldQuaternion( quaternion )
var vector = new three.Vector3()
vector.applyQuaternion( quaternion )
const sourceAngle = three.Math.radToDeg(vector.y)

var tquaternion = new three.Quaternion()
targetEntity.object3D.getWorldQuaternion( tquaternion )
var tvector = new three.Vector3()
tvector.applyQuaternion( tquaternion )

const prevAngle = three.Math.radToDeg(tvector.y)
Run Code Online (Sandbox Code Playgroud)

但是targetEntity Quaterion总是 Quaternion {_x: 0, _y: 0, _z: 0, _w: 1}

为什么会这样呢?这是替换的正确方法吗getWorldRotation()

Pio*_*ski 6

object3Ds的旋转由一个THREE.Euler对象(source)表示。

如果使用它而不是Vector3,则计算应该可以正常进行。

var quaternion = new three.Quaternion()
sourceEntity.object3D.getWorldQuaternion( quaternion )

let rotation = new THREE.Euler()
rotation.setFromQuaternion(quaternion)
Run Code Online (Sandbox Code Playgroud)

在我的小提琴中检查一下。