I have a scene, full with visual objects that are implemented as one mesh (just like the particle emitter), and I need to be able to pick them with mouse. Considering, there may be a > 1000 objects on the screen, and that they are represented with one geometry, I think it is impossible to use a ray for picking. Hence I wanted to use the color-coded picking technique ( reference-1 , reference-2 ). How do I better implement it with JME3? Had anyone tried this?
I think that I can apply vertex colors to the objects and somehow I need to render the vertex-colored geometry to a separate buffer, while the normal one, textured, has to be rendered to the usual visual buffer… Or is there any better way for that?
The ray allows you to get the hit triangle, what more do you need? If you have enough info to color them, you have enough info to determine the object based on the triangle or?
For a normal model, you could also make a separate texture, and use the hit locations uv coordinates to lookup in your secondary texture what object it is. (I used that approach in a sideproject for critical hitzones)
1 is somewhat cheap, but it depends on your scene setup.
2 it is somehwat simple, if you don’t care about exact,you could also pretend that one of the vertices is your hitpoint, and simply use that uv coordiantes directly instead of interpolating between them. If you want to do it exact take a look at Barycentric Coordinates.