diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-01 05:41:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-01 05:41:56 +0400 |
commit | f06bbaed9263fbcc00a91ca47edcaace288efe9c (patch) | |
tree | ae72a5ae61f9d9f1f07f0e5292d42004272b20a6 /source/blender | |
parent | 25098c741b4ee227b4d63ab3d56bb5e829305612 (diff) |
split BMFlags_To_MEFlags & MEFlags_To_BMFlags into type specific calls, since we always know the types with these functions theres not much point in having generic calls with a type switch.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedbmesh.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/bmesh.h | 13 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 110 | ||||
-rw-r--r-- | source/blender/bmesh/operators/mesh_conv.c | 14 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_meshdata_types.h | 2 |
7 files changed, 114 insertions, 61 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 470f6a09d65..9a1a5cfaafa 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -2021,7 +2021,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis normal_float_to_short_v3(mv->no, eve->no); - mv->flag = BMFlags_To_MEFlags(eve); + mv->flag = BM_Vert_Flag_To_MEFlag(eve); if (has_vert_bweight) mv->bweight = (unsigned char)(BM_GetCDf(&bm->vdata, eve, CD_BWEIGHT)*255.0f); @@ -2047,7 +2047,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis if (has_edge_bweight) med->bweight = (unsigned char)(BM_GetCDf(&bm->edata, eed, CD_BWEIGHT)*255.0f); - med->flag = BMFlags_To_MEFlags(eed); + med->flag = BM_Edge_Flag_To_MEFlag(eed); CustomData_from_bmesh_block(&bm->edata, &dm->edgeData, eed->head.data, i); if (add_orig) *index = i; @@ -2068,7 +2068,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis mf->v3 = BM_GetIndex(l[2]->v); mf->v4 = 0; mf->mat_nr = efa->mat_nr; - mf->flag = BMFlags_To_MEFlags(efa); + mf->flag = BM_Face_Flag_To_MEFlag(efa); *index = add_orig ? BM_GetIndex(efa) : *(int*)CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_ORIGINDEX); *polyindex = BM_GetIndex(efa); @@ -2085,7 +2085,7 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis MPoly *mp = &mpoly[i]; mp->totloop = efa->len; - mp->flag = BMFlags_To_MEFlags(efa); + mp->flag = BM_Face_Flag_To_MEFlag(efa); mp->loopstart = j; mp->mat_nr = efa->mat_nr; diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c index 08c4ea5fa00..df28ab99bec 100644 --- a/source/blender/blenkernel/intern/editderivedbmesh.c +++ b/source/blender/blenkernel/intern/editderivedbmesh.c @@ -1294,11 +1294,9 @@ static int bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *vert_r) { copy_v3_v3(vert_r->co, ev->co); - vert_r->no[0] = (short)(ev->no[0] * 32767.0f); - vert_r->no[1] = (short)(ev->no[1] * 32767.0f); - vert_r->no[2] = (short)(ev->no[2] * 32767.0f); + normal_float_to_short_v3(vert_r->no, ev->no); - vert_r->flag = BMFlags_To_MEFlags(ev); + vert_r->flag = BM_Vert_Flag_To_MEFlag(ev); if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { vert_r->bweight = (unsigned char) (BM_GetCDf(&bm->vdata, ev, CD_BWEIGHT)*255.0f); @@ -1341,7 +1339,7 @@ static void bmDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r) edge_r->crease = (unsigned char) (BM_GetCDf(&bm->edata, e, CD_CREASE)*255.0f); } - edge_r->flag = BMFlags_To_MEFlags(e); + edge_r->flag = BM_Edge_Flag_To_MEFlag(e); edge_r->v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(bmdm->vhash, e->v1)); edge_r->v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(bmdm->vhash, e->v2)); @@ -1363,7 +1361,7 @@ static void bmDM_getTessFace(DerivedMesh *dm, int index, MFace *face_r) ef = l[0]->f; face_r->mat_nr = (unsigned char) ef->mat_nr; - face_r->flag = BMFlags_To_MEFlags(ef); + face_r->flag = BM_Face_Flag_To_MEFlag(ef); face_r->v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(bmdm->vhash, l[0]->v)); face_r->v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(bmdm->vhash, l[1]->v)); @@ -1383,11 +1381,9 @@ static void bmDM_copyVertArray(DerivedMesh *dm, MVert *vert_r) for( ; ev; ev = BMIter_Step(&iter), ++vert_r) { copy_v3_v3(vert_r->co, ev->co); - vert_r->no[0] = (short) (ev->no[0] * 32767.0); - vert_r->no[1] = (short) (ev->no[1] * 32767.0); - vert_r->no[2] = (short) (ev->no[2] * 32767.0); + normal_float_to_short_v3(vert_r->no, ev->no); - vert_r->flag = BMFlags_To_MEFlags(ev); + vert_r->flag = BM_Vert_Flag_To_MEFlag(ev); if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) { vert_r->bweight = (unsigned char) (BM_GetCDf(&bm->vdata, ev, CD_BWEIGHT)*255.0f); @@ -1415,7 +1411,7 @@ static void bmDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r) edge_r->crease = (unsigned char) (BM_GetCDf(&bm->edata, ee, CD_CREASE)*255.0f); } - edge_r->flag = BMFlags_To_MEFlags(ee); + edge_r->flag = BM_Edge_Flag_To_MEFlag(ee); edge_r->v1 = (int)BM_GetIndex(ee->v1); edge_r->v2 = (int)BM_GetIndex(ee->v2); @@ -1438,7 +1434,7 @@ static void bmDM_copyTessFaceArray(DerivedMesh *dm, MFace *face_r) face_r->mat_nr = (unsigned char) ef->mat_nr; - face_r->flag = BMFlags_To_MEFlags(ef); + face_r->flag = BM_Face_Flag_To_MEFlag(ef); face_r->v1 = BM_GetIndex(l[0]->v); face_r->v2 = BM_GetIndex(l[1]->v); @@ -1479,7 +1475,7 @@ static void bmDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r) i = 0; BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { - poly_r->flag = BMFlags_To_MEFlags(f); + poly_r->flag = BM_Face_Flag_To_MEFlag(f); poly_r->loopstart = i; poly_r->totloop = f->len; poly_r->mat_nr = f->mat_nr; diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index 2dc994b2159..079d8fad7cb 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -148,7 +148,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing) for (i=0; i<totvert; i++, mv++) { v = BM_Make_Vert(bm, mv->co, NULL); normal_short_to_float_v3(v->no, mv->no); - v->head.hflag = MEFlags_To_BMFlags(mv->flag, BM_VERT); + v->head.hflag = BM_Vert_Flag_From_MEFlag(mv->flag); CustomData_to_bmesh_block(&dm->vertData, &bm->vdata, i, &v->head.data); vtable[i] = v; @@ -160,7 +160,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing) for (i=0; i<totedge; i++, me++) { e = BM_Make_Edge(bm, vtable[me->v1], vtable[me->v2], NULL, 0); - e->head.hflag = MEFlags_To_BMFlags(me->flag, BM_EDGE); + e->head.hflag = BM_Edge_Flag_From_MEFlag(me->flag); CustomData_to_bmesh_block(&dm->edgeData, &bm->edata, i, &e->head.data); etable[i] = e; @@ -190,7 +190,7 @@ BMEditMesh *CDDM_To_BMesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing) if (!f) continue; - f->head.hflag = MEFlags_To_BMFlags(mp->flag, BM_FACE); + f->head.hflag = BM_Vert_Flag_From_MEFlag(mp->flag); f->mat_nr = mp->mat_nr; l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f); diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 80bdc8e4713..970e0bbdf18 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -303,6 +303,8 @@ BMesh *init_editmesh_to_bmesh ( struct EditMesh *em, struct BMOperator *op ); /*converts a bmesh to an editmesh*/ struct EditMesh *bmesh_to_editmesh ( BMesh *bm ); +/* unused, type spesific functions below */ +#if 0 /*convert between bmesh and Mesh flags*/ short BMFlags_To_MEFlags(void *element); @@ -312,6 +314,17 @@ short BMFlags_To_MEFlags(void *element); parameter (the three defines map to MVert, MEdge, and MPoly, respectively).*/ char MEFlags_To_BMFlags(const short hflag, const char htype); +#endif + +/* flag conversion funcs */ +char BM_Face_Flag_From_MEFlag(const char mflag); +char BM_Edge_Flag_From_MEFlag(const short mflag); +char BM_Vert_Flag_From_MEFlag(const char mflag); +/* reverse */ +char BM_Face_Flag_To_MEFlag(BMFace *f); +short BM_Edge_Flag_To_MEFlag(BMEdge *e); +char BM_Vert_Flag_To_MEFlag(BMVert *v); + /*convert MLoop*** in a bmface to mtface and mcol in an MFace*/ diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index 1b228c84c91..da7cd9c6692 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -626,6 +626,62 @@ BMesh *BM_Copy_Mesh(BMesh *bmold) return bm; } +/* ME -> BM */ +char BM_Vert_Flag_From_MEFlag(const char meflag) +{ + return ( ((meflag & SELECT) ? BM_SELECT : 0) | + ((meflag & ME_HIDE) ? BM_HIDDEN : 0) + ); +} +char BM_Edge_Flag_From_MEFlag(const short meflag) +{ + return ( ((meflag & SELECT) ? BM_SELECT : 0) | + ((meflag & ME_SEAM) ? BM_SEAM : 0) | + ((meflag & ME_SHARP) ? BM_SHARP : 0) | + ((meflag & ME_HIDE) ? BM_HIDDEN : 0) + ); +} +char BM_Face_Flag_From_MEFlag(const char meflag) +{ + return ( ((meflag & ME_FACE_SEL) ? BM_SELECT : 0) | + ((meflag & ME_SMOOTH) ? BM_SMOOTH : 0) | + ((meflag & ME_HIDE) ? BM_HIDDEN : 0) + ); +} + +/* BM -> ME */ +char BM_Vert_Flag_To_MEFlag(BMVert *eve) +{ + const char hflag= eve->head.hflag; + + return ( ((hflag & BM_SELECT) ? SELECT : 0) | + ((hflag & BM_HIDDEN) ? ME_HIDE : 0) + ); +} +short BM_Edge_Flag_To_MEFlag(BMEdge *eed) +{ + const char hflag= eed->head.hflag; + + return ( ((hflag & BM_SELECT) ? SELECT : 0) | + ((hflag & BM_SEAM) ? ME_SEAM : 0) | + ((hflag & BM_SHARP) ? ME_SHARP : 0) | + ((hflag & BM_HIDDEN) ? ME_HIDE : 0) | + ((BM_Wire_Edge(NULL, eed)) ? ME_LOOSEEDGE : 0) | /* not typical */ + (ME_EDGEDRAW | ME_EDGERENDER) + ); +} +char BM_Face_Flag_To_MEFlag(BMFace *efa) +{ + const char hflag= efa->head.hflag; + + return ( ((hflag & BM_SELECT) ? ME_FACE_SEL : 0) | + ((hflag & BM_SMOOTH) ? ME_SMOOTH : 0) | + ((hflag & BM_HIDDEN) ? ME_HIDE : 0) + ); +} + +/* unused, type spesific functions below */ +#if 0 /* BM FLAGS TO ME FLAGS @@ -633,30 +689,22 @@ BMesh *BM_Copy_Mesh(BMesh *bmold) which much be either a BMVert, BMEdge, or BMFace, converted to mesh flags. */ - short BMFlags_To_MEFlags(void *element) { const char src_htype= ((BMHeader *)element)->htype; - const char src_hflag= ((BMHeader *)element)->hflag; - - short dst_flag= 0; - - if (src_hflag & BM_HIDDEN) dst_flag |= ME_HIDE; if (src_htype == BM_FACE) { - if (src_hflag & BM_SELECT) dst_flag |= ME_FACE_SEL; - if (src_hflag & BM_SMOOTH) dst_flag |= ME_SMOOTH; - } else if (src_htype == BM_EDGE) { - if (src_hflag & BM_SELECT) dst_flag |= SELECT; - if (src_hflag & BM_SEAM) dst_flag |= ME_SEAM; - if (src_hflag & BM_SHARP) dst_flag |= ME_SHARP; - if (BM_Wire_Edge(NULL, element)) dst_flag |= ME_LOOSEEDGE; - dst_flag |= ME_EDGEDRAW | ME_EDGERENDER; - } else if (src_htype == BM_VERT) { - if (src_hflag & BM_SELECT) dst_flag |= SELECT; + return BM_Face_Flag_To_MEFlag(element); + } + else if (src_htype == BM_EDGE) { + return BM_Edge_Flag_To_MEFlag(element); + } + else if (src_htype == BM_VERT) { + return BM_Vert_Flag_To_MEFlag(element); + } + else { + return 0; } - - return dst_flag; } /* @@ -670,21 +718,17 @@ short BMFlags_To_MEFlags(void *element) */ char MEFlags_To_BMFlags(const short hflag, const char htype) { - char f= 0; - if (htype == BM_FACE) { - if (hflag & ME_FACE_SEL) f |= BM_SELECT; - if (hflag & ME_SMOOTH) f |= BM_SMOOTH; - if (hflag & ME_HIDE) f |= BM_HIDDEN; - } else if (htype == BM_EDGE) { - if (hflag & SELECT) f |= BM_SELECT; - if (hflag & ME_SEAM) f |= BM_SEAM; - if (hflag & ME_SHARP) f |= BM_SHARP; - if (hflag & ME_HIDE) f |= BM_HIDDEN; - } else if (htype == BM_VERT) { - if (hflag & SELECT) f |= BM_SELECT; - if (hflag & ME_HIDE) f |= BM_HIDDEN; + return BM_Face_Flag_From_MEFlag(hflag); + } + else if (htype == BM_EDGE) { + return BM_Edge_Flag_From_MEFlag(hflag); + } + else if (htype == BM_VERT) { + return BM_Vert_Flag_From_MEFlag(hflag); + } + else { + return 0; } - - return f; } +#endif diff --git a/source/blender/bmesh/operators/mesh_conv.c b/source/blender/bmesh/operators/mesh_conv.c index 00368e9eb9e..b87b5e436b8 100644 --- a/source/blender/bmesh/operators/mesh_conv.c +++ b/source/blender/bmesh/operators/mesh_conv.c @@ -132,7 +132,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) vt[i] = v; /*transfer flags*/ - v->head.hflag = MEFlags_To_BMFlags(mvert->flag, BM_VERT); + v->head.hflag = BM_Vert_Flag_From_MEFlag(mvert->flag); /*this is necassary for selection counts to work properly*/ if (BM_TestHFlag(v, BM_SELECT)) BM_Select_Vert(bm, v, 1); @@ -177,7 +177,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) et[i] = e; /*transfer flags*/ - e->head.hflag = MEFlags_To_BMFlags(medge->flag, BM_EDGE); + e->head.hflag = BM_Edge_Flag_From_MEFlag(medge->flag); /*this is necassary for selection counts to work properly*/ if (BM_TestHFlag(e, BM_SELECT)) BM_Select(bm, e, 1); @@ -240,7 +240,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) BM_SetIndex(f, bm->totface-1); /* set_ok */ /*transfer flags*/ - f->head.hflag = MEFlags_To_BMFlags(mpoly->flag, BM_FACE); + f->head.hflag = BM_Face_Flag_From_MEFlag(mpoly->flag); /*this is necassary for selection counts to work properly*/ if (BM_TestHFlag(f, BM_SELECT)) BM_Select(bm, f, 1); @@ -527,7 +527,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) copy_v3_v3(mvert->co, v->co); normal_float_to_short_v3(mvert->no, v->no); - mvert->flag = BMFlags_To_MEFlags(v); + mvert->flag = BM_Vert_Flag_To_MEFlag(v); BM_SetIndex(v, i); /* set_inline */ @@ -552,7 +552,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) med->crease = crease ? (char)((*crease)*255) : 0; med->bweight = bweight ? (char)((*bweight)*255) : 0; - med->flag = BMFlags_To_MEFlags(e); + med->flag = BM_Edge_Flag_To_MEFlag(e); BM_SetIndex(e, i); /* set_inline */ @@ -655,7 +655,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) } mface->mat_nr = f->mat_nr; - mface->flag = BMFlags_To_MEFlags(f); + mface->flag = BM_Face_Flag_To_MEFlag(f); mface->v1 = BM_GetIndex(ls[0]->v); mface->v2 = BM_GetIndex(ls[1]->v); @@ -683,7 +683,7 @@ void bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) mpoly->loopstart = j; mpoly->totloop = f->len; mpoly->mat_nr = f->mat_nr; - mpoly->flag = BMFlags_To_MEFlags(f); + mpoly->flag = BM_Face_Flag_To_MEFlag(f); l = BMIter_New(&liter, bm, BM_LOOPS_OF_FACE, f); for ( ; l; l=BMIter_Step(&liter), j++, mloop++) { diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 3a8fecc133c..c4fb1c9b33a 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -80,7 +80,7 @@ typedef struct MPoly { /*offset into loop array and number of loops in the face*/ int loopstart, totloop; short mat_nr; - short flag; + char flag, pad; } MPoly; /*the e here is because we want to move away from |