Matrix 三个JS,更新一个对象';s矩阵不会改变它';s位置和旋转参数
我想在创建对象时将变换矩阵设置为对象,然后通过位置、旋转和缩放对其进行控制,但虽然更改矩阵确实会更改世界空间中的对象,但其位置参数仍然保持为0、0、0Matrix 三个JS,更新一个对象';s矩阵不会改变它';s位置和旋转参数,matrix,three.js,transformation,Matrix,Three.js,Transformation,我想在创建对象时将变换矩阵设置为对象,然后通过位置、旋转和缩放对其进行控制,但虽然更改矩阵确实会更改世界空间中的对象,但其位置参数仍然保持为0、0、0 let mesh = new THREE.Mesh( new THREE.BoxGeometry(), new THREE.MeshPhongMaterial({color:0xf15728}) ) this.scene.add(mesh) let pos = new THREE.Vector3().setFromMatrix
let mesh = new THREE.Mesh(
new THREE.BoxGeometry(),
new THREE.MeshPhongMaterial({color:0xf15728})
)
this.scene.add(mesh)
let pos = new THREE.Vector3().setFromMatrixPosition(m)
mesh.matrixAutoUpdate = false
mesh.matrix.copy(m)
// ***************//
mesh.updateMatrix()
// ***************//
console.log("mesh.position", mesh.position)
console.log("pos", pos)
以下是pos
和mesh.position
更新对象
矩阵
不会更新其位置或旋转字段,默认情况下,three.js将根据渲染前的位置
、旋转
和缩放
值更新矩阵(您已通过将矩阵自动更新
设置为false禁用)
如果要从矩阵初始化对象变换,可以使用如下函数:
// m is the initial local matrix transform
m.decompose(
mesh.position,
mesh.quaternion,
mesh.scale,
);
另外,如果保持mesh.matrixautodate=false
,则每当位置
、旋转
或缩放
值发生更改时,必须在渲染前调用mesh.updateMatrix()
您可以阅读更多关于矩阵变换如何工作的内容