Three.js将一个对象添加到一个组,但保持全局位置/旋转/缩放 [英] Three.js add an object to a group but keep global position/rotation/scale as it was

查看:367
本文介绍了Three.js将一个对象添加到一个组,但保持全局位置/旋转/缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个对象从一个组(或世界/场景)移动到另一个组,但保持其全局转换不变。基本上,我不希望看到对象发生变化。

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.

基本上是这样的:

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

然而,这似乎不起作用。我想因为世界矩阵总是根据本地位置/旋转/比例属性更新下一帧。
我试过将它与matrixAutoUpdate = false一起使用,但这似乎也不起作用。

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?

谢谢!

推荐答案

您需要使用的方法可以在 /examples/js/utils/SceneUtils.js 文件中找到。

The methods you need to utilize can be found in the file /examples/js/utils/SceneUtils.js.

// 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()让你明白他们在做什么。

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

three.js r.96

three.js r.96

这篇关于Three.js将一个对象添加到一个组,但保持全局位置/旋转/缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆