Bruno Lima
Bruno Lima

Reputation: 43

How to apply a matrix transformation and set the result as default state in ThreeJS?

I have a group of THREE.Mesh objects. My goal is to use something like group.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2) );. Then, I would like to make the result as the group default matrix, so that I can use matrixUpdate() in my animation.

In ThreeJS docs, we can find: "Calling updateMatrix will clobber the manual changes made to the matrix, recalculating the matrix from position, scale, and so on."

Is there a way to make the manual changes I want and then set the result as if it was the default state of group?

Upvotes: 1

Views: 4355

Answers (1)

Bruno Lima
Bruno Lima

Reputation: 43

Based on @WestLangley related answer, here is the solution for my problem! After executing all the matrix transformations I want, I just needed to do:

group.children.forEach( function(mesh) {
    mesh.geometry.applyMatrix( group.matrix );
});
group.updateMatrix();

Upvotes: 2

Related Questions