Ignore children on ray collision detection

I am having a tree of entities, every one of them is checked for ray collision detection when mouse is clicked. All is fine, except that nodes that have children nodes catch the collisions of the children nodes. I would like to retain the hierarhical node relationships but make parents skip collision tests of their children - I want each node to only check for it’s own collisions. How can I do that?

What would you collide against? Only geometry+mesh can be “hit” and by definition that’s always a child and never a parent.

If you just want to intersect the bounding shapes then you will have to do that manually as there is no built in way to skip children without subclassing Node.

In my program I have:

  1. subclassed Node
  2. subclassed Geometry

And I build my scene graph of these subclassed kinds like this:
[java]
N
/|
/ |
G G N N — G
\ /
\ /
N ------ N — G
/|
/ |
/ G
G G

N - subclassed Node
G - subclassed geometry

[/java]

and whenever I catch something on a G, the whole branch of N’s says to catch that pick. Could you tell me more on what do I have to do to avoid this? Currently I am performing a proximity distance check, but it is not a perfect solution, you know.

Please show the code which you are using to find the collision and make sure you have not overwritten any of collideWith implementations on your Node subclasses.

BTW, you don’t really need to subclass Node or Geometry in most cases. set/getUserData is often more than enough to hold custom information (at the cost of making your structures Saveable).

I still don’t understand what your are trying to do versus what is actually happening.

You must be wanting to collide with some children or you’d never reach any of the Geometry objects… and then what exactly would you be colliding with? So how do you tell which children you want to traverse? Or are you just trying to collide with the bounding spheres of the roots.

Friends, I apologize for taking that long to respond, having pretty busy times now…

@abies
I am not sure that I can factor out the code quickly. The reason is that I am developing a full-scale framework on top of JME3, intended for simplifying development with JME3 in Scala, and having many additional features. But I can say that when there is a mouseclick or touch event, all objects on the screen check for collision with the ray. And if them are in a hierarhy, the hits on children count for hits on parent and that thing propagates to the root of the hierarchy. That turns out to be a fatal problem sometimes. For example, the framework provides somewhat rich GUI capabilities with JME objects in ortho projection. Some types of GUIs, e.g. sets of hierarhical moving nodes, suffer much from this kind of behavior. Actually, that is why I am asking this. I can share the framework code if you want no problem it’s opensource, but it may require too much involvement for a simple answer on a forum question, to get accustomized with the architecture of the framework, especially for it being written in Scala. Apart from that, the very mechanism of ray collision detection is no different from that in the tutorial on this website.

@pspeed
I have a 2D GUI consisting of a tree of moveable nodes. The nodes are in parent-children relationships. So I want to move a leaf node or some intermediate branching node. When I touch the screen or click the mouse, the picking ray is checked via collideWith against every visible node (nodes have Quads geometries attached, which are used for checking the collisions). And the unwanted behavior is that if some node is found to be colliding with the ray, all the nodes, up to the very root of the tree are considered to be colliding with the ray (since their children do). I want the following to be true: if some node’s quad is found to be directly pierced by the ray, any nodes that are higher in the hierarchy and are not directly pierced by the ray are not considered to be collided with the ray… Actually, that is a pretty natural requirement and I think that either I am doing something wrong or misunderstand some concept that I come stuck with it.

<cite>@noncom said:</cite> @pspeed I have a 2D GUI consisting of a tree of moveable nodes. The nodes are in parent-children relationships. So I want to move a leaf node or some intermediate branching node. When I touch the screen or click the mouse, the picking ray is checked via collideWith against every visible node (nodes have Quads geometries attached, which are used for checking the collisions). And the unwanted behavior is that if some node is found to be colliding with the ray, all the nodes, up to the very root of the tree are considered to be colliding with the ray (since their children do). I want the following to be true: if some node's quad is found to be directly pierced by the ray, any nodes that are higher in the hierarchy and are not directly pierced by the ray are not considered to be collided with the ray... Actually, that is a pretty natural requirement and I think that either I am doing something wrong or misunderstand some concept that I come stuck with it.

Nodes don’t get collisions so it’s not the parents in the hierarchy that you are getting hits on but all of the other children of those nodes, I guess. Only Geometry gets actual collisions. Nodes are only used for traversal.

To have hit that little down deep child in the first place the whole scene graph up to that point had to be considered already. It’s a depth first traversal after all. So there is no “natural requirement” that you are somehow missing. You have overlapping siblings and they all get collisions when clicked. That you want only the one with the deepest ancestry is a specific requirement to your framework, I guess… and is easy to detect in the results.

1 Like