How to extend "Node" class?

Hello,

I’m new in JME and this is my first post!

I’m a java programmer, with a my friend we are creating a new game.

We started to use Unity 3D, then (for some reasons…) we switched to Shiva Stonetrip, and finally (for other reasons!) we defintively switched to JME3!



Well, we almost completed the “game analysis” (we planned the details, the conceptual game structure, etc…) and we are looking for information to start to write code.



Now I have a question:

I have a model on the screen (in the scenegraph) and the player click on it (object pick). I need to QUICKLY find an internal class that manage the details of the instanced model.

The only solution I found is using the object instance name getName() and looking for in a Map structure to get a reference to the internal class.



Since I’m managing a virtually unlimited terrain (creating our terrain and sectors chunk structure), I wanted to create a new class based on Node class, in order to avoid to work with obejct name, but using a direct reference. For example:



[java]public MyObject extends Spatial {

private MyModelClass myInternalClassReference;



public MyModelClass getMyInternalClassReference() {

return myInternalClassReference;

}

}[/java]



Ok, I wish to use MyObject to be inserted in the sceneGraph instead of a Spatial (model instance).

When I will call getMyInternalClassReference() I will directly get a reference to the original internal class, instead of using an expensive Map (including the methods to manage it: insert object instance in the list, remove from list, etc…).



Is it a good method? Or JME offer better tools to make this?



Thank you for your support!

You can use Spatial.setUserData() to assign your MyModelClass to the model

1 Like

Thank you! That’s just what I really needed!

Thumb up for you!