user3241843
user3241843

Reputation: 11

Three.js update object's matrix and scale?

I need to transform my objects from normal coordinates to relative coordinate on a globe. I have computed a very nice transformation matrix and set it to the object like below. Object.matrixAutoUpdate = false; Object.matrix= my matrix; It works fine. But later when I need to perform a scale on z. Nothing happened, I guess it's because I turn off auto update. So I called updateMatrix() after changing the scale. The scale did change, but the transformation matrix changed backed to the default one.

Did I do anything wrong?

By the way, if I don't use matrix, and change the up vector of the object. The value never changes. It's always 0,1,0.

Upvotes: 1

Views: 5633

Answers (2)

LF-DevJourney
LF-DevJourney

Reputation: 28529

if you want to use object matrix, you set the matrixAutoUpdate to false, here is the code for transform, rotation in x,y,z sequence, then do scale, last transform.

rM = new THREE.Matrix4().multiplyMatrices(new THREE.Matrix4().makeRotationY(rV.y), new THREE.Matrix4().makeRotationX(rV.x));
rM.premultiply(new THREE.Matrix4().makeRotationZ(rV.z));
object.matrix.copy(rM).scale(sV).setPosition(tV);

here you cannot use the updateMatrix for it will update matrix according the object posiiton, scale, rotation info which were not changed when your set the matrix.

Upvotes: 1

mrdoob
mrdoob

Reputation: 19592

You need to set object.matrixWorldNeedsUpdate to true when modifying object.matrix.

Upvotes: 1

Related Questions