[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42207] branches/bmesh/blender/source/ blender/bmesh: more work on getting bmesh dirty index flags reliable.

Campbell Barton ideasman42 at gmail.com
Mon Nov 28 07:49:25 CET 2011


Revision: 42207
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42207
Author:   campbellbarton
Date:     2011-11-28 06:49:16 +0000 (Mon, 28 Nov 2011)
Log Message:
-----------
more work on getting bmesh dirty index flags reliable.

now there very close, some hard to redo cases to check on.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mesh.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
    branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
    branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-11-28 05:56:00 UTC (rev 42206)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2011-11-28 06:49:16 UTC (rev 42207)
@@ -175,6 +175,11 @@
  *
  * - 'set_ok'      -- this is valid use since the part of the code is low level.
  *
+ * - 'set_ok_invalid'  -- set to -1 on purpose since this should not be
+ *                    used without a full array re-index, do this on
+ *                    adding new vert/edge/faces since they may be added at
+ *                    the end of the array.
+ *
  * - 'set_loop'    -- currently loop index values are not used used much so
  *                    assume each case they are dirty.
  * - campbell */

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mesh.c	2011-11-28 05:56:00 UTC (rev 42206)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mesh.c	2011-11-28 06:49:16 UTC (rev 42207)
@@ -570,10 +570,14 @@
 			        location, func, type_names[i], err_idx, err_val, msg_a, msg_b);
 		}
 		else if ((is_error == FALSE) && (is_dirty == TRUE)) {
+
+#if 0		/* mostly annoying */
+
 			/* dirty may have been incorrectly set */
 			fprintf(stderr,
 			        "Invalid Dirty: at %s, %s (%s), dirty flag was set but all index values are correct, '%s', '%s'\n",
 			        location, func, type_names[i], msg_a, msg_b);
+#endif
 		}
 	}
 

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2011-11-28 05:56:00 UTC (rev 42206)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_newcore.c	2011-11-28 06:49:16 UTC (rev 42207)
@@ -25,7 +25,8 @@
 {
 	BMVert *v = BLI_mempool_calloc(bm->vpool);
 
-	BM_SetIndex(v, bm->totvert); /* set_ok */
+	BM_SetIndex(v, -1); /* set_ok_invalid */
+	bm->elem_index_dirty |= BM_VERT; /* may add to middle of the pool */
 
 	bm->totvert++;
 
@@ -81,7 +82,8 @@
 	
 	e = BLI_mempool_calloc(bm->epool);
 
-	BM_SetIndex(e, bm->totedge); /* set_ok */
+	BM_SetIndex(e, -1); /* set_ok_invalid */
+	bm->elem_index_dirty |= BM_EDGE; /* may add to middle of the pool */
 
 	bm->totedge++;
 
@@ -230,7 +232,8 @@
 	
 	f = BLI_mempool_calloc(bm->fpool);
 
-	BM_SetIndex(f, bm->totface); /* set_ok */
+	BM_SetIndex(f, -1); /* set_ok_invalid */
+	bm->elem_index_dirty |= BM_FACE; /* may add to middle of the pool */
 
 	bm->totface++;
 
@@ -925,7 +928,8 @@
 	f->head.htype = BM_FACE;
 	BLI_addtail(&f->loops, lst);
 
-	BM_SetIndex(f, bm->totface); /* set_ok */
+	BM_SetIndex(f, -1); /* set_ok_invalid */
+	bm->elem_index_dirty |= BM_FACE; /* may add to middle of the pool */
 
 	bm->totface++;
 

Modified: branches/bmesh/blender/source/blender/bmesh/operators/bevel.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/bevel.c	2011-11-28 05:56:00 UTC (rev 42206)
+++ branches/bmesh/blender/source/blender/bmesh/operators/bevel.c	2011-11-28 06:49:16 UTC (rev 42207)
@@ -270,7 +270,7 @@
 				/*create tags for all loops in l->f*/
 				BM_ITER(l2, &liter2, bm, BM_LOOPS_OF_FACE, l->f) {
 					BLI_array_growone(tags);
-					BM_SetIndex(l2, BLI_array_count(tags)-1); /* set_ok (loop) */
+					BM_SetIndex(l2, BLI_array_count(tags)-1); /* set_loop */
 					
 					if (!BLI_smallhash_haskey(&hash, (intptr_t)l2->e)) {
 						BLI_array_growone(etags);
@@ -287,7 +287,7 @@
 		}
 	}
 
-	bm->elem_index_dirty |= BM_VERT;
+	bm->elem_index_dirty |= BM_EDGE;
 
 	BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) {
 		BMIter eiter;

Modified: branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c	2011-11-28 05:56:00 UTC (rev 42206)
+++ branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c	2011-11-28 06:49:16 UTC (rev 42207)
@@ -128,8 +128,7 @@
 
 	for (i=0, mvert = me->mvert; i<me->totvert; i++, mvert++) {
 		v = BM_Make_Vert(bm, keyco&&set_key ? keyco[i] : mvert->co, NULL);
-		normal_short_to_float_v3(v->no, mvert->no);
-
+		BM_SetIndex(v, i); /* set_ok */
 		vt[i] = v;
 
 		/*transfer flags*/
@@ -138,6 +137,8 @@
 		/*this is necassary for selection counts to work properly*/
 		if (BM_TestHFlag(v, BM_SELECT)) BM_Select_Vert(bm, v, 1);
 
+		normal_short_to_float_v3(v->no, mvert->no);
+
 		BM_SetCDf(&bm->vdata, v, CD_BWEIGHT, (float)mvert->bweight / 255.0f);
 
 		/*Copy Custom Data*/
@@ -160,6 +161,8 @@
 		}
 	}
 
+	bm->elem_index_dirty &= ~BM_VERT; /* added in order, clear dirty flag */
+
 	if (!me->totedge) {
 		MEM_freeN(vt);
 		return;
@@ -170,20 +173,23 @@
 	medge = me->medge;
 	for (i=0; i<me->totedge; i++, medge++) {
 		e = BM_Make_Edge(bm, vt[medge->v1], vt[medge->v2], NULL, 0);
+		BM_SetIndex(e, i); /* set_ok */
 		et[i] = e;
+
+		/*transfer flags*/
+		e->head.hflag = MEFlags_To_BMFlags(medge->flag, BM_EDGE);
+
+		/*this is necassary for selection counts to work properly*/
+		if (BM_TestHFlag(e, BM_SELECT)) BM_Select(bm, e, 1);
 		
 		/*Copy Custom Data*/
 		CustomData_to_bmesh_block(&me->edata, &bm->edata, i, &e->head.data);
 		
 		BM_SetCDf(&bm->edata, e, CD_CREASE, (float)medge->crease / 255.0f);
 		BM_SetCDf(&bm->edata, e, CD_BWEIGHT, (float)medge->bweight / 255.0f);
+	}
 
-		/*transfer flags*/
-		e->head.hflag = MEFlags_To_BMFlags(medge->flag, BM_EDGE);
-
-		/*this is necassary for selection counts to work properly*/
-		if (BM_TestHFlag(e, BM_SELECT)) BM_Select(bm, e, 1);
-	}
+	bm->elem_index_dirty &= ~BM_EDGE; /* added in order, clear dirty flag */
 	
 	if (!me->totpoly) {
 		MEM_freeN(vt);
@@ -224,11 +230,15 @@
 		f = BM_Make_Face(bm, verts, fedges, mpoly->totloop, 0);
 
 		if (!f) {
-			printf("Warning! Bad face in mesh"
-			       " \"%s\" at index %d!\n", me->id.name+2, i);
+			printf("%s: Warning! Bad face in mesh"
+			       " \"%s\" at index %d!, skipping\n",
+			       __func__, me->id.name+2, i);
 			continue;
 		}
 
+		/* dont use 'i' since we may have skipped the face */
+		BM_SetIndex(f, bm->totface-1); /* set_ok */
+
 		/*transfer flags*/
 		f->head.hflag = MEFlags_To_BMFlags(mpoly->flag, BM_FACE);
 
@@ -248,6 +258,8 @@
 		CustomData_to_bmesh_block(&me->pdata, &bm->pdata, i, &f->head.data);
 	}
 
+	bm->elem_index_dirty &= ~BM_FACE; /* added in order, clear dirty flag */
+
 	{
 		BMIter fiter;
 		BMIter liter;




More information about the Bf-blender-cvs mailing list