Back in the Lab: Particle Meshes on Model Children

Many thanks to the devs of jME – it's a wonderful thing.  What I will explain probably has an easy solution or workaround (but if so, I have not yet found it on the forums)…



I'm having a problem attaching a particle mesh to the child of a model.  I have a two part obj file model (with parent and child "nodes") built in and exported from Blender (as triangulated) – call the parent the "kettle" and the child the "coal" and those are defined as such in the model.  The coal is, of course, in the kettle.  Originally, I tried to load the model as a TriMesh (thinking to attach the particles to the child, as I have done in other experiements on one object models) but the compiler complained of incompatible types – it was expecting a Node.  So, I modified the code to load the model as a node.  Once that was done, I got the child as a Spatial and ran into another incompatible type issue: setGeometry for the particles would not take a Spatial as an argument.  I tried a few different things to get around this, such as attempting to cast the Spatial to TriMesh (which threw a compile time error – a model export issue?) but none seemed to work.  Is there standard way to handle this sort of thing or should I look at other parts of what I'm trying to do (model, parent/child relationships, etc.)?

ashtonv said:

I tried a few different things to get around this, such as attempting to cast the Spatial to TriMesh (which threw a compile time error -- a model export issue?) but none seemed to work

You have loaded a hierarchy of a Node containing two TriMeshes. Find the child of the Node that is your coal mesh, then you have a TriMesh to feed to the particle generator.

Well, I thought that I did that with the cast… I don't have the code on hand right now, but the line I used psuedo looks like:



TriMesh coalMesh = (TriMesh)model.getChild("coal");



but this returned the compile time error that I mentioned in my original post.  Unless, the mesh I'm after is not defined by the model part itself… but a sub part?


what's the compile time error?

ashtonv said:

Unless, the mesh I'm after is not defined by the model part itself... but a sub part?

You are thinking in the right direction. Nothing should stop you from examining your scenegraph a little deeper using "instanceof" "getChild", and recursion. Or, if you really want to spoil the fun of discovering yourself, you could use this tool:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=6498
Which I posted inspired by this very thread :)


TriMesh coalMesh = (TriMesh)model.getChild("coal");


should not give a compile time error, unless model isn't a com.jme.scene.Node - maybe you auto-imported the wrong Node class?

My mistake in recall: it was a runtime error (as seen in the NetBeans output window – I think it said something essentially like target is not trimesh – which made no sense to me at the time since I casted, or so I thought, the spatial to trimesh) and not a compile time error.



Thanks for tip of how to explore the scenegraph deeper and the link to the tool.  I will definitely check them out!

Sorry… I just removed the previous post because the tool mentioned in an earlier post identified that I wasn't after a mesh just called "burner" but "Sphere_burner".  Thus, as you said, I was pointing to a null.  All is well now.  Fire is appropriately dancing off of the coal!  Thanks for your comments and help! 


Ah, well so a child named "burner" is not being found and thus you are passing null to setGeometry.