Scene Graph confusion!

Hi all,



After reading the docs, I’m still a little confused about the structure of nodes/geometries/meshes in my scene, and would appreciate some advice!



In Blender, I’ve created an Empty (called “Sites”) and made it the parent of 3 objects (called “Site1-3”) and named the mesh of each object S1, S2, S3, as in the picture below…



http://i1047.photobucket.com/albums/b480/CookieJonathan/nav.gif



I load the scene into my JME SimpleApplication, and attach only the “Sites” node to the rootNode, like so…



[java]

// Load scene and attach “Sites”

gameLevel = assetManager.loadModel(“Scenes/test/test.j3o”);

siteNode = ((Node)gameLevel).getChild(“Sites”);

rootNode.attachChild(siteNode);

[/java]



When the user clicks an object, I want to get the name of the object that was clicked…



[java]

rootNode.getChild(“Sites”).collideWith(ray, results);



for (int i = 0; i < results.size(); i++) {



trace("* " + results.getCollision(i).getGeometry().getName());

trace("* " + results.getCollision(i).getGeometry().getParent().getName());

trace("* " + results.getCollision(i).getGeometry().getParent().getParent().getName());

trace("* " + results.getCollision(i).getGeometry().getParent().getParent().getParent().getName());

}

[/java]



This yields…



[java]

  • s3-geom-1
  • s3-ogremesh
  • s3-entity
  • Site3

    [/java]



    …which is not what I expected.



    So, my questions…


  1. It seems that every object in Blender, when imported to JME, is added as a Node which in turn contains a Geometry… with two more levels of objects (“entity” and “ogremesh”) in between. Is that right? 4 objects from Node → Geometry? Do all Geometries have to be added to their own individual Nodes? And what exactly is the “ogreMesh” and “entity”? I understood all objects were either “Nodes” or “Geometries”. What am I missing?


  2. Why is the ogre importer munging the names of my meshes (i.e. adding “-geom-1”, “ogremesh” and “entity”), and is there anything I can do to preserve the names assigned in my Blender scene?


  3. Am I going about this all wrong? If I want to have a series of items which exist purely to be clicked on (and return the name of the clicked item), should I be arranging my scene in a completely different way to reduce the amount of objects in my scene graph, and if so, how?



    Confused.



    Thanks in advance for any advice!

    Jon.

To your name confusion, thats the getName not getclass you are using, by any chance you named some stuff that way in blender (or the exporter did?)



Also the jme scenegraph can hendel quite much Nodes so the depth before the geometrys come should not be that much of concern, if you dont have any kind of performance problem right now.

1 Like
@EmpirePhoenix said:
To your name confusion, thats the getName not getclass you are using, by any chance you named some stuff that way in blender (or the exporter did?)

Hmm... pretty sure it must be the ogre exporter. The first pic shows exactly what each object/mesh is called in my Blender scene.

Also the jme scenegraph can hendel quite much Nodes so the depth before the geometrys come should not be that much of concern, if you dont have any kind of performance problem right now.

Ok. So you're saying that using...
"getCollision(i).getGeometry().getParent().getParent().getParent().getName());"
.. IS the appropriate method of getting the name of the Node clicked? Right-o, I can live with that if it's normal practice. I was just worried I was doing something completely wrong, as it seems a bit bloated.

Thanks for your help! It's much appreciated. :)

I suggest to have a list of regexes for names you are expecting like “Site*”,“Path*” ect.

then doing a recursive getParent untill one matches the regex for this, this will look much simpler, and you are free to do stuff differently without breaking anything.



However I assume that the exporter is the reason you get the additional nodes that are not really needed, sine I never used blender I cannot help much here, but maybee there is a option to reduce this.

1 Like
@jonmonkey said:
Ok. So you're saying that using...
"getCollision(i).getGeometry().getParent().getParent().getParent().getName());"
.. IS the appropriate method of getting the name of the Node clicked?

No. You should never assume that the structure is always this way. Do a recursive search. Start with the clicked node, look if it has the desired parameter (in this case, if the name starts with "Site" and ends with a number, but in some caeses it might be a control that was added to the node that you're looking for, or something else), and if that is not the case, check it's parent node etc. until you reach the root node.
1 Like

Excellent, thanks for your advice Phoenix & Gnome. :slight_smile: