Trouble with naming of collision results

Hi…

I've tested picking specific objects, and it works fine… my problem is the object i am colliding my ray with are Spatial's and CollisionResults return Geometry.

If i set my Spatial's name with setName, then the Geometry returned won't share that name, which means i can only use the auto-generated Geometry name, and there seems to be no way to turn a Spation into the subclass Geometry.



This is very messy, especially because the autogenerated names for Spatials are different from the autogenerated names of Geometry returned as CollisionResults.



(The HelloPicking Tutorial uses a Box as example which is a mesh and can therefore be used to form a Spatial, and assetManager's loadModel returns Spatial's)

1 Like

You can always find the Spatial/Node of a Geometry by checking its parent nodes. So if you set all your Spatials names to something like <name>-entity you can find the Spatial like so:


public Spatial getGeometrySpatial(Geometry geometry){
   Spatial s = geometry.getParent();
   while (s != null){
       if (s.getName().endsWith("-entity")){
           return s;
       }
       s = s.getParent();
   }
   return null; // geometry does not belong to one of the expected spatials.
}

1 Like

Thanks made the trick… i'm just naming the parent node instead :slight_smile:

1 Like