Scaling objects - Unexpected behavior


I’m trying to understand the behavior of using different forms of geometric transformations and I got an unexpected behavior when scaling objects.

When I perform the following operations I get the expected behavior (object getting far from the translated position):

var mat4 = new THREE.Matrix4();
cube.matrixAutoUpdate = false;
cube.matrix.multiply(mat4.makeScale(2, 1, 2));
cube.matrix.multiply(mat4.makeTranslation(2, 0, 2));

But when I do the following, I expected the same behavior but it seems the scale is executed in object’s local space.

cube.scale.set(2, 1, 2);
cube.translateX( 2 );
cube.translateZ( 2 );

In this case, if a put the scale command after the translations, I got the same output.

Am I missing something?

The fiddle is here:

You compare two different mathematical operations which produce different outputs.

In almost all cases, users expect that defining a translation is not affected by scaling. Meaning if you translate a 3D object (without ancestor nodes) to (2, 0, 2), it should be add that place and not somewhere else. No matter how it is scaled or rotated. If you study how Matrix4.compose() is implemented, you will see why this is the case (tl;dr; the translation portion is just set to the result matrix).

1 Like