diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-09-07 12:15:15 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-09-07 12:15:15 +0400 |
commit | ec1854697bf964cc26dbb75283a88fc3c3681330 (patch) | |
tree | a86047c98a95913d4f4f05f71ac7285663f67631 /source/blender/src/editface.c | |
parent | e3d1a6ea9be51f249692c3934a9a80559be0bd94 (diff) |
Fix for bug #4966:
Texture painting handled non-planar quads incorrectly in some cases.
Diffstat (limited to 'source/blender/src/editface.c')
-rw-r--r-- | source/blender/src/editface.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index 6a671a0da93..fb452c2723c 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -1562,7 +1562,8 @@ static int texpaint_projected_verts(Object *ob, Mesh *mesh, TFace *tf, float *v1 /* compute uv coordinates of mouse in face */ void texpaint_pick_uv(Object *ob, Mesh *mesh, TFace *tf, short *xy, float *uv) { - float v1[2], v2[2], v3[2], v4[2], p[2], w[3]; + float v1[2], v2[2], v3[2], v4[2], p[2], w[3], w2[3]; + float absw, absw2; int nvert; /* compute barycentric coordinates of point in face and interpolate uv's. @@ -1575,14 +1576,16 @@ void texpaint_pick_uv(Object *ob, Mesh *mesh, TFace *tf, short *xy, float *uv) if (nvert == 4) { texpaint_barycentric_2d(v1, v2, v4, p, w); - - if(w[0] < 0.0f) { - /* if w[0] is negative, co is on the other side of the v1-v3 edge, - so we interpolate using the other triangle */ - texpaint_barycentric_2d(v2, v3, v4, p, w); + texpaint_barycentric_2d(v2, v3, v4, p, w2); - uv[0]= tf->uv[1][0]*w[0] + tf->uv[2][0]*w[1] + tf->uv[3][0]*w[2]; - uv[1]= tf->uv[1][1]*w[0] + tf->uv[2][1]*w[1] + tf->uv[3][1]*w[2]; + /* the triangle with the largest absolute values is the one with the + most negative weights */ + absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]); + absw2= fabs(w2[0]) + fabs(w2[1]) + fabs(w2[2]); + + if(absw > absw2) { + uv[0]= tf->uv[1][0]*w2[0] + tf->uv[2][0]*w2[1] + tf->uv[3][0]*w2[2]; + uv[1]= tf->uv[1][1]*w2[0] + tf->uv[2][1]*w2[1] + tf->uv[3][1]*w2[2]; } else { uv[0]= tf->uv[0][0]*w[0] + tf->uv[1][0]*w[1] + tf->uv[3][0]*w[2]; |