[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56331] trunk/blender/source/blender: real fix for [#35097], (curve cap flipping).

Campbell Barton ideasman42 at gmail.com
Fri Apr 26 23:04:12 CEST 2013


Revision: 56331
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56331
Author:   campbellbarton
Date:     2013-04-26 21:04:12 +0000 (Fri, 26 Apr 2013)
Log Message:
-----------
real fix for [#35097], (curve cap flipping).

previous commit was incorrect, the face flipping depended on the orientation of the curve.

fix by passing the bevel direction to the fill function so we can have a reliable front/back.

This also gives some speedup for all curve filling since we can avoid calculating the normal since its already known.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_displist.h
    trunk/blender/source/blender/blenkernel/intern/displist.c
    trunk/blender/source/blender/blenlib/intern/scanfill.c
    trunk/blender/source/blender/editors/mesh/editmesh_select.c
    trunk/blender/source/blender/python/mathutils/mathutils_geometry.c

Modified: trunk/blender/source/blender/blenkernel/BKE_displist.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_displist.h	2013-04-26 20:04:58 UTC (rev 56330)
+++ trunk/blender/source/blender/blenkernel/BKE_displist.h	2013-04-26 21:04:12 UTC (rev 56331)
@@ -95,7 +95,7 @@
 void BKE_displist_make_mball_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase);
 
 bool BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4);
-void BKE_displist_fill(struct ListBase *dispbase, struct ListBase *to, int flipnormal);
+void BKE_displist_fill(struct ListBase *dispbase, struct ListBase *to, const float normal_proj[3], const bool flipnormal);
 
 float BKE_displist_calc_taper(struct Scene *scene, struct Object *taperobj, int cur, int tot);
 

Modified: trunk/blender/source/blender/blenkernel/intern/displist.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/displist.c	2013-04-26 20:04:58 UTC (rev 56330)
+++ trunk/blender/source/blender/blenkernel/intern/displist.c	2013-04-26 21:04:12 UTC (rev 56331)
@@ -444,8 +444,12 @@
 	}
 }
 
-
-void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal)
+/**
+ * \param normal_proj  Optional normal thats used to project the scanfill verts into 2d coords.
+ * Pass this along if known since it saves time calculating the normal.
+ * \param flipnormal  Flip the normal (same as passing \a normal_proj negated)
+ */
+void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj[3], const bool flipnormal)
 {
 	ScanFillContext sf_ctx;
 	ScanFillVert *sf_vert, *sf_vert_new, *sf_vert_last;
@@ -508,7 +512,10 @@
 		}
 
 		/* XXX (obedit && obedit->actcol) ? (obedit->actcol-1) : 0)) { */
-		if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES))) {
+		if (totvert && (tot = BLI_scanfill_calc_ex(&sf_ctx,
+		                                           BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES,
+		                                           normal_proj)))
+		{
 			if (tot) {
 				dlnew = MEM_callocN(sizeof(DispList), "filldisplist");
 				dlnew->type = DL_INDEX3;
@@ -568,6 +575,7 @@
 
 static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
 {
+	const float z_up[3] = {0.0f, 0.0f, 1.0f};
 	ListBase front, back;
 	DispList *dl, *dlnew;
 	float *fp, *fp1;
@@ -624,13 +632,13 @@
 		dl = dl->next;
 	}
 
-	BKE_displist_fill(&front, dispbase, 1);
-	BKE_displist_fill(&back, dispbase, 0);
+	BKE_displist_fill(&front, dispbase, z_up, true);
+	BKE_displist_fill(&back, dispbase, z_up, false);
 
 	BKE_displist_free(&front);
 	BKE_displist_free(&back);
 
-	BKE_displist_fill(dispbase, dispbase, 0);
+	BKE_displist_fill(dispbase, dispbase, z_up, false);
 }
 
 static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dispbase)
@@ -642,7 +650,8 @@
 		bevels_to_filledpoly(cu, dispbase);
 	}
 	else {
-		BKE_displist_fill(dispbase, dispbase, 0);
+		/* TODO, investigate passing zup instead of NULL */
+		BKE_displist_fill(dispbase, dispbase, NULL,0);
 	}
 }
 
@@ -1436,6 +1445,8 @@
 						DispList *dlb;
 						ListBase bottom_capbase = {NULL, NULL};
 						ListBase top_capbase = {NULL, NULL};
+						float bottom_no[3] = {0.0f};
+						float top_no[3] = {0.0f};
 
 						for (dlb = dlbev.first; dlb; dlb = dlb->next) {
 							const float bevfac1 = min_ff(cu->bevfac1, cu->bevfac2);
@@ -1527,10 +1538,14 @@
 									rotateBevelPiece(cu, bevp, NULL, dlb, 0.0f, widfac, fac, &data);
 
 								if (cu->bevobj && (cu->flag & CU_FILL_CAPS) && !(nu->flagu & CU_NURB_CYCLIC)) {
-									if (a == 1)
+									if (a == 1) {
 										fillBevelCap(nu, dlb, cur_data - 3 * dlb->nr, &bottom_capbase);
-									if (a == steps - 1)
+										negate_v3_v3(bottom_no, bevp->dir);
+									}
+									if (a == steps - 1) {
 										fillBevelCap(nu, dlb, cur_data, &top_capbase);
+										copy_v3_v3(top_no, bevp->dir);
+									}
 								}
 							}
 
@@ -1539,8 +1554,8 @@
 						}
 
 						if (bottom_capbase.first) {
-							BKE_displist_fill(&bottom_capbase, dispbase, false);
-							BKE_displist_fill(&top_capbase, dispbase, true);
+							BKE_displist_fill(&bottom_capbase, dispbase, bottom_no, false);
+							BKE_displist_fill(&top_capbase, dispbase, top_no, false);
 							BKE_displist_free(&bottom_capbase);
 							BKE_displist_free(&top_capbase);
 						}

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/scanfill.c	2013-04-26 20:04:58 UTC (rev 56330)
+++ trunk/blender/source/blender/blenlib/intern/scanfill.c	2013-04-26 21:04:12 UTC (rev 56331)
@@ -867,7 +867,7 @@
 	float *min_xy_p, *max_xy_p;
 	short a, c, poly = 0, ok = 0, toggle = 0;
 	int totfaces = 0; /* total faces added */
-	int co_x, co_y;
+	float mat_2d[3][3];
 
 	/* reset variables */
 	eve = sf_ctx->fillvertbase.first;
@@ -960,7 +960,7 @@
 			return 0;
 		}
 
-		axis_dominant_v3(&co_x, &co_y, n);
+		axis_dominant_v3_to_m3(mat_2d, n);
 	}
 
 
@@ -968,8 +968,7 @@
 	if (flag & BLI_SCANFILL_CALC_HOLES) {
 		eve = sf_ctx->fillvertbase.first;
 		while (eve) {
-			eve->xy[0] = eve->co[co_x];
-			eve->xy[1] = eve->co[co_y];
+			mul_v2_m3v3(eve->xy, mat_2d, eve->co);
 
 			/* get first vertex with no poly number */
 			if (eve->poly_nr == 0) {
@@ -1016,8 +1015,7 @@
 
 		eve = sf_ctx->fillvertbase.first;
 		while (eve) {
-			eve->xy[0] = eve->co[co_x];
-			eve->xy[1] = eve->co[co_y];
+			mul_v2_m3v3(eve->xy, mat_2d, eve->co);
 			eve->poly_nr = poly;
 			eve = eve->next;
 		}

Modified: trunk/blender/source/blender/editors/mesh/editmesh_select.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_select.c	2013-04-26 20:04:58 UTC (rev 56330)
+++ trunk/blender/source/blender/editors/mesh/editmesh_select.c	2013-04-26 21:04:12 UTC (rev 56331)
@@ -144,6 +144,7 @@
 	DispList *dl;
 	float *fp;
 	int a;
+	const float z_up[3] = {0.0f, 0.0f, 1.0f};
 	
 	/* make displist */
 	dl = MEM_callocN(sizeof(DispList), "poly disp");
@@ -159,7 +160,7 @@
 	}
 	
 	/* do the fill */
-	BKE_displist_fill(&lb, &lb, 0);
+	BKE_displist_fill(&lb, &lb, z_up, false);
 
 	/* do the draw */
 	dl = lb.first;  /* filldisplist adds in head of list */

Modified: trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2013-04-26 20:04:58 UTC (rev 56330)
+++ trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2013-04-26 21:04:12 UTC (rev 56331)
@@ -1343,7 +1343,8 @@
 	}
 	else if (totpoints) {
 		/* now make the list to return */
-		BKE_displist_fill(&dispbase, &dispbase, 0);
+		/* TODO, add normal arg */
+		BKE_displist_fill(&dispbase, &dispbase, NULL, false);
 
 		/* The faces are stored in a new DisplayList
 		 * thats added to the head of the listbase */




More information about the Bf-blender-cvs mailing list