Three.js adds an object to the group, but retains the global position / rotation / scale, as it was

I want to move an object from one group (or world / scene) to another group, but keep its global transformation intact. Basically, I don’t want to see an 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 does not work. I think, because the next frame is always updated in the world matrix based on the local properties of position / rotation / scale. I tried using this with matrixAutoUpdate = false, but this does not work either.

The result I am trying to accomplish seems to be something that should be simple, so I hope I have something implicit. Can someone let me know how to do this?

Thank!

+4
1

, , , :

// remove child from parent and add it to scene
THREE.SceneUtils.detach( child, parent, scene );

// remove child from scene and add it to parent
THREE.SceneUtils.attach( child, scene, parent );

attach() detach(), , .

three.js r.74

+4

Source: https://habr.com/ru/post/1628520/


All Articles