Say I have a textured model and I pick an arbitrary point on its surface. This point can either be in local or global space. How would I go about getting the approximate u-v coordinate on the texture that would correspond to the aforementioned arbitrary point I picked?
Is there an easy way to do this without reading the vertex-data from the model in question?
(If it helps to understand the question better, imagine one wanted to paint on a model directly in panda3D, like to paint on the smiley-model for example…)
The best way to do this is by rendering the object to an offscreen buffer with a special gradient texture which at UV coordinates (0, 0) contains the colour (0, 0, 0) and at UV coordinates (1, 1) contains the colour (1, 1, 0). Then, you just have to do a to-RAM render-to-texture and sample at the pixel where the mouse is. The sampled colour value will contain your UV coordinate.
You can use the third channel with a special identifier to distinguish different textures / objects.
To be more specific, I’m doing this by shooting a ray to the faces of a model, getting the vertex and UV data from the face it hits, figuring out what the UV coordinates of the hit point are on the loaded texture of the model and then modifying the pixel (or set of pixels) at those coordinates on the texture as I see fit. So I want to modify an existing texture by painting over it this way. This method works well, but is a bit long-winded.
If I look further into what you propose, will it give me similar results? Will it allow me to paint over an existing texture that is loaded on to a model?