Three.js 将一个对象添加到一个组中,但保持全局位置/旋转/缩放原样 [英] 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.
基本上是这样的:
//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?
谢谢!
推荐答案
您可以使用内置方法 Object3D.attach()
:
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
three.js r.109
这篇关于Three.js 将一个对象添加到一个组中,但保持全局位置/旋转/缩放原样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!