gpt4 book ai didi

matrix - 三个 js,更新对象的矩阵不会改变其位置和旋转参数

转载 作者:行者123 更新时间:2023-12-05 02:04:12 25 4
gpt4 key购买 nike

我想在创建对象时设置一个转换矩阵,然后通过位置、旋转和缩放来控制它,但是改变矩阵确实改变了世界空间中的对象,它的位置参数仍然是 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().setFromMatrixPosition(m)

mesh.matrixAutoUpdate = false
mesh.matrix.copy(m)

// ***************//
mesh.updateMatrix()
// ***************//

console.log("mesh.position", mesh.position)
console.log("pos", pos)

这是 posmesh.position 值的输出

enter image description here

最佳答案

更新对象 matrix不更新其位置或旋转字段,默认情况下 three.js 将根据 position 更新矩阵, rotation , 和 scale渲染前的值(您已通过将 matrixAutoUpdate 设置为 false 来禁用)。

如果您想从矩阵初始化对象转换,您可以使用 Matrix4.decompose像这样的功能:

// m is the initial local matrix transform
m.decompose(
mesh.position,
mesh.quaternion,
mesh.scale,
);

此外,如果您保留 mesh.matrixAutoUpdate = false你必须调用mesh.updateMatrix()每当 position 渲染之前, rotation , 或 scale值已更改。

您可以阅读更多关于矩阵变换如何工作的信息 here .

关于matrix - 三个 js,更新对象的矩阵不会改变其位置和旋转参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64633212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com