How to delete all children with texture from an object3d

Started by coordinate, October 14, 2013, 02:38:10 AM

Previous topic - Next topic

coordinate

I find "removeChild" method, but it can only remove one child.

And "clearObject" method is not work too.

So how can I delete all children (and their texture) from an object3d one-time.

Thanks.

EgonOlsen

removeChild takes an Object3D as parameter just as addChild takes one. Just remove all Object3Ds that you have added one after the other.
About the textures: These have nothing to do with the objects. You have to remove and unload them individually in the TextureManager if you don't use them any longer.

coordinate

#2
I used to use scene graph library like openscenegraph.

After i add amount of children to a node, i can remove them all with one method like removeChildren.

I don't understand is when i add children in jpct:

private void addChildren(Object3D obj) {
    obj.addChild(new Object3D()); // add child A
    obj.addChild(new Object3D()); // add child B
    ... ...
}


How can i remove all children in another function.

private void removeChildren(Object3D obj) {
    // i can not get all children from obj.
}


Thanks for your reply.

EgonOlsen

I can add some method to remove all the children at once if that would make you happy. I'll add this later today and report back.

coordinate

Extremely grateful if you can add removeChildren method.

I have another question that I have found "removeAllObjects" in "World" class.

When I add object3d A to object3d B, I have to add A to world too.

Does this mean that when I remove object3d A from object3d B, I have to remove A from world too?

(I use jpct first-time. I am not familiar with "world". In osg and jme, there is no "world", just node tree.)

EgonOlsen

Quote from: coordinate on October 14, 2013, 02:26:31 PM
Extremely grateful if you can add removeChildren method.
It's actually not as easy as i thought and now that i look at it, i remember why such a thing doesn't exist: The relation between objects is actually implemented as a parent-relation, i.e. an Object3D knows its parents but not it's childs. The addChild and removeChild-methods are just there for convenience if one prefers to think in child-relations instead. If i would add this, i would introduce a cyclic reference between these objects and i rather don't want to do that.
Quote from: coordinate on October 14, 2013, 02:26:31 PM
I have another question that I have found "removeAllObjects" in "World" class.

When I add object3d A to object3d B, I have to add A to world too.

Does this mean that when I remove object3d A from object3d B, I have to remove A from world too?
Yes. child/parent relations make child Object3Ds inherit the transformations of the parent but not rendering attributes or world assignment. You can create a tree of objects but only add the roots to the world if you want that.