Painting a model

I want to make an application to paint 3d models. I believe I have read every existing thread on the subject and am still quite confused: … ight=paint … fe8100c1bd … 6619#66619

I do not understand the logic. So far, I have been able to write a program that can detect when a model has been clicked, and the coordinates of the point. What is next? How do I get from the x,y,z coordinates to the u,v coordinates of the texture so I can modify it?

One way suggested was to calculate the closest vertex to the point of the click(collision between CollisionRay and model) on the model and find the corresponding U,V coordinates. How can I get a list of the vertexes and their positions, and the u,v coordinates on the texture that correspond?

The other solution suggested using a buffer. The code from the posts suggests that the x,y coordinates of the mouseclick at a point on the model correspond to the x,y coordinates of the texture that is displayed there. I am finding this hard to believe because several points on a model with the same x,y coordinates, but a different z coordinate can have different colors.

Furthermore, when I tried to demo the sample file found on: … ight=paint

called,, my macbook failed to run the program saying:

DirectStart: Starting the game.
Known pipe types:
(all display modules loaded.)
:display(error): Window wouldn’t open; abandoning window.

I think I was able to trace the problem back to the RenderTextureMode, which is an argument of addRenderTexture(). When I commented out the lines, I could get the code to run, but no painting was possible. Changing the mode to any of the other possible RenderTextureModes resulted with this error:

AssertionError: do_has_ram_mipmap_image(n) at line 2875 of panda/src/gobj/texture.cxx

So, I am thinking that this may reflect the importance of using a RAM buffer, but I am not very sure why this is happening. I am running on a 10.5.8 Leopard Macbook under panda3d 1.7.0. I tried downgrading to panda1.6.2 but that version also gave me other kinds of errors, so I came back to 1.7.0.

I would really appreciate your help. I have spent days trying to sort these problems out and have not been able to understand and implement solutions(especially since I cannot even run examples from other people’s painting programs).

Thanks a lot,

Solution (1), walking through the vertices, is possible using a GeomVertexReader. It’s fairly complicated to walk through the vertices of a model, but there is a whole chapter in the manual devoted to this subject, called “Advanced operations with Panda3D’s internal structures”.

Solution (2), using a buffer, requires you to render the model with a special texture applied that encodes the UV coordinates into the RGB colors. That is, if you have a texture that ranges from 0 to 255 along the horizontal axis in the red channel, and from 0 to 255 along the vertical axis in the blue channel, then when you sample a pixel from the rendered image, you only have to examine the R and G colors and divide by 255 to get the corresponding U and V values.

It is, of course, necessary to copy the rendered image to RAM, in order to look up rendered pixel values on the CPU. I’m not sure why the sample program is failing, but it might just be crufty. Are you sure it’s failing to launch? It’s supposed to start with a gray window, after all; try pulling the camera back (on Mac, hold down the command key and the mouse button and drag the mouse from near the bottom of the window to the top).