I’ve noticed that in my RTS prototype, when I use a ray for mouse picking and use collideWith(…) on my unit node in the scene graph, I get more Spatial results than I anticipate. Namely with the HoverTank model, I load it using AssetManager.loadModel(…) and the Spatial that it returns appears to have another child Spatial.
For example, here is the hierarchy of results taken from the first CollisionResult.getGeometry(…):
Is this expected behavior? I’m asking because my “Matt’s HoverTank” Spatial has the controls I want to interact with, and I has assumed that would be my collision result since that was the Spatial returned from AssetManager.loadModel(…).
collideWith() never returns Nodes, only Geometries. In order to determine which model a Geometry belongs to, you must iterate up the scene graph using getParent() until you find the main node of its model.
@sgold said:
collideWith() never returns Nodes, only Geometries. In order to determine which model a Geometry belongs to, you must iterate up the scene graph using getParent() until you find the main node of its model.
Is there a good way to know how far up to iterate?
I added the getClass() to the log and I see the Node/Geometry classes now. I still didn’t anticipate that loadModel(…) would return a Node with a Geometry child instead of simply a Geometry instance.
INFO: Selection #0 is a class com.jme3.scene.Geometry: Tank2-geom-1 at (-138.889, 36.55636, -21.925623), 93.169525 WU away.
INFO: Selection #0 is a class com.jme3.scene.Node: Matt's HoverTank at (-138.889, 36.55636, -21.925623), 93.169525 WU away.
INFO: Selection #0 is a class com.jme3.scene.Node: FriendlyEntities at (-138.889, 36.55636, -21.925623), 93.169525 WU away.
INFO: Selection #0 is a class com.jme3.scene.Node: Root Node at (-138.889, 36.55636, -21.925623), 93.169525 WU away.
@grghost said:
Is there a good way to know how far up to iterate?
Go until you see your control?
Edit: loadModel might have returned a node with 100 geometry children. Or 500 nodes each with 10 children. You can’t know… but this is a pretty common question.
@pspeed said:
Edit: loadModel might have returned a node with 100 geometry children. Or 500 nodes each with 10 children. You can't know... but this is a pretty common question.