Three.js将一个对象添加到一个组中,但保持全局位置/旋转/缩放

时间:2021-02-05 19:39:47

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.

但是,这似乎不起作用。我想因为世界矩阵总是在下一帧更新,基于本地位置/旋转/缩放属性。我已经尝试使用matrixAutoUpdate = false,但这似乎也不起作用。

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 个解决方案

#1


5  

As I mentioned in my comment, the methods you need to utilize are:

正如我在评论中提到的,您需要使用的方法是:

// 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 );

Study the source code of attach() and detach() so you understand what they are doing.

研究attach()和detach()的源代码,以便了解它们正在做什么。

three.js r.74

three.js r.74

#1


5  

As I mentioned in my comment, the methods you need to utilize are:

正如我在评论中提到的,您需要使用的方法是:

// 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 );

Study the source code of attach() and detach() so you understand what they are doing.

研究attach()和detach()的源代码,以便了解它们正在做什么。

three.js r.74

three.js r.74