diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-03-09 12:23:32 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-03-09 12:26:09 +0300 |
commit | 40ef25d000b3708ee1fb408077ac591ed59158d6 (patch) | |
tree | 94bffde498a14003736eec7a30c627df41ab6dc1 | |
parent | 9ffc66b1c0e33b107193af38c71efb86c714dc5b (diff) |
Fix T43891: Skin modifier inverts some faces
-rw-r--r-- | source/blender/modifiers/intern/MOD_skin.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 2bde963029a..4a99168f351 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -965,23 +965,51 @@ static void add_poly(SkinOutput *so, f->mat_nr = so->mat_nr; } -static void connect_frames(SkinOutput *so, - BMVert *frame1[4], -BMVert *frame2[4]) +static void connect_frames( + SkinOutput *so, + BMVert *frame1[4], + BMVert *frame2[4]) { BMVert *q[4][4] = {{frame2[0], frame2[1], frame1[1], frame1[0]}, {frame2[1], frame2[2], frame1[2], frame1[1]}, {frame2[2], frame2[3], frame1[3], frame1[2]}, {frame2[3], frame2[0], frame1[0], frame1[3]}}; - float p[3], no[3]; - int i, swap; + int i; + bool swap; /* Check if frame normals need swap */ - sub_v3_v3v3(p, q[3][0]->co, q[0][0]->co); - normal_quad_v3(no, - q[0][0]->co, q[0][1]->co, - q[0][2]->co, q[0][3]->co); - swap = dot_v3v3(no, p) > 0; +#if 0 + { + /* simple method, works mostly */ + float p[3], no[3]; + sub_v3_v3v3(p, q[3][0]->co, q[0][0]->co); + normal_quad_v3(no, + q[0][0]->co, q[0][1]->co, + q[0][2]->co, q[0][3]->co); + swap = dot_v3v3(no, p) > 0; + } +#else + { + /* comprehensive method, accumulate flipping of all faces */ + float cent_sides[4][3]; + float cent[3]; + float dot = 0.0f; + + for (i = 0; i < 4; i++) { + mid_v3_v3v3v3v3(cent_sides[i], UNPACK4_EX(,q[i],->co)); + } + mid_v3_v3v3v3v3(cent, UNPACK4(cent_sides)); + + for (i = 0; i < 4; i++) { + float p[3], no[3]; + normal_quad_v3(no, UNPACK4_EX(,q[i],->co)); + sub_v3_v3v3(p, cent, cent_sides[i]); + dot += dot_v3v3(no, p); + } + + swap = dot > 0; + } +#endif for (i = 0; i < 4; i++) { if (swap) |