问题
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