So in doing exercise 3 in tutorial 8 (picking) today, I ran into a problem with adding a custom name to a Spatial (Geometry's parent class). In this case, I wanted to name the Golem in the scene to "test" for easy testing to see if it was the closest object hit by a ray cast. Doing the following test when the golem spatial is initialized and loaded works fine:
...
golem.setName("test");
System.out.println(golem.getName() + "!!!");
...
the output is "test!!!" in the console as expected. However, doing the following after doing a ray cast does not work:
...
Geometry closestGeom = closest.getGeometry(); //This is the golem when he is clicked on.
System.out.println(closestGeom.getName() + "###"); //should be outputting "test"...
...
What is output is "Oto-geom-1###", which seems like an auto generated name made from its filename or a name in its .xml file. If I changed my if statement to check for that name (Oto-geom-1) then everything would work fine. However, I really need to figure out how to add custom names to objects. Hopefully the solution will come to me asap...
Picture:
Note: The red dot is the hit indicator, where the user last clicked on the model and made it rotate.
Fixed Edit:
So as I was trying a workaround of adding the golem to new node (named "golemNode") and then using that node as the character identifier, when I figured out the original problem. When I ran these two lines after the ray cast:
System.out.println(closestGeom.getName() + "------------");
System.out.println(closestGeom.getParent().getName() + "------------");
I was expecting to get in the console:
Oto-geom-1------------
golemNode------------
However I instead got:
Oto-geom-1------------
test------------
"test" being the original name I had been giving the spatial. Calling getParent() one more time in the above System.out would indeed print "golemNode-------". I am stuck no more!
No comments:
Post a Comment