Three.js 变换前重置矩阵

问题描述 投票:0回答:2

我想多次将相同的矩阵变换应用于

three.js
网格,但我只想要第一次变换所描述的变换。在重新应用变换之前,如何将网格的矩阵“重置”为其变换前的值?

我已经尝试过以下方法,但没有成功

const identity = model.matrix.identity();
model.matrix = identity;
model.matrixWorld = identity;
model.updateMatrix();
model.updateMatrixWorld();
model.applyMatrix4(newMatrix);
javascript three.js 3d transformation matrix-multiplication
2个回答
4
投票

编辑:替换我的整个答案,因为我不知道

Object3D.applyMatrix4
除了修改
position
之外还更新了
quaterion
/
scale
/
matrix
属性。

解决此问题的最简单方法是备份模型的原始

matrix
属性,并在下次更新之前将其复制回原位。这可以使用
Object3D.userData
来完成。

// before doing any updates, ensure the local matrix is set from postion/quaternion/scale:
model.updateMatrix();

// back-up the matrix:
model.userData.originalMatrix = model.matrix.clone();

// reset the model before each update
model.userData.originalMatrix.decompose( model.position, model.quaternion, model.scale );
model.matrix.copy( model.userData.originalMatrix );

0
投票

最简单的方法(https://discourse.thirdjs.org/t/how-to-reset-matrix/36939):

newMatrix.decompose(model.position, model.quaternion, model.scale);
model.updateMatrix();

或使用 applyMatrix4 方法和一些“第一次转换”:

var identityMatrix = new THREE.Matrix4().identity(); //any "first transformation" matrix
identityMatrix.decompose(model.position, model.quaternion, model.scale);
model.updateMatrix();

model.applyMatrix4(newMatrix);
model.updateMatrix();
© www.soinside.com 2019 - 2024. All rights reserved.