Author Topic: How to delete all children with texture from an object3d  (Read 1402 times)

Offline coordinate

  • byte
  • *
  • Posts: 3
    • View Profile
How to delete all children with texture from an object3d
« 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11983
    • View Profile
    • http://www.jpct.net
Re: How to delete all children with texture from an object3d
« Reply #1 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.

Offline coordinate

  • byte
  • *
  • Posts: 3
    • View Profile
Re: How to delete all children with texture from an object3d
« Reply #2 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.
« Last Edit: October 14, 2013, 11:40:15 am by coordinate »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11983
    • View Profile
    • http://www.jpct.net
Re: How to delete all children with texture from an object3d
« Reply #3 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.

Offline coordinate

  • byte
  • *
  • Posts: 3
    • View Profile
Re: How to delete all children with texture from an object3d
« Reply #4 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.)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11983
    • View Profile
    • http://www.jpct.net
Re: How to delete all children with texture from an object3d
« Reply #5 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.