diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-12 21:44:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-12 21:44:10 +0400 |
commit | 9a92cd80087d5d8158c6af27d2ae3d2da4856ef0 (patch) | |
tree | 9f7ebaeac7d2529e05136411855867a14e10feea /source/blender/blenkernel | |
parent | 9099e59da86b26c9d360b59dd5c8de769dfa0c4f (diff) |
bmesh minor refactor
* add DM_to_bmesh_ex, DM_to_bmesh for converting a derived mesh to a BMesh (rather than a BMEditMesh)
* have a generic variable for allocsize: bm_mesh_allocsize_default, rather than copying the values about.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifiers_bmesh.c | 49 |
3 files changed, 38 insertions, 21 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index a8bb4d0fa65..8a5d7c06bee 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -441,7 +441,12 @@ int DM_release(DerivedMesh *dm); void DM_to_mesh(DerivedMesh *dm, struct Mesh *me, struct Object *ob); struct BMEditMesh *DM_to_editbmesh(struct Object *ob, struct DerivedMesh *dm, - struct BMEditMesh *existing, int do_tesselate); + struct BMEditMesh *existing, int do_tesselate); + +/* conversion to bmesh only */ +void DM_to_bmesh_ex(struct DerivedMesh *dm, struct BMesh *bm); +struct BMesh *DM_to_bmesh(struct Object *ob, struct DerivedMesh *dm); + /* utility function to convert a DerivedMesh to a shape key block */ diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index b907fd1cbae..4e0dc41e9a0 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -526,9 +526,8 @@ Mesh *copy_mesh(Mesh *me) BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob) { BMesh *bm; - int allocsize[4] = {512,512,2048,512}; - bm = BM_mesh_create(ob, allocsize); + bm = BM_mesh_create(ob, bm_mesh_allocsize_default); BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%i", me, ob, 1); diff --git a/source/blender/blenkernel/intern/modifiers_bmesh.c b/source/blender/blenkernel/intern/modifiers_bmesh.c index b3e0c298bbe..2fdf0e0bb70 100644 --- a/source/blender/blenkernel/intern/modifiers_bmesh.c +++ b/source/blender/blenkernel/intern/modifiers_bmesh.c @@ -22,12 +22,11 @@ * * ***** END GPL LICENSE BLOCK ***** * - * Modifier stack implementation. - * - * BKE_modifier.h contains the function prototypes for this file. - * */ +/** \file blender/blenkernel/intern/modifiers_bmesh.c + * \ingroup bke + */ #include "BLI_math.h" @@ -40,14 +39,9 @@ #include "BKE_bmesh.h" #include "BKE_tessmesh.h" - -/* converts a cddm to a BMEditMesh. if existing is non-NULL, the - * new geometry will be put in there.*/ -BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int do_tesselate) +/* main function for copying DerivedMesh data into BMesh */ +void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm) { - int allocsize[4] = {512, 512, 2048, 512}; - BMesh *bm, bmold; /*bmold is for storing old customdata layout*/ - BMEditMesh *em = existing; MVert *mv, *mvert; MEdge *me, *medge; MPoly *mpoly, *mp; @@ -59,11 +53,6 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i BLI_array_declare(verts); BLI_array_declare(edges); int i, j, k, totvert, totedge, totface; - - if (em) bm = em->bm; - else bm = BM_mesh_create(ob, allocsize); - - bmold = *bm; /*merge custom data layout*/ CustomData_bmesh_merge(&dm->vertData, &bm->vdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_VERT); @@ -101,7 +90,7 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i etable[i] = e; } MEM_freeN(medge); - + /*do faces*/ mpoly = mp = dm->getPolyArray(dm); mloop = dm->getLoopArray(dm); @@ -141,9 +130,22 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i MEM_freeN(vtable); MEM_freeN(etable); - + BLI_array_free(verts); BLI_array_free(edges); +} + +/* converts a cddm to a BMEditMesh. if existing is non-NULL, the + * new geometry will be put in there.*/ +BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, int do_tesselate) +{ + BMEditMesh *em = existing; + BMesh *bm; + + if (em) bm = em->bm; + else bm = BM_mesh_create(ob, bm_mesh_allocsize_default); + + DM_to_bmesh_ex(dm, bm); if (!em) { em = BMEdit_Create(bm, do_tesselate); @@ -156,3 +158,14 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i return em; } + +BMesh *DM_to_bmesh(Object *ob, DerivedMesh *dm) +{ + BMesh *bm; + + bm = BM_mesh_create(ob, bm_mesh_allocsize_default); + + DM_to_bmesh_ex(dm, bm); + + return bm; +} |