[Bf-blender-cvs] [40ef25d] master: Fix T43891: Skin modifier inverts some faces

Campbell Barton noreply at git.blender.org
Mon Mar 9 10:26:56 CET 2015


Commit: 40ef25d000b3708ee1fb408077ac591ed59158d6
Author: Campbell Barton
Date:   Mon Mar 9 20:23:32 2015 +1100
Branches: master
https://developer.blender.org/rB40ef25d000b3708ee1fb408077ac591ed59158d6

Fix T43891: Skin modifier inverts some faces

===================================================================

M	source/blender/modifiers/intern/MOD_skin.c

===================================================================

diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index 2bde963..4a99168 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)




More information about the Bf-blender-cvs mailing list