Within my software, users have the ability to select 3D objects on a workplane and then scale, move, or rotate these elements collectively using a "transformation" container. This container, represented by an Object3D
, groups all transformations and applies them to every child object. When deselecting the child elements, the parent container's transformation should be passed down to all children. As a result, the children are removed from the transform container and added back to the main scene object.
However, there is an issue with how the child elements are transformed within the transform container. The transformation is applied to the container itself rather than to the individual elements. For example, when applying a scale transformation to the container that contains a child with local rotations, it seems as though the local rotation is applied first and then followed by the container's scale transformation.
When applying the parent's transformations to all children using
child.applyMatrix(parent.matrixWorld)
and placing the child back into the scene container, the order of transformation is reversed.
- container[scale]{child[rotation]} -> order: rotation, scale
child.applyMatrix(parent.matrixWorld)
- child[scale,rotation]{} -> order: scale, rotation
How can I ensure that the child elements undergo the same transformation order and maintain their appearance?
Update:
I have found a solution to correctly apply the parent's transformations to the child objects. By using the code snippet from Object3D.applyMatrix()
:
child.matrix.multiplyMatrices(parent_old.matrixWorld, child.matrix);
while also setting child.matrixAutoUpdate = false;
and excluding child.matrix.decompose(child.position, child.quaternion, child.scale);
It seems that having matrixAutoUpdate = true
does not produce the desired outcome. Moreover, Matrix4.decompose()
alters the matrix values before assigning them to position
, scale
, and quaternion
. Consequently, in my scenario, the shearing transform caused by the parent's scaled transformation is reset.
This inconsistency raises questions about nested object transformations. While nested object transformations usually display the intended effects, using
child.applyMatrix(parent.matrixWorld)
may not yield the correct results for applying parental transformations to child objects. It remains unclear whether this behavior in three.js is intentional. If so, could someone explain the reasoning behind it?