Hi!
I am trying to write a generic mouse picker which will tell me the spatials name which i assign i.e player.setName("andy"); when i click on it with the mouse.
So far I have developed something but i have to go geometry.getParent().getParent().getName() and i fairly sure this is like a magic number and wont work in all cases, it just so happens the geometry has 2 parents. How can i tell how many parents a geometry has safely so I can jump back up the tree to find the start of the path?
This is my current code and as you can see it currently relies on expected null pointers which aint good. I am also experiancing multiple null pointers on the geometry.getName() which I could ignore, but is a bit frustrating and I dont think it should ever be null.
SnowReference.getRootNode().collideWith(ray, results);
for (int p = 0; p < results.size(); p++) {
// For each hit, we know distance, impact point, name of geometry.
float dist = 0;
Vector3f pt = null;
String hit = null;
String parent = null;
try {
dist = results.getCollision(p).getDistance();
pt = results.getCollision(p).getContactPoint();
hit = results.getCollision(p).getGeometry().getName();
parent = results.getCollision(p).getGeometry().getParent().getParent().getName();
System.out.println("* Collision #" + p);
System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away." + ", name is " + parent);
} catch (Exception e) {
System.out.println("* Collision #" + p);
System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away." + ", no parent");
}
}