Selecting a point on an object

I know ray casting can be used to select an object within a scene. I would like to be able to determine the point on the object where the ray intersected, or to determine the corresponding point on a texture . Say for example that I have a sphere as the only object in my scene (OK… lights, stage, etc., but we’re focusing on the ball). The user clicks on the ball (it’s an Android app in this case). I would like to change the color of that point on the surface of the ball.

Hmm… I guess this is like a 3D painting app (that’s not the app, but it may be a good place for me to start): allow the user to provide a model (*.OBJ file, for example) . The app would “cover” the model with a neutral texture (RGB=128,128,128) and then the user could color the model by painting on the surface.

Of course, to do this I need to figure out which point on the model/texture is being selected.

Can jmonkeyengine do this? Can I cast a ray onto a model and get the point of intersection?

Thanks!
– Steve G.

You can get the contact point of the collision:
[java]collisionResults.getClosestCollision().getContactPoint()[/java]

Then with that point you have to do some shader magic. You can pass the point into the fragment shader and then when it is rendering, check the distance to the point and change the color accordingly. It would just be the one spot, unless you save all previous click locations.
I’m not sure of the best technique for saving out the painted locations, probably to an alpha map that you can then use later on in the fragment shader.

Well, I’m not sure shader magic is the answer there.

Once you have the collision point you will then need to track into your uv mapping and vertices to work out what point in the texture that collision point maps to. You can then use ImageRaster or ImagePainter to modify the texture as desired.

All presuming the shaders are yours or well known, that they are not doing any magic, the the texture isn’t repeated, etc…

This is a hard problem in the general case and not enough information has been provided for the specific case.

Can you get this to work with just any loaded model? No, probably not.

Thank you for all the answers. At this point, I have enough information that I believe JME should work for my project. I’m not quite ready to give out the whole idea, but I can add the following pieces:

  1. The model is fixed (won’t be changing).
  2. The texture is fixed (it will probably start as a normal color like RGB=128,128,128).
  3. The datapoints (selected by the user) will be kept in a lightweight database, and I expect to have a custom shader that sets the color based on the proximity to a selection.

My next concerns (and yes, I’m learning about 3D and LOD and all sorts of Good Stuff):
A. The model has 25000 to 50000 faces, and
B. This needs to run on Android.

So now I need to break the model down into components. I’m not yet sure how many faces I can have on the visible side of the model (I believe this equates to the number of visible triangles being processed), so I have some research/work to do. However, at least I feel fairly comfortable that JME is viable. The last engine/library I tried didn’t have the ability to determine collision/selection coordinates, so I wanted to get this issue answered before I started learning JME.

Thanks again,
– Steve G.