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.
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "BLI_smallhash.h"
|
||||
|
||||
@@ -43,7 +44,7 @@
|
||||
#define SMHASH_CELL_FREE ((void *)0x7FFFFFFD)
|
||||
|
||||
#define SMHASH_NONZERO(n) ((n) + !(n))
|
||||
#define SMHASH_NEXT(h, hoff) ABS(((h) + ((hoff=SMHASH_NONZERO(hoff*2)+1), hoff)))
|
||||
#define SMHASH_NEXT(h, hoff) ABS(((h) + ((hoff = SMHASH_NONZERO(hoff * 2) + 1), hoff)))
|
||||
|
||||
extern unsigned int hashsizes[];
|
||||
|
||||
@@ -60,7 +61,7 @@ void BLI_smallhash_init(SmallHash *hash)
|
||||
hash->copytable = hash->_copytable;
|
||||
hash->stacktable = hash->_stacktable;
|
||||
|
||||
for (i=0; i<hash->size; i++) {
|
||||
for (i = 0; i < hash->size; i++) {
|
||||
hash->table[i].val = SMHASH_CELL_FREE;
|
||||
}
|
||||
}
|
||||
@@ -98,11 +99,11 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
|
||||
|
||||
hash->size = newsize;
|
||||
|
||||
for (i=0; i<hash->size; i++) {
|
||||
for (i = 0; i < hash->size; i++) {
|
||||
hash->table[i].val = SMHASH_CELL_FREE;
|
||||
}
|
||||
|
||||
for (i=0; i<hashsizes[hash->curhash-1]; i++) {
|
||||
for (i = 0; i<hashsizes[hash->curhash - 1]; i++) {
|
||||
if (ELEM(tmp[i].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
|
||||
continue;
|
||||
}
|
||||
@@ -228,7 +229,7 @@ void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)
|
||||
|
||||
iter->i++;
|
||||
|
||||
return iter->hash->table[iter->i-1].val;
|
||||
return iter->hash->table[iter->i - 1].val;
|
||||
}
|
||||
|
||||
iter->i++;
|
||||
|
||||
@@ -112,9 +112,10 @@ struct EditMesh;
|
||||
void bmesh_error(void);
|
||||
|
||||
/* Mesh Level Ops */
|
||||
extern int bm_mesh_allocsize_default[4];
|
||||
|
||||
/* ob is needed by multires */
|
||||
BMesh *BM_mesh_create(struct Object *ob, int allocsize[4]);
|
||||
BMesh *BM_mesh_create(struct Object *ob, const int allocsize[4]);
|
||||
BMesh *BM_mesh_copy(BMesh *bmold);
|
||||
void BM_mesh_free(BMesh *bm);
|
||||
|
||||
|
||||
@@ -658,21 +658,20 @@ BMesh *BM_mesh_copy(BMesh *bmold)
|
||||
BMFace *f, *f2, **ftable = NULL;
|
||||
BMEditSelection *ese;
|
||||
BMIter iter, liter;
|
||||
int allocsize[4] = {512, 512, 2048, 512};
|
||||
int i, j;
|
||||
|
||||
/* allocate a bmesh */
|
||||
bm = BM_mesh_create(bmold->ob, allocsize);
|
||||
bm = BM_mesh_create(bmold->ob, bm_mesh_allocsize_default);
|
||||
|
||||
CustomData_copy(&bmold->vdata, &bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&bmold->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&bmold->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&bmold->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
|
||||
CustomData_bmesh_init_pool(&bm->vdata, allocsize[0]);
|
||||
CustomData_bmesh_init_pool(&bm->edata, allocsize[1]);
|
||||
CustomData_bmesh_init_pool(&bm->ldata, allocsize[2]);
|
||||
CustomData_bmesh_init_pool(&bm->pdata, allocsize[3]);
|
||||
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default[0]);
|
||||
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default[1]);
|
||||
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default[2]);
|
||||
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default[3]);
|
||||
|
||||
vtable = MEM_mallocN(sizeof(BMVert *) * bmold->totvert, "BM_mesh_copy vtable");
|
||||
etable = MEM_mallocN(sizeof(BMEdge *) * bmold->totedge, "BM_mesh_copy etable");
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
|
||||
#include "bmesh_private.h"
|
||||
|
||||
/* used as an extern, defined in bmesh.h */
|
||||
int bm_mesh_allocsize_default[4] = {512, 512, 2048, 512};
|
||||
|
||||
/* bmesh_error stub */
|
||||
void bmesh_error(void)
|
||||
{
|
||||
@@ -58,6 +61,18 @@ void bmesh_error(void)
|
||||
BLI_assert(0);
|
||||
}
|
||||
|
||||
static void bmesh_mempool_init(BMesh *bm, const int allocsize[4])
|
||||
{
|
||||
bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize[0], allocsize[0], FALSE, TRUE);
|
||||
bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize[1], allocsize[1], FALSE, TRUE);
|
||||
bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize[2], allocsize[2], FALSE, FALSE);
|
||||
bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), allocsize[3], allocsize[3], FALSE, FALSE);
|
||||
bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize[3], allocsize[3], FALSE, TRUE);
|
||||
|
||||
/* allocate one flag pool that we dont get rid of. */
|
||||
bm->toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), 512, 512, FALSE, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* BMESH MAKE MESH
|
||||
*
|
||||
@@ -67,29 +82,17 @@ void bmesh_error(void)
|
||||
*
|
||||
*/
|
||||
|
||||
BMesh *BM_mesh_create(struct Object *ob, int allocsize[4])
|
||||
BMesh *BM_mesh_create(struct Object *ob, const int allocsize[4])
|
||||
{
|
||||
/* allocate the structure */
|
||||
BMesh *bm = MEM_callocN(sizeof(BMesh), __func__);
|
||||
int vsize, esize, lsize, fsize, lstsize;
|
||||
|
||||
vsize = sizeof(BMVert);
|
||||
esize = sizeof(BMEdge);
|
||||
lsize = sizeof(BMLoop);
|
||||
fsize = sizeof(BMFace);
|
||||
lstsize = sizeof(BMLoopList);
|
||||
|
||||
bm->ob = ob;
|
||||
|
||||
/* allocate the memory pools for the mesh elements */
|
||||
bm->vpool = BLI_mempool_create(vsize, allocsize[0], allocsize[0], FALSE, TRUE);
|
||||
bm->epool = BLI_mempool_create(esize, allocsize[1], allocsize[1], FALSE, TRUE);
|
||||
bm->lpool = BLI_mempool_create(lsize, allocsize[2], allocsize[2], FALSE, FALSE);
|
||||
bm->looplistpool = BLI_mempool_create(lstsize, allocsize[3], allocsize[3], FALSE, FALSE);
|
||||
bm->fpool = BLI_mempool_create(fsize, allocsize[3], allocsize[3], FALSE, TRUE);
|
||||
bmesh_mempool_init(bm, allocsize);
|
||||
|
||||
/* allocate one flag pool that we dont get rid of. */
|
||||
bm->toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), 512, 512, FALSE, FALSE);
|
||||
bm->stackdepth = 1;
|
||||
bm->totflags = 1;
|
||||
|
||||
@@ -163,11 +166,6 @@ void BM_mesh_data_free(BMesh *bm)
|
||||
|
||||
void BM_mesh_clear(BMesh *bm)
|
||||
{
|
||||
/* allocate the structure */
|
||||
int vsize, esize, lsize, fsize, lstsize;
|
||||
/* I really need to make the allocation sizes defines, there's no reason why the API
|
||||
* should allow client code to mess around with this - joeedh */
|
||||
int allocsize[5] = {512, 512, 512, 2048, 512};
|
||||
Object *ob = bm->ob;
|
||||
|
||||
/* free old mesh */
|
||||
@@ -175,23 +173,11 @@ void BM_mesh_clear(BMesh *bm)
|
||||
memset(bm, 0, sizeof(BMesh));
|
||||
|
||||
/* re-initialize mesh */
|
||||
vsize = sizeof(BMVert);
|
||||
esize = sizeof(BMEdge);
|
||||
lsize = sizeof(BMLoop);
|
||||
fsize = sizeof(BMFace);
|
||||
lstsize = sizeof(BMLoopList);
|
||||
|
||||
bm->ob = ob;
|
||||
|
||||
/* allocate the memory pools for the mesh elements */
|
||||
bm->vpool = BLI_mempool_create(vsize, allocsize[0], allocsize[0], FALSE, TRUE);
|
||||
bm->epool = BLI_mempool_create(esize, allocsize[1], allocsize[1], FALSE, TRUE);
|
||||
bm->lpool = BLI_mempool_create(lsize, allocsize[2], allocsize[2], FALSE, FALSE);
|
||||
bm->looplistpool = BLI_mempool_create(lstsize, allocsize[3], allocsize[3], FALSE, FALSE);
|
||||
bm->fpool = BLI_mempool_create(fsize, allocsize[4], allocsize[4], FALSE, TRUE);
|
||||
bmesh_mempool_init(bm, bm_mesh_allocsize_default);
|
||||
|
||||
/* allocate one flag pool that we dont get rid of. */
|
||||
bm->toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), 512, 512, FALSE, FALSE);
|
||||
bm->stackdepth = 1;
|
||||
bm->totflags = 1;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op)
|
||||
float (*keyco)[3] = NULL;
|
||||
int *keyi;
|
||||
int set_key = BMO_slot_int_get(op, "set_shapekey");
|
||||
int totuv, i, j, allocsize[4] = {512, 512, 2048, 512};
|
||||
int totuv, i, j;
|
||||
|
||||
if (!me || !me->totvert) {
|
||||
return; /* sanity check */
|
||||
@@ -137,10 +137,10 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op)
|
||||
printf("shapekey<->mesh mismatch!\n");
|
||||
}
|
||||
|
||||
CustomData_bmesh_init_pool(&bm->vdata, allocsize[0]);
|
||||
CustomData_bmesh_init_pool(&bm->edata, allocsize[1]);
|
||||
CustomData_bmesh_init_pool(&bm->ldata, allocsize[2]);
|
||||
CustomData_bmesh_init_pool(&bm->pdata, allocsize[3]);
|
||||
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default[0]);
|
||||
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default[1]);
|
||||
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default[2]);
|
||||
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default[3]);
|
||||
|
||||
for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
|
||||
v = BM_vert_create(bm, keyco && set_key ? keyco[i] : mvert->co, NULL);
|
||||
|
||||
@@ -3198,21 +3198,20 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO
|
||||
Mesh *me = obedit->data;
|
||||
BMEditMesh *em = me->edit_btmesh;
|
||||
BMesh *bmnew;
|
||||
int allocsize[] = {512, 512, 2048, 512};
|
||||
|
||||
if (!em)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
bmnew = BM_mesh_create(obedit, allocsize);
|
||||
bmnew = BM_mesh_create(obedit, bm_mesh_allocsize_default);
|
||||
CustomData_copy(&em->bm->vdata, &bmnew->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&em->bm->edata, &bmnew->edata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&em->bm->ldata, &bmnew->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
CustomData_copy(&em->bm->pdata, &bmnew->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
||||
|
||||
CustomData_bmesh_init_pool(&bmnew->vdata, allocsize[0]);
|
||||
CustomData_bmesh_init_pool(&bmnew->edata, allocsize[1]);
|
||||
CustomData_bmesh_init_pool(&bmnew->ldata, allocsize[2]);
|
||||
CustomData_bmesh_init_pool(&bmnew->pdata, allocsize[3]);
|
||||
CustomData_bmesh_init_pool(&bmnew->vdata, bm_mesh_allocsize_default[0]);
|
||||
CustomData_bmesh_init_pool(&bmnew->edata, bm_mesh_allocsize_default[1]);
|
||||
CustomData_bmesh_init_pool(&bmnew->ldata, bm_mesh_allocsize_default[2]);
|
||||
CustomData_bmesh_init_pool(&bmnew->pdata, bm_mesh_allocsize_default[3]);
|
||||
|
||||
basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */
|
||||
assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */
|
||||
|
||||
@@ -560,14 +560,13 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata))
|
||||
Object *ob;
|
||||
undomesh *um = umv;
|
||||
BMesh *bm;
|
||||
int allocsize[4] = {512, 512, 2048, 512};
|
||||
|
||||
ob = (Object *)find_id("OB", um->obname);
|
||||
ob->shapenr = em->bm->shapenr;
|
||||
|
||||
BMEdit_Free(em);
|
||||
|
||||
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", &um->me, ob, 0);
|
||||
|
||||
em2 = BMEdit_Create(bm, TRUE);
|
||||
|
||||
@@ -116,7 +116,6 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob,
|
||||
BMIter iter;
|
||||
BMEdge *e;
|
||||
BevelModifierData *bmd = (BevelModifierData*) md;
|
||||
/* int allocsize[] = {512, 512, 2048, 512}; */ /* UNUSED */
|
||||
float threshold = cos((bmd->bevel_angle + 0.00001) * M_PI / 180.0);
|
||||
|
||||
em = DM_to_editbmesh(ob, dm, NULL, FALSE);
|
||||
|
||||
@@ -64,7 +64,6 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj
|
||||
BMEditMesh *em;
|
||||
BMIter iter;
|
||||
BMEdge *e;
|
||||
/* int allocsize[] = {512, 512, 2048, 512}; */ /* UNUSED */
|
||||
float threshold = cos((emd->split_angle + 0.00001) * M_PI / 180.0);
|
||||
|
||||
em = DM_to_editbmesh(ob, dm, NULL, FALSE);
|
||||
|
||||
Reference in New Issue
Block a user