Clicking in models with data

hi… i am having some problems clicking in imported 3d models…



i am loading a lot of 3d models… and inserting them in my gameNode

(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(models.get(obj.getURL()).toByteArray()));


for example... i load a tiger.3ds  and insert them in gameNode..
i have a class Tiger.java... that will carry infos about this object... like name, age, strength, and other things...

when i click on tiger and use:
GeomBatch gb = pr.getPickData(0).getTargetMesh();
System.out.println(gb.getName());
System.out.println(gb.getParentGeom().getName());// Man_bofy  , Sphere


i get the following strings:
null
Tiger_Material


i dont know how to create a path between my class tiger (that extends a Spatial) and the model in the screen...
cause i want to click in the Tiger model with ID 1... and load the info about the Tiger 1... and so on...

thanks!
   

Looks as if you never set the node name :slight_smile:



make sure you are setting names on ALL the models you import…


Spatial model = [ load model....]

model.setName( "modelName" );



Also, those names should be unique for each model loaded otherwise picking may result object 'collisions' (ex. tiger1 and tiger2 (vs) tiger and tiger).

What I do in my app is use setUserData() to store some data object, when I receive the geometry from the pick callback, I loop through the ancestors of said geometry until I find one with the user data set.

Momoko_Fan said:

What I do in my app is use setUserData() to store some data object, when I receive the geometry from the pick callback, I loop through the ancestors of said geometry until I find one with the user data set.


Exactly.

You can also store an actual refernece to the Tiger ;) using the Savable wrapper described in this thread: http://www.jmonkeyengine.com/jmeforum/index.php?topic=9967.

Also have a search on the forum for entity and entity node - simple framework that extends Node and implements Entity - that way you just test instanceof Entity on the picks