[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39892] branches/bmesh/blender/source/ blender/bmesh/operators: Fixes for smooth shading of primitves.

Howard Trickey howard.trickey at gmail.com
Sat Sep 3 15:08:38 CEST 2011


Revision: 39892
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39892
Author:   howardt
Date:     2011-09-03 13:08:38 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
Fixes for smooth shading of primitves.

Reverses order of vertices that weld op gives to make ngon so that it doesn't
reverse the normal from what it used to be.
Fixed a bunch of inconsistent normals in primitives: circle (made normal(s)
point up instead of down), uvsphere, icosphere, cylinder, and cone.
Reviewed at http://codereview.appspot.com/4959056/.
Cone and Cylinder still don't shade properly with ngon end caps, but that is now a different issue from normals.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/operators/primitiveops.c
    branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c

Modified: branches/bmesh/blender/source/blender/bmesh/operators/primitiveops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/primitiveops.c	2011-09-03 12:57:33 UTC (rev 39891)
+++ branches/bmesh/blender/source/blender/bmesh/operators/primitiveops.c	2011-09-03 13:08:38 UTC (rev 39892)
@@ -41,21 +41,21 @@
 };
 
 static short icoface[20][3] = {
-	{1,0,2},
+	{0,1,2},
 	{1,0,5},
-	{2,0,3},
-	{3,0,4},
-	{4,0,5},
+	{0,2,3},
+	{0,3,4},
+	{0,4,5},
 	{1,5,10},
 	{2,1,6},
 	{3,2,7},
 	{4,3,8},
 	{5,4,9},
-	{10,1,6},
-	{6,2,7},
-	{7,3,8},
-	{8,4,9},
-	{9,5,10},
+	{1,10,6},
+	{2,6,7},
+	{3,7,8},
+	{4,8,9},
+	{5,9,10},
 	{6,10,11},
 	{7,6,11},
 	{8,7,11},
@@ -296,7 +296,8 @@
 	phi= 0; 
 	phid/=2;
 	for(a=0; a<=tot; a++) {
-		vec[0]= dia*sinf(phi);
+		/* Going in this direction, then edge extruding, makes normals face outward */
+		vec[0]= -dia*sinf(phi);
 		vec[1]= 0.0;
 		vec[2]= dia*cosf(phi);
 		eve= BM_Make_Vert(bm, vec, NULL);
@@ -312,8 +313,8 @@
 		preveve = eve;
 	}
 
-	/* extrude and rotate */
-	phi= M_PI/seg;
+	/* extrude and rotate; negative phi to make normals face outward */
+	phi= -M_PI/seg;
 	q[0]= cos(phi);
 	q[3]= sin(phi);
 	q[1]=q[2]= 0;
@@ -469,7 +470,8 @@
 	}
 
 	for (a=0; a<segs; a++, phi+=phid) {
-		vec[0]= dia*sinf(phi);
+		/* Going this way ends up with normal(s) upward */
+		vec[0]= -dia*sinf(phi);
 		vec[1]= dia*cosf(phi);
 		vec[2]= 0.0f;
 		mul_m4_v3(mat, vec);
@@ -501,7 +503,7 @@
 	if (cap_ends) {
 		BMFace *f;
 		
-		f = BM_Make_QuadTri(bm, cent1, firstv1, v1, NULL, NULL, 0);
+		f = BM_Make_QuadTri(bm, cent1, v1, firstv1, NULL, NULL, 0);
 		BMO_SetFlag(bm, f, FACE_NEW);
 	}
 	
@@ -571,7 +573,7 @@
 				
 				f = BM_Make_QuadTri(bm, cent1, lastv1, v1, NULL, NULL, 0);
 				BMO_SetFlag(bm, f, FACE_NEW);
-				f = BM_Make_QuadTri(bm, v2, lastv2, cent2, NULL, NULL, 0);
+				f = BM_Make_QuadTri(bm, cent2, v2, lastv2, NULL, NULL, 0);
 				BMO_SetFlag(bm, f, FACE_NEW);
 			}
 			BM_Make_QuadTri(bm, lastv1, lastv2, v2, v1, NULL, 0);
@@ -590,9 +592,9 @@
 	if (cap_ends) {
 		BMFace *f;
 		
-		f = BM_Make_QuadTri(bm, cent1, firstv1, v1, NULL, NULL, 0);
+		f = BM_Make_QuadTri(bm, cent1, v1, firstv1, NULL, NULL, 0);
 		BMO_SetFlag(bm, f, FACE_NEW);
-		f = BM_Make_QuadTri(bm, v2, firstv2, cent2, NULL, NULL, 0);
+		f = BM_Make_QuadTri(bm, cent2, firstv2, v2, NULL, NULL, 0);
 		BMO_SetFlag(bm, f, FACE_NEW);
 	}
 	
@@ -600,7 +602,7 @@
 		BMO_CallOpf(bm, "dissolvefaces faces=%ff", FACE_NEW);
 	}
 	
-	BM_Make_QuadTri(bm, firstv1, firstv2, v2, v1, NULL, 0);
+	BM_Make_QuadTri(bm, v1, v2, firstv2, firstv1, NULL, 0);
 
 	BMO_CallOpf(bm, "removedoubles verts=%fv dist=%f", VERT_MARK, 0.000001);
 	BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);

Modified: branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c	2011-09-03 12:57:33 UTC (rev 39891)
+++ branches/bmesh/blender/source/blender/bmesh/operators/removedoubles.c	2011-09-03 13:08:38 UTC (rev 39892)
@@ -170,7 +170,6 @@
 		
 		if (BLI_array_count(loops) < 3)
 			continue;
-
 		v = loops[0]->v;
 		v2 = loops[1]->v;
 
@@ -179,7 +178,7 @@
 		if (BMO_TestFlag(bm, v2, ELE_DEL)) 
 			v2 = BMO_Get_MapPointer(bm, op, "targetmap", v2);
 		
-		f2 = BM_Make_Ngon(bm, v2, v, edges, a, 0);
+		f2 = BM_Make_Ngon(bm, v, v2, edges, a, 0);
 		if (f2) {
 			BM_Copy_Attributes(bm, bm, f, f2);
 




More information about the Bf-blender-cvs mailing list