5
votes

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!

1
See stackoverflow.com/questions/24441223/… Study the source code of attach() and detach() so you understand what they are doing.WestLangley
Thanks so much, exactly what I was looking for. You'd think that in all my searches, I would have stumbled upon that answer :)Qbz

1 Answers

11
votes

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