I have a problem with the coordinates returned from picking. I have two models in my scene and when I shoot a ray at them I can correctly access their geometry. Now the problem is that the coordinates for the pick stays the same if I move the models. I have tried updating both the rootNode and the models themselves - I am not quite sure how it works.
I’m not asking for a complete explanation, just a gentle nudge in the right way.
Here’s the code for picking.
It’s from the HelloCollision tutorial and was originally implemented by iterating over all the picked elements but it seemed the last item in the list was always the one I wanted.
[java]
CollisionResults results = new CollisionResults();
Ray ray = new Ray(cam.getLocation(), cam.getDirection());
I tried using getClosestCollision() but my models’ geometry object seems to be separated into more geometry objects which means that the names I gave to the spatial node doesn’t stay with all the geometries. So when I try to get the name out of the geometry of a given collision the name field is null.
The effect of all this is that I need the collisions with the name of the spatial node and not just the closest one. By trial and error I found that the last element of the list is always the element with a name field that isn’t null. I just assumed the list was sorted somehow, closest to farthest or vice versa because it is a list. I’d have used a set datastructure if I wanted an unordered set of elements.
Hope this explains my troubles.
Thanks for reading and trying though. There’s still hope
I created models in 3ds max and exported them as .obj which are then added to the jME assets and converted to .j3o.
I then use
[java]Spatial x = assetManager.loadModel(“Models/x.j3o”);[/java]
to load the model. This seems to automatically transform the model into several geometry objects. If only the name given to the original spatial was propegated to all the geometry instances the closest collision you mentioned would be the easiest, and altogether nicest, fix.
I’ll play around with the scenario some more and post a solution if I get it to work.
I’m still not ruling out that I may have failed miserably somewhere. So any hints would be appreciated.