diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-30 12:54:05 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-04-20 13:24:33 +0300 |
commit | 4798464e8bbbcc3f92fbda82b1114c4824eaabf1 (patch) | |
tree | 67a96215cb77fad71caa9a16d8195b45e268c0c1 /source | |
parent | 299859e40b2f9652ded56863e293c104705dbfb7 (diff) |
Extended Mesh <-> BMesh copy function versions for specifying custom
data masks explicitly.
A dummy mesh is used for strand edit undo storage like in mesh edit
to prevent unnecessary code duplication. However, when copying from/to
BMesh only the mesh data layers are copied by default, omitting the new
data layers for strands (currently only MSurfaceSample hair root data).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_conv.c | 40 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_conv.h | 6 | ||||
-rw-r--r-- | source/blender/editors/hair/hair_undo.c | 4 |
5 files changed, 43 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index cabde860f66..85d1a2559bf 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -57,6 +57,7 @@ extern const CustomDataMask CD_MASK_EDITMESH; extern const CustomDataMask CD_MASK_DERIVEDMESH; extern const CustomDataMask CD_MASK_BMESH; extern const CustomDataMask CD_MASK_FACECORNERS; +extern const CustomDataMask CD_MASK_STRANDS; extern const CustomDataMask CD_MASK_EVERYTHING; /* for ORIGINDEX layer type, indicates no original index for this element */ diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 569af4acdfc..444163e4c32 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1369,6 +1369,12 @@ const CustomDataMask CD_MASK_BMESH = const CustomDataMask CD_MASK_FACECORNERS = /* XXX Not used anywhere! */ CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_NORMAL | CD_MASK_MLOOPTANGENT; +const CustomDataMask CD_MASK_STRANDS = + CD_MASK_MVERT | CD_MASK_MEDGE | + CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MCOL | + CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | + CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE | + CD_MASK_MSURFACE_SAMPLE; const CustomDataMask CD_MASK_EVERYTHING = CD_MASK_MVERT | CD_MASK_MSTICKY /* DEPRECATED */ | CD_MASK_MDEFORMVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_NORMAL /* | CD_MASK_POLYINDEX */ | CD_MASK_PROP_FLT | diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c index cb75d75e18c..98521137816 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.c +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c @@ -227,6 +227,17 @@ static BMFace *bm_face_create_from_mpoly(MPoly *mp, MLoop *ml, void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, const bool calc_face_normal, const bool set_key, int act_key_nr) { + BM_mesh_bm_from_me_ex(bm, me, CD_MASK_BMESH, calc_face_normal, set_key, act_key_nr); +} + +/** + * \brief Mesh -> BMesh + * + * \warning This function doesn't calculate face normals. + */ +void BM_mesh_bm_from_me_ex(BMesh *bm, Mesh *me, CustomDataMask mask, + const bool calc_face_normal, const bool set_key, int act_key_nr) +{ MVert *mvert; MEdge *medge; MLoop *mloop; @@ -252,10 +263,10 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, if (!me || !me->totvert) { if (me) { /*no verts? still copy customdata layout*/ - CustomData_copy(&me->vdata, &bm->vdata, CD_MASK_BMESH, CD_ASSIGN, 0); - CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_ASSIGN, 0); - CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_ASSIGN, 0); - CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_ASSIGN, 0); + CustomData_copy(&me->vdata, &bm->vdata, mask, CD_ASSIGN, 0); + CustomData_copy(&me->edata, &bm->edata, mask, CD_ASSIGN, 0); + CustomData_copy(&me->ldata, &bm->ldata, mask, CD_ASSIGN, 0); + CustomData_copy(&me->pdata, &bm->pdata, mask, CD_ASSIGN, 0); CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT); CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE); @@ -267,10 +278,10 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, vtable = MEM_mallocN(sizeof(void **) * me->totvert, "mesh to bmesh vtable"); - CustomData_copy(&me->vdata, &bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0); + CustomData_copy(&me->vdata, &bm->vdata, mask, CD_CALLOC, 0); + CustomData_copy(&me->edata, &bm->edata, mask, CD_CALLOC, 0); + CustomData_copy(&me->ldata, &bm->ldata, mask, CD_CALLOC, 0); + CustomData_copy(&me->pdata, &bm->pdata, mask, CD_CALLOC, 0); /* make sure uv layer names are consisten */ totuv = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY); @@ -571,6 +582,11 @@ BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e) void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface) { + BM_mesh_bm_to_me_ex(bm, me, CD_MASK_MESH, do_tessface); +} + +void BM_mesh_bm_to_me_ex(BMesh *bm, Mesh *me, CustomDataMask mask, bool do_tessface) +{ MLoop *mloop; MPoly *mpoly; MVert *mvert, *oldverts; @@ -630,10 +646,10 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface) me->totface = 0; me->act_face = -1; - CustomData_copy(&bm->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, me->totvert); - CustomData_copy(&bm->edata, &me->edata, CD_MASK_MESH, CD_CALLOC, me->totedge); - CustomData_copy(&bm->ldata, &me->ldata, CD_MASK_MESH, CD_CALLOC, me->totloop); - CustomData_copy(&bm->pdata, &me->pdata, CD_MASK_MESH, CD_CALLOC, me->totpoly); + CustomData_copy(&bm->vdata, &me->vdata, mask, CD_CALLOC, me->totvert); + CustomData_copy(&bm->edata, &me->edata, mask, CD_CALLOC, me->totedge); + CustomData_copy(&bm->ldata, &me->ldata, mask, CD_CALLOC, me->totloop); + CustomData_copy(&bm->pdata, &me->pdata, mask, CD_CALLOC, me->totpoly); CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert); CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge); diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.h b/source/blender/bmesh/intern/bmesh_mesh_conv.h index ab9d7a0ccf3..f910c696fb6 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_conv.h +++ b/source/blender/bmesh/intern/bmesh_mesh_conv.h @@ -32,7 +32,10 @@ * \ingroup bmesh */ +#include "BLI_sys_types.h" + struct Mesh; +typedef uint64_t CustomDataMask; void BM_mesh_cd_validate(BMesh *bm); void BM_mesh_cd_flag_ensure(BMesh *bm, struct Mesh *mesh, const char cd_flag); @@ -41,6 +44,9 @@ char BM_mesh_cd_flag_from_bmesh(BMesh *bm); void BM_mesh_bm_from_me(BMesh *bm, struct Mesh *me, const bool calc_face_normal, const bool set_key, int act_key_nr); +void BM_mesh_bm_from_me_ex(BMesh *bm, struct Mesh *me, CustomDataMask mask, + const bool calc_face_normal, const bool set_key, int act_key_nr); void BM_mesh_bm_to_me(BMesh *bm, struct Mesh *me, bool do_tessface); +void BM_mesh_bm_to_me_ex(BMesh *bm, struct Mesh *me, CustomDataMask mask, bool do_tessface); #endif /* __BMESH_MESH_CONV_H__ */ diff --git a/source/blender/editors/hair/hair_undo.c b/source/blender/editors/hair/hair_undo.c index 14597687088..c3096e56219 100644 --- a/source/blender/editors/hair/hair_undo.c +++ b/source/blender/editors/hair/hair_undo.c @@ -96,7 +96,7 @@ static void *strands_edit_to_undo(void *editv, void *UNUSED(obdata)) /* BM_mesh_validate(em->bm); */ /* for troubleshooting */ - BM_mesh_bm_to_me(edit->bm, &undo->me, false); + BM_mesh_bm_to_me_ex(edit->bm, &undo->me, CD_MASK_STRANDS, false); undo->selectmode = edit->bm->selectmode; undo->shapenr = edit->bm->shapenr; @@ -126,7 +126,7 @@ static void strands_undo_to_edit(void *undov, void *editv, void *UNUSED(obdata)) BKE_editstrands_free(edit); - BM_mesh_bm_from_me(bm, &undo->me, true, false, undo->shapenr); + BM_mesh_bm_from_me_ex(bm, &undo->me, CD_MASK_STRANDS, false, false, undo->shapenr); *edit = *edit_tmp; |