Paint on Mesh Aug 31, 2006
Next week I'll be back to the more usual article type, but since I left off last week when the program was just starting to get interesting I felt inspired to code something related to the intended functionality. So now you can draw directly on the 3d mesh( as well as on the texture.) You can see a rather absurd screenshot here. Since I'm still within my programming comfort zone, I was able to code a lot for this update in a short time.
What the program does
You can now paint directly on the 3d Mesh. Just click left click and draw with the mouse. You can switch to the texture view, which will show the 2d texture, with a wireframe of the mesh UV coordinates over it. You can change the brush size with the [ and ] keys, and pick the color from the texture/mesh by holding alt and left clicking. The mesh viewing options have been expanded, the list now is: wireframe, normals, vertices, textured, lighting. (triangle selection has been disabled.) Ray-Triangle Intersection
To be able to paint on a mesh, you need to be able to retrieve the UV coordinate at the intersection. To do this, I decided to choose a point on the tri as the origin, and calculate the distance along each of the two adjacent tri edges to the intersection point. I googled ray triangle intersection and based my algorithm on one near the bottom of this page, which gives me these distances for free.
I haven't done any benchmarking yet, but the new ray-tri should be faster than my old line-tri. However that would change if I did any pre-calculation for the old one.
Note that UV coordinate calculation is also useful in ray-tracing with texturing, so you can get the texture color at the intersection point. Future Plans
This program is still at the point where it's really just a toy program, and not something particularly useful. I plan to split it off from the weekly tutorial article series, and when it has progressed to the point of being possibly useful release it as a freeware open-source program on its own page. I have plenty of ideas for features to add, but as usual I'm not sure when I'll have the time. I still plan to try some unrelated simple demo programs in future articles, that will probably borrow their base code from the current sample programs. Download
Sample4-Mesh_Paint.zip ( 64K ) :
The source code files are in the main directory. The head mesh and texture are in the data directory. See readme.txt for details.
|