Author Topic: Object3D.getNumberOfChildren() && Object3D.getChild(int)  (Read 1702 times)

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Object3D.getNumberOfChildren() && Object3D.getChild(int)
« on: May 18, 2010, 12:25:20 am »
Egon, could you write those for a static method I'm working on? Thanks in advance.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #1 on: May 18, 2010, 11:10:19 am »
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!?

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #2 on: May 18, 2010, 03:17:06 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #3 on: May 18, 2010, 03:41:27 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #4 on: May 18, 2010, 08:24:30 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #5 on: May 18, 2010, 08:28:28 pm »
No, the immediate children is all I need, thanks a lot for the suggestion.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: Object3D.getNumberOfChildren() && Object3D.getChild(int)
« Reply #6 on: May 19, 2010, 12:14:11 am »
-if possible- subclassing Object3D and overriding addChild(..) method may also be an alternative