This method here three.js docs is very useful, i didn’t know it existed and i would end up writing my own function to do it’s work.
however in the docs i don’t understand what “non-uniformly-scaled nodes” mean?
Uniformly scaled means the same scale factor along each axis; non-uniformly scaled means at least one of the scale factors differs from the rest
object1.scale.set( 5, 5, 5 ); // uniformly scaled
object2.scale.set( 5, 1, 3 ); // non-uniformly scaled
object3.scale.set( 1, 1, 2 ); // also non-uniformly scaled
Thanks! but any insight into why .attach() doesn’t work in this case?
Because it needs much more complex calculations to adjust the matrices for correct transformations. If you plan to make universal .attach
, please, share it with others.
Addition: I think I need to add clarification about this complexity. In the general case when an object is attached/detached its matrix can be easily calculated by all the matrices of the parents. However, matrices are internal representation of transformations. Externally users see positions, rotations ad scalings. And this is the problem – when positions, rotations and scalings of parents are combined, the result may not be possible to represent as one translation, one rotation and one scaling. So, if you want universal attach/detach, you have to work directly with the matrices.
Here is an example: the object is a square, its parent adds rotation; its grandparent adds non-uniform scaling. The result is that on the screen there is compressed rhomboid. If you detach the square and put it as standalone object, there is no way to transform it into rhomboid with the properties .position
, .rotation/.quaternion
and .scale
. The only way is to directly use matrices and to turn off automatic matrix updates.
When all scalings are uniform, it is possible to pack many translations, rotations and scalings into one set of values for .position
, .rotation/.quaternion
and .scale
.