About Store Forum Documentation Contact



Post Reply 
Painting onto a mesh texture
Author Message
Chris Offline
Member

Post: #1
Painting onto a mesh texture
I have Mesh *myMesh; (and not a lot else, no bones etc)

What's the best way I can paint directly onto its diffuse texture? I don't want to add decals to the mesh. I've looked at:

Vec pos, dir; ScreenToPosDir(Vec2(0,0),pos,dir);
PhysHit phys_hit; if(Physics.ray(pos,dir*D.viewRange(),&phys_hit))

But that just tests for hits on an actor.

1. How can I test for collision detection just for triangles of a mesh?
2. Is there a good way to do this with EE, other than getting the triangle, and translating the collision position on the triangle to a UV position?

Thanks for your help,
Chris
(This post was last modified: 04-30-2010 02:59 PM by Chris.)
04-30-2010 11:54 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Painting onto a mesh texture
Hello,

Quote:1. How can I test for collision detection just for triangles of a mesh?
You'd need to use any of those functions:

Code:
Bool Sweep(Vec &point,Vec &move,Mshr      &mshr,Matrix *mesh_matrix=NULL,Flt *hit_frac=NULL,Vec *hit_pos=NULL,Int *hit_face=NULL                                                                     );
Bool Sweep(Vec &point,Vec &move,MeshBase  &mshb,Matrix *mesh_matrix=NULL,Flt *hit_frac=NULL,Vec *hit_pos=NULL,Int *hit_face=NULL                                      ,Bool test_quads_as_2_tris=true);
Bool Sweep(Vec &point,Vec &move,Mesh      &mesh,Matrix *mesh_matrix=NULL,Flt *hit_frac=NULL,Vec *hit_pos=NULL,Int *hit_face=NULL,Int *hit_mshb=NULL                   ,Bool test_quads_as_2_tris=true); // 'hit_mshb'=index of hit MeshBase
Bool Sweep(Vec &point,Vec &move,MeshGroup &mshg,Matrix *mesh_matrix=NULL,Flt *hit_frac=NULL,Vec *hit_pos=NULL,Int *hit_face=NULL,Int *hit_mshb=NULL,Int *hit_mesh=NULL,Bool test_quads_as_2_tris=true); // 'hit_mshb'=index of hit MeshBase, 'hit_mesh'=index of hit Mesh
you can grab the index of mesh part, face index,
compare it to the face triangle vertex positions,
calculate barycentric coordinates of 'hit_pos' on the triangle using helper function:
Code:
// return blending factors 'blend' that (blend.x*tri.p[0] + blend.y*tri.p[1] + blend.z*tri.p[2] == p), these are also known as "barycentric coordinates"
Vec  TriBlend(Vec2  &p,Tri2  &tri);
VecD TriBlend(VecD2 &p,TriD2 &tri);
Vec  TriBlend(Vec   &p,Tri   &tri);
VecD TriBlend(VecD  &p,TriD  &tri);

according to barycentric coordinates you can calculate UV texture position (use triangle uv vertexes combined with obtained barycentric coordinates)
having UV on the texture you can lock it, update and unlock
(per pixel updating requires textures to be non compressed- not DXT)

generally this is slow process.
05-02-2010 12:57 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Painting onto a mesh texture
Thank you so much for the help with the barycentric coordinates - this is exactly what I was after, my supervisor suggested them a while ago but I wasn't sure how to do them in the engine. I can't wait to try this in the lab tomorrow.

EDIT: This works perfectly now <3

Cheers,
Chris
(This post was last modified: 05-03-2010 11:03 AM by Chris.)
05-02-2010 02:44 PM
Find all posts by this user Quote this message in a reply
Post Reply