Three.js add an object to a group but keep global position/rotation/scale as it was
I want to move an object from one group (or world/scene) to another group, but keep it's global transformation intact. Basically, I don't want to see the object change.
basically, something like this:
//store current world transformation
var origWorldMatrix = myObject.matrixWorld.clone();
//move object to a group (that is positioned and rotated arbitrarily)
someGroup.add( myObject );
//restore previous world transformation
myObject.matrixWorld.copy( origWorldMatrix );
However, this doesn't seem to work. I guess because the world matrix is always updated the next frame, based on the local position/rotation/scale properties. I've tried to use this with matrixAutoUpdate = false, but that doesn't seem to work either.
The result I am trying to accomplish seems like something that should be simple to do, so I hope I am missing something obvious. Can anybody give me a clue on how do do this?
Thanks!
EDIT: You can use the built-in method Object3D.attach()
:
// add object as a child of parent, while maintaining the object's world transform
parent.attach( object );
three.js r.109