threejs applyMatrix4似乎什么都不做



方法applyMatrix4似乎什么都不做…为什么我不能把这个变换矩阵应用到向量上?

const vec = new THREE.Vector3(1,1,1)
const geometry = new THREE.BoxGeometry(1,1,1)
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 })
const mesh = new THREE.Mesh(geometry, material)
mesh.rotateX(Math.PI)
const rotatedVec = vec.applyMatrix4(mesh.matrix)
console.log(rotatedVec)

期望(求外积):

{x: 1, y: -1, z: -1}

现实(矢量不变)

{x: 1, y: 1, z: 1}

我的网格矩阵已经改变-它不是单位矩阵。

[
[1, 0, 0,  0],
[0, -1, 0, 0],
[0, 0, -1, 0],
[0, 0, 0,  1],
]

Object3D.rotateX()仅影响对象的quaternion属性。它不更新它的局部矩阵。如果你说你的矩阵已经改变了,我假设你已经检查过了,当其他引擎逻辑触发重新计算。

可以在调用Object3D.rotateX()后添加mesh.updateMatrix();来解决此问题。

或者更好地使用Vector3.applyQuaternion()。这样,你就不需要重新计算矩阵,因为你根本不需要它。

const rotatedVec = vec.applyQuaternion(mesh.quaternion)

最新更新