Picking objects: How to pick a (parent) BoundingBox, possible?

You can do this pretty easily through a recursion function:



private Node findNode(Spatial s){
   if(s.getParent().getName().startsWith("player NR")){
      return (Node)s;
   }
   else{
      return findNode(s.getParent());
   }
}



If you can guarantee that everything being put through this loop will be under something starting with the name 'player NR', then you don't need to check for null.  Otherwise, you would want to check that the parent is not null before checking the name.

Hi,

hope I found the right thread for such topic  (where is a JME help-forum?).



I have not found any infos or examples in JME2 how to pick parent nodes in JME. Even the pick example is sparse.

The problem is, I need an extern model used much times in JME. So I created a node 'player NR X', attached a SharedNode (from a loaded 3ds model).

However when I pick on that object, I get the 'model'-name wich is used in much of my objects (non unique), never the upper specific NR I need. So the pick information is useless, I cant identify my player-object.



Is there a way one would code such? What I need is that on pick the top-bounding box's node-name is retrieved, not the name of the child objects.



thanks in advance


Great, looks like a solution. Thank you for your tip!



So, a stop of the pick, not to go deeper into childs when a bounding box on a parent is hit, is not possible, right?

Ah right, you have a bounding box around your 'player NR' node.  In that case, it should show up in the pick results then by just using a for loop:


for(int i=0; i<pickResults.getNumber(); i++){
     pickResults.getPickData(i)
}



One of those should be your top level player node.  Unless your bounding box is really tight, going from child to parent (or using triangle picking) will be more accurate FYI