diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-28 10:49:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-28 10:49:16 +0400 |
commit | f8d5a0156218fb10e200020da8c0fbe86a16ac5f (patch) | |
tree | 603a5159cbef85b0e8bf8d1ed396c22b78972639 | |
parent | 8d6b280cac09785e8e3e7f0562535ba2108977bb (diff) |
more work on getting bmesh dirty index flags reliable.
now there very close, some hard to redo cases to check on.
-rw-r--r-- | source/blender/bmesh/bmesh.h | 5 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_newcore.c | 12 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bevel.c | 4 | ||||
-rw-r--r-- | source/blender/bmesh/operators/mesh_conv.c | 32 |
5 files changed, 41 insertions, 16 deletions
diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 4f51019a2e0..8b75f5a19f2 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -175,6 +175,11 @@ BM_INLINE void BM_MergeHFlag(void *element_a, void *element_b); * * - '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 */ diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index acb23034ca7..19a1fac3910 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -570,10 +570,14 @@ void BM_ElemIndex_Validate(BMesh *bm, const char *location, const char *func, co 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 } } diff --git a/source/blender/bmesh/intern/bmesh_newcore.c b/source/blender/bmesh/intern/bmesh_newcore.c index 3cfbb88ff52..453c332e5f8 100644 --- a/source/blender/bmesh/intern/bmesh_newcore.c +++ b/source/blender/bmesh/intern/bmesh_newcore.c @@ -25,7 +25,8 @@ BMVert *BM_Make_Vert(BMesh *bm, float co[3], const struct BMVert *example) { 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 @@ BMEdge *BM_Make_Edge(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *example, i 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 @@ BMFace *BM_Make_Face(BMesh *bm, BMVert **verts, BMEdge **edges, int len, int nod 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 @@ static BMFace *bmesh_addpolylist(BMesh *bm, BMFace *UNUSED(example)) 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++; diff --git a/source/blender/bmesh/operators/bevel.c b/source/blender/bmesh/operators/bevel.c index 8d48b86ee84..421306bdd9d 100644 --- a/source/blender/bmesh/operators/bevel.c +++ b/source/blender/bmesh/operators/bevel.c @@ -270,7 +270,7 @@ void bmesh_bevel_exec(BMesh *bm, BMOperator *op) /*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 @@ void bmesh_bevel_exec(BMesh *bm, BMOperator *op) } } - bm->elem_index_dirty |= BM_VERT; + bm->elem_index_dirty |= BM_EDGE; BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { BMIter eiter; diff --git a/source/blender/bmesh/operators/mesh_conv.c b/source/blender/bmesh/operators/mesh_conv.c index 3ab99a5e555..00368e9eb9e 100644 --- a/source/blender/bmesh/operators/mesh_conv.c +++ b/source/blender/bmesh/operators/mesh_conv.c @@ -128,8 +128,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) 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 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) /*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 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) } } + bm->elem_index_dirty &= ~BM_VERT; /* added in order, clear dirty flag */ + if (!me->totedge) { MEM_freeN(vt); return; @@ -170,20 +173,23 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) 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; - - /*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); + + /*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); } + + bm->elem_index_dirty &= ~BM_EDGE; /* added in order, clear dirty flag */ if (!me->totpoly) { MEM_freeN(vt); @@ -224,11 +230,15 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) 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 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) 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; |