Object3D.getNumberOfChildren() && Object3D.getChild(int)

Started by AGP, May 18, 2010, 12:25:20 AM

Previous topic - Next topic

AGP

Egon, could you write those for a static method I'm working on? Thanks in advance.

EgonOlsen

What is this supposed to return? A list of all children in existence? I mean...it's static, so it can't be related to a specific Object3D's children but to all. But then, this isn't the right location, because an Object3D don't know of any other Object3Ds except for its own children of course. The better location would be an instance of World but then it can't be static either!?

AGP

Egon, it's obviously not supposed to be static, I put Object3D where my instance of Object3D would be. In this particular case I want to calculate a bounding box of all the children of a given dummy object, but there are many uses for these methods.

AGP

Having just read what I wrote in the first post, I guess I should clarify that mine is the static method on a Utilities class I'm writing, the methods I requested aren't.

EgonOlsen

I see...problem is, that this isn't possible in that way, because an Object3D doesn't know it's children. It only knows it's parents. I suggest to use World.getObjects(), iterate over the enumaration and store all objects in a list where Object3D.hasParent(<yourObject3D>); returns true. That will give you all the direct children of your object. If that's not enough, you'll need some stack or recursion to collect them.

AGP

No, the immediate children is all I need, thanks a lot for the suggestion.

raft

-if possible- subclassing Object3D and overriding addChild(..) method may also be an alternative