Change Object parent in Three.js?

怎甘沉沦 提交于 2020-01-03 15:39:28

问题


Is it possible to change the parent of any object?

For example:

scene.add(Object);
Object.Add(OtherObject);
OtherObject.parent = scene; // <-- Something like this

I just know that I can remove the Object and create it again in the new parent, but I'll hope there's another way. I got some Object that are on a plane, if I click them I want fix them to the camera so I can see all the time in front of the camera. And If I click them Again I wanna set the parent again to the plane.

Why did this dont work?

var obj = clicked.clone();
camera.add(obj);
obj.position.set(0,0,-20);

回答1:


Easiest way is to use the detach and attach functions of the THREE.SceneUtils object:

THREE.SceneUtils.detach( child, parent, scene );
THREE.SceneUtils.attach( child, scene, parent );


来源:https://stackoverflow.com/questions/27561788/change-object-parent-in-three-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!