www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: coordinate on October 14, 2013, 02:38:10 am

Title: How to delete all children with texture from an object3d
Post by: coordinate on October 14, 2013, 02:38:10 am
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.
Title: Re: How to delete all children with texture from an object3d
Post by: EgonOlsen on October 14, 2013, 10:40:50 am
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.
Title: Re: How to delete all children with texture from an object3d
Post by: coordinate on October 14, 2013, 11:37:56 am
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:
Code: [Select]
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.
Code: [Select]
private void removeChildren(Object3D obj) {
    // i can not get all children from obj.
}

Thanks for your reply.
Title: Re: How to delete all children with texture from an object3d
Post by: EgonOlsen on October 14, 2013, 12:25:27 pm
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.
Title: Re: How to delete all children with texture from an object3d
Post by: coordinate on October 14, 2013, 02:26:31 pm
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.)
Title: Re: How to delete all children with texture from an object3d
Post by: EgonOlsen on October 14, 2013, 08:14:26 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.
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.