move bmesh array lookup data and utility functions from editmesh into bmesh,

since enough bmesh operations can also take advantage of direct index lookups on verts/edges/faces.

developers note:
- EDBM_index_arrays_init/ensure/free -> BM_mesh_elem_table_ensure/init/free
- EDBM_vert/edge/face_at_index -> BM_vert/edge/face_at_index
- EDBM_uv_element_map_create/free -> BM_uv_element_map_create/free
- ED_uv_element_get -> BM_uv_element_get
This commit is contained in:
Campbell Barton 2013-10-28 02:05:33 +00:00
parent 0773fd7b78
commit 3264461598
28 changed files with 443 additions and 410 deletions

@ -71,13 +71,6 @@ typedef struct BMEditMesh {
unsigned char (*derivedFaceColor)[4];
int derivedFaceColorLen;
/* index tables, to map indices to elements via
* EDBM_index_arrays_init and associated functions. don't
* touch this or read it directly.*/
struct BMVert **vert_index;
struct BMEdge **edge_index;
struct BMFace **face_index;
/*selection mode*/
short selectmode;
short mat_nr;

@ -1233,7 +1233,8 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert)
return;
}
ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
bmvert_to_mvert(bm, ev, r_vert);
@ -1255,7 +1256,10 @@ static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
copy_v3_v3(r_co, bmdm->vertexCos[index]);
}
else {
BMVert *ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */
BMVert *ev;
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
copy_v3_v3(r_co, ev->co);
}
@ -1277,7 +1281,10 @@ static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
copy_v3_v3(r_no, bmdm->vertexNos[index]);
}
else {
BMVert *ev = bmdm->em->vert_index[index]; /* should be EDBM_vert_at_index() */
BMVert *ev;
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
copy_v3_v3(r_no, ev->no);
}
@ -1298,7 +1305,10 @@ static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3])
copy_v3_v3(r_no, bmdm->polyNos[index]);
}
else {
BMFace *efa = bmdm->em->face_index[index]; /* should be EDBM_vert_at_index() */
BMFace *efa;
BLI_assert((bm->elem_table_dirty & BM_FACE) == 0);
efa = bm->ftable[index]; /* should be BM_vert_at_index() */
// efa = BM_face_at_index(bm, index); /* warning, does list loop, _not_ ideal */
copy_v3_v3(r_no, efa->no);
}
@ -1316,7 +1326,8 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *r_edge)
return;
}
e = bmdm->em->edge_index[index]; /* should be EDBM_edge_at_index() */
BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0);
e = bm->etable[index]; /* should be BM_edge_at_index() */
// e = BM_edge_at_index(bm, index); /* warning, does list loop, _not_ ideal */
r_edge->flag = BM_edge_flag_to_mflag(e);

@ -78,10 +78,6 @@ BMEditMesh *BKE_editmesh_copy(BMEditMesh *em)
* used.*/
em_copy->looptris = NULL;
em_copy->vert_index = NULL;
em_copy->edge_index = NULL;
em_copy->face_index = NULL;
return em_copy;
}
@ -345,10 +341,6 @@ void BKE_editmesh_free(BMEditMesh *em)
if (em->looptris) MEM_freeN(em->looptris);
if (em->vert_index) MEM_freeN(em->vert_index);
if (em->edge_index) MEM_freeN(em->edge_index);
if (em->face_index) MEM_freeN(em->face_index);
if (em->bm)
BM_mesh_free(em->bm);
}

@ -946,7 +946,7 @@ bool BKE_mesh_center_centroid(Mesh *me, float cent[3])
* \{ */
/* ngon version wip, based on EDBM_uv_vert_map_create */
/* ngon version wip, based on BM_uv_vert_map_create */
/* this replaces the non bmesh function (in trunk) which takes MTFace's, if we ever need it back we could
* but for now this replaces it because its unused. */

@ -183,9 +183,28 @@ typedef struct BMesh {
* BM_LOOP isn't handled so far. */
char elem_index_dirty;
/* flag array table as being dirty so we know when its safe to use it,
* or when it needs to be re-created */
char elem_table_dirty;
/* element pools */
struct BLI_mempool *vpool, *epool, *lpool, *fpool;
/* mempool lookup tables (optional)
* index tables, to map indices to elements via
* BM_mesh_elem_table_ensure and associated functions. don't
* touch this or read it directly.\
* Use BM_mesh_elem_table_ensure(), BM_vert/edge/face_at_index() */
BMVert **vtable;
BMEdge **etable;
BMFace **ftable;
/* size of allocated tables */
int vtable_tot;
int etable_tot;
int ftable_tot;
/* operator api stuff (must be all NULL or all alloc'd) */
struct BLI_mempool *vtoolflagpool, *etoolflagpool, *ftoolflagpool;

@ -70,7 +70,9 @@ BMVert *BM_vert_create(BMesh *bm, const float co[3],
/* disallow this flag for verts - its meaningless */
BLI_assert((create_flag & BM_CREATE_NO_DOUBLE) == 0);
bm->elem_index_dirty |= BM_VERT; /* may add to middle of the pool */
/* may add to middle of the pool */
bm->elem_index_dirty |= BM_VERT;
bm->elem_table_dirty |= BM_VERT;
bm->totvert++;
@ -130,7 +132,9 @@ BMEdge *BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2,
BM_elem_index_set(e, -1); /* set_ok_invalid */
#endif
bm->elem_index_dirty |= BM_EDGE; /* may add to middle of the pool */
/* may add to middle of the pool */
bm->elem_index_dirty |= BM_EDGE;
bm->elem_table_dirty |= BM_EDGE;
bm->totedge++;
@ -292,7 +296,9 @@ BLI_INLINE BMFace *bm_face_create__internal(BMesh *bm, const eBMCreateFlag creat
BM_elem_index_set(f, -1); /* set_ok_invalid */
#endif
bm->elem_index_dirty |= BM_FACE; /* may add to middle of the pool */
/* may add to middle of the pool */
bm->elem_index_dirty |= BM_FACE;
bm->elem_table_dirty |= BM_FACE;
bm->totface++;
@ -562,6 +568,7 @@ static void bm_kill_only_vert(BMesh *bm, BMVert *v)
{
bm->totvert--;
bm->elem_index_dirty |= BM_VERT;
bm->elem_table_dirty |= BM_VERT;
BM_select_history_remove(bm, v);
@ -582,6 +589,7 @@ static void bm_kill_only_edge(BMesh *bm, BMEdge *e)
{
bm->totedge--;
bm->elem_index_dirty |= BM_EDGE;
bm->elem_table_dirty |= BM_EDGE;
BM_select_history_remove(bm, (BMElem *)e);
@ -605,6 +613,7 @@ static void bm_kill_only_face(BMesh *bm, BMFace *f)
bm->totface--;
bm->elem_index_dirty |= BM_FACE;
bm->elem_table_dirty |= BM_FACE;
BM_select_history_remove(bm, (BMElem *)f);

@ -213,6 +213,10 @@ void BM_mesh_data_free(BMesh *bm)
BLI_mempool_destroy(bm->lpool);
BLI_mempool_destroy(bm->fpool);
if (bm->vtable) MEM_freeN(bm->vtable);
if (bm->etable) MEM_freeN(bm->etable);
if (bm->ftable) MEM_freeN(bm->ftable);
/* destroy flag pool */
BM_mesh_elem_toolflags_clear(bm);
@ -623,6 +627,179 @@ void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *fu
}
/* debug check only - no need to optimize */
#ifndef NDEBUG
bool BM_mesh_elem_table_check(BMesh *bm)
{
BMIter iter;
BMElem *ele;
int i;
if (bm->vtable && ((bm->elem_table_dirty & BM_VERT) == 0)) {
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) {
if (ele != (BMElem *)bm->vtable[i]) {
return false;
}
}
}
if (bm->etable && ((bm->elem_table_dirty & BM_EDGE) == 0)) {
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
if (ele != (BMElem *)bm->etable[i]) {
return false;
}
}
}
if (bm->ftable && ((bm->elem_table_dirty & BM_FACE) == 0)) {
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
if (ele != (BMElem *)bm->ftable[i]) {
return false;
}
}
}
return true;
}
#endif
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
{
/* assume if the array is non-null then its valid and no need to recalc */
const char htype_needed = (((bm->vtable && ((bm->elem_table_dirty & BM_VERT) == 0)) ? 0 : BM_VERT) |
((bm->etable && ((bm->elem_table_dirty & BM_EDGE) == 0)) ? 0 : BM_EDGE) |
((bm->ftable && ((bm->elem_table_dirty & BM_FACE) == 0)) ? 0 : BM_FACE)) & htype;
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
/* in debug mode double check we didn't need to recalculate */
BLI_assert(BM_mesh_elem_table_check(bm) == true);
if (htype_needed & BM_VERT) {
if (bm->vtable && bm->totvert <= bm->vtable_tot && bm->totvert * 2 >= bm->vtable_tot) {
/* pass (re-use the array) */
}
else {
if (bm->vtable)
MEM_freeN(bm->vtable);
bm->vtable = MEM_mallocN(sizeof(void **) * bm->totvert, "bm->vtable");
bm->vtable_tot = bm->totvert;
}
bm->elem_table_dirty &= ~BM_VERT;
}
if (htype_needed & BM_EDGE) {
if (bm->etable && bm->totedge <= bm->etable_tot && bm->totedge * 2 >= bm->etable_tot) {
/* pass (re-use the array) */
}
else {
if (bm->etable)
MEM_freeN(bm->etable);
bm->etable = MEM_mallocN(sizeof(void **) * bm->totedge, "bm->etable");
bm->etable_tot = bm->totedge;
}
bm->elem_table_dirty &= ~BM_EDGE;
}
if (htype_needed & BM_FACE) {
if (bm->ftable && bm->totface <= bm->ftable_tot && bm->totface * 2 >= bm->ftable_tot) {
/* pass (re-use the array) */
}
else {
if (bm->ftable)
MEM_freeN(bm->ftable);
bm->ftable = MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable");
bm->ftable_tot = bm->totface;
}
bm->elem_table_dirty &= ~BM_FACE;
}
#pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
{
#pragma omp section
{
if (htype_needed & BM_VERT) {
BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)bm->vtable, bm->totvert);
}
}
#pragma omp section
{
if (htype_needed & BM_EDGE) {
BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)bm->etable, bm->totedge);
}
}
#pragma omp section
{
if (htype_needed & BM_FACE) {
BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)bm->ftable, bm->totface);
}
}
}
}
/* use BM_mesh_elem_table_ensure where possible to avoid full rebuild */
void BM_mesh_elem_table_init(BMesh *bm, const char htype)
{
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
/* force recalc */
BM_mesh_elem_table_free(bm, BM_ALL_NOLOOP);
BM_mesh_elem_table_ensure(bm, htype);
}
void BM_mesh_elem_table_free(BMesh *bm, const char htype)
{
if (htype & BM_VERT) {
MEM_SAFE_FREE(bm->vtable);
}
if (htype & BM_EDGE) {
MEM_SAFE_FREE(bm->etable);
}
if (htype & BM_FACE) {
MEM_SAFE_FREE(bm->ftable);
}
}
BMVert *BM_vert_at_index(BMesh *bm, int index)
{
BLI_assert((index >= 0) && (index < bm->totvert));
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
return bm->vtable[index];
}
BMEdge *BM_edge_at_index(BMesh *bm, int index)
{
BLI_assert((index >= 0) && (index < bm->totedge));
BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0);
return bm->etable[index];
}
BMFace *BM_face_at_index(BMesh *bm, int index)
{
BLI_assert((index >= 0) && (index < bm->totface));
BLI_assert((bm->elem_table_dirty & BM_FACE) == 0);
return bm->ftable[index];
}
BMVert *BM_vert_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->vpool, index);
}
BMEdge *BM_edge_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->epool, index);
}
BMFace *BM_face_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->fpool, index);
}
/**
* Return the amount of element of type 'type' in a given bmesh.
*/
@ -828,18 +1005,3 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx)
if (fptr_map)
BLI_ghash_free(fptr_map, NULL, NULL);
}
BMVert *BM_vert_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->vpool, index);
}
BMEdge *BM_edge_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->epool, index);
}
BMFace *BM_face_at_index_find(BMesh *bm, const int index)
{
return BLI_mempool_findelem(bm->fpool, index);
}

@ -45,14 +45,29 @@ void bmesh_edit_end(BMesh *bm, const BMOpTypeFlag type_flag);
void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag);
void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *func,
const char *msg_a, const char *msg_b);
int BM_mesh_elem_count(BMesh *bm, const char htype);
void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx);
#ifndef NDEBUG
bool BM_mesh_elem_table_check(BMesh *em);
#endif
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype);
void BM_mesh_elem_table_init(BMesh *bm, const char htype);
void BM_mesh_elem_table_free(BMesh *bm, const char htype);
BMVert *BM_vert_at_index(BMesh *bm, const int index);
BMEdge *BM_edge_at_index(BMesh *bm, const int index);
BMFace *BM_face_at_index(BMesh *bm, const int index);
BMVert *BM_vert_at_index_find(BMesh *bm, const int index);
BMEdge *BM_edge_at_index_find(BMesh *bm, const int index);
BMFace *BM_face_at_index_find(BMesh *bm, const int index);
// XXX
int BM_mesh_elem_count(BMesh *bm, const char htype);
void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx);
typedef struct BMAllocTemplate {
int totvert, totedge, totloop, totface;
} BMAllocTemplate;

@ -97,16 +97,6 @@ void EDBM_mesh_free(struct BMEditMesh *em);
void EDBM_mesh_load(struct Object *ob);
struct DerivedMesh *EDBM_mesh_deform_dm_get(struct BMEditMesh *em);
void EDBM_index_arrays_ensure(struct BMEditMesh *em, const char htype);
void EDBM_index_arrays_init(struct BMEditMesh *em, const char htype);
void EDBM_index_arrays_free(struct BMEditMesh *em);
#ifndef NDEBUG
bool EDBM_index_arrays_check(struct BMEditMesh *em);
#endif
struct BMVert *EDBM_vert_at_index(struct BMEditMesh *em, int index);
struct BMEdge *EDBM_edge_at_index(struct BMEditMesh *em, int index);
struct BMFace *EDBM_face_at_index(struct BMEditMesh *em, int index);
/* flushes based on the current select mode. if in vertex select mode,
* verts select/deselect edges and faces, if in edge select mode,
* edges select/deselect faces and vertices, and in face select mode faces select/deselect
@ -129,16 +119,16 @@ void EDBM_mesh_reveal(struct BMEditMesh *em);
void EDBM_update_generic(struct BMEditMesh *em, const bool do_tessface, const bool is_destructive);
struct UvElementMap *EDBM_uv_element_map_create(struct BMEditMesh *em, const bool selected, const bool do_islands);
void EDBM_uv_element_map_free(struct UvElementMap *vmap);
struct UvElement *ED_uv_element_get(struct UvElementMap *map, struct BMFace *efa, struct BMLoop *l);
struct UvElementMap *BM_uv_element_map_create(struct BMesh *em, const bool selected, const bool do_islands);
void BM_uv_element_map_free(struct UvElementMap *vmap);
struct UvElement *BM_uv_element_get(struct UvElementMap *map, struct BMFace *efa, struct BMLoop *l);
bool EDBM_mtexpoly_check(struct BMEditMesh *em);
struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, const bool sloppy, const bool selected);
void EDBM_uv_vert_map_free(struct UvVertMap *vmap);
struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
struct UvVertMap *EDBM_uv_vert_map_create(struct BMEditMesh *em, bool use_select, const float limit[2]);
void BM_uv_vert_map_free(struct UvVertMap *vmap);
struct UvMapVert *BM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
struct UvVertMap *BM_uv_vert_map_create(struct BMesh *bm, bool use_select, const float limit[2]);
void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag);
void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);

@ -797,7 +797,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to
if (em) {
if (skip_em_vert_array_init == false) {
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
}
}
@ -822,8 +822,8 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to
if ((a == totvert) || (topo_pairs[a - 1].hash != topo_pairs[a].hash)) {
if (a - last == 2) {
if (em) {
index_lookup[topo_pairs[a - 1].v_index] = (intptr_t)EDBM_vert_at_index(em, topo_pairs[a - 2].v_index);
index_lookup[topo_pairs[a - 2].v_index] = (intptr_t)EDBM_vert_at_index(em, topo_pairs[a - 1].v_index);
index_lookup[topo_pairs[a - 1].v_index] = (intptr_t)BM_vert_at_index(em->bm, topo_pairs[a - 2].v_index);
index_lookup[topo_pairs[a - 2].v_index] = (intptr_t)BM_vert_at_index(em->bm, topo_pairs[a - 1].v_index);
}
else {
index_lookup[topo_pairs[a - 1].v_index] = topo_pairs[a - 2].v_index;

@ -219,7 +219,7 @@ static void edgering_sel(RingSelOpData *lcd, int previewlines, bool select)
}
if (dm) {
EDBM_index_arrays_ensure(lcd->em, BM_VERT);
BM_mesh_elem_table_ensure(lcd->em->bm, BM_VERT);
}
BMW_init(&walker, em->bm, BMW_EDGERING,
@ -478,8 +478,8 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
else {
const int e_index = RNA_int_get(op->ptr, "edge_index");
BMEdge *e;
EDBM_index_arrays_ensure(lcd->em, BM_EDGE);
e = EDBM_edge_at_index(lcd->em, e_index);
BM_mesh_elem_table_ensure(lcd->em->bm, BM_EDGE);
e = BM_edge_at_index(lcd->em->bm, e_index);
loopcut_update_edge(lcd, e, 0);
}

@ -4712,7 +4712,7 @@ static int mesh_symmetry_snap_exec(bContext *C, wmOperator *op)
EDBM_verts_mirror_cache_begin_ex(em, axis, true, true, use_topology, thresh, index);
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(bm, BM_VERT);
BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false);
@ -4724,7 +4724,7 @@ static int mesh_symmetry_snap_exec(bContext *C, wmOperator *op)
int i_mirr = index[i];
if (i_mirr != -1) {
BMVert *v_mirr = EDBM_vert_at_index(em, index[i]);
BMVert *v_mirr = BM_vert_at_index(bm, index[i]);
if (v != v_mirr) {
float co[3], co_mirr[3];

@ -410,134 +410,6 @@ void EDBM_mesh_free(BMEditMesh *em)
BKE_editmesh_free(em);
}
void EDBM_index_arrays_ensure(BMEditMesh *em, const char htype)
{
/* assume if the array is non-null then its valid and no need to recalc */
const char htype_needed = ((em->vert_index ? 0 : BM_VERT) |
(em->edge_index ? 0 : BM_EDGE) |
(em->face_index ? 0 : BM_FACE)) & htype;
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
/* in debug mode double check we didn't need to recalculate */
BLI_assert(EDBM_index_arrays_check(em) == true);
if (htype_needed & BM_VERT) {
em->vert_index = MEM_mallocN(sizeof(void **) * em->bm->totvert, "em->vert_index");
}
if (htype_needed & BM_EDGE) {
em->edge_index = MEM_mallocN(sizeof(void **) * em->bm->totedge, "em->edge_index");
}
if (htype_needed & BM_FACE) {
em->face_index = MEM_mallocN(sizeof(void **) * em->bm->totface, "em->face_index");
}
#pragma omp parallel sections if (em->bm->totvert + em->bm->totedge + em->bm->totface >= BM_OMP_LIMIT)
{
#pragma omp section
{
if (htype_needed & BM_VERT) {
BM_iter_as_array(em->bm, BM_VERTS_OF_MESH, NULL, (void **)em->vert_index, em->bm->totvert);
}
}
#pragma omp section
{
if (htype_needed & BM_EDGE) {
BM_iter_as_array(em->bm, BM_EDGES_OF_MESH, NULL, (void **)em->edge_index, em->bm->totedge);
}
}
#pragma omp section
{
if (htype_needed & BM_FACE) {
BM_iter_as_array(em->bm, BM_FACES_OF_MESH, NULL, (void **)em->face_index, em->bm->totface);
}
}
}
}
/* use EDBM_index_arrays_ensure where possible to avoid full rebuild */
void EDBM_index_arrays_init(BMEditMesh *em, const char htype)
{
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
/* force recalc */
EDBM_index_arrays_free(em);
EDBM_index_arrays_ensure(em, htype);
}
void EDBM_index_arrays_free(BMEditMesh *em)
{
if (em->vert_index) {
MEM_freeN(em->vert_index);
em->vert_index = NULL;
}
if (em->edge_index) {
MEM_freeN(em->edge_index);
em->edge_index = NULL;
}
if (em->face_index) {
MEM_freeN(em->face_index);
em->face_index = NULL;
}
}
/* debug check only - no need to optimize */
#ifndef NDEBUG
bool EDBM_index_arrays_check(BMEditMesh *em)
{
BMIter iter;
BMElem *ele;
int i;
if (em->vert_index) {
BM_ITER_MESH_INDEX (ele, &iter, em->bm, BM_VERTS_OF_MESH, i) {
if (ele != (BMElem *)em->vert_index[i]) {
return false;
}
}
}
if (em->edge_index) {
BM_ITER_MESH_INDEX (ele, &iter, em->bm, BM_EDGES_OF_MESH, i) {
if (ele != (BMElem *)em->edge_index[i]) {
return false;
}
}
}
if (em->face_index) {
BM_ITER_MESH_INDEX (ele, &iter, em->bm, BM_FACES_OF_MESH, i) {
if (ele != (BMElem *)em->face_index[i]) {
return false;
}
}
}
return true;
}
#endif
BMVert *EDBM_vert_at_index(BMEditMesh *em, int index)
{
BLI_assert((index >= 0) && (index < em->bm->totvert));
return em->vert_index[index];
}
BMEdge *EDBM_edge_at_index(BMEditMesh *em, int index)
{
BLI_assert((index >= 0) && (index < em->bm->totedge));
return em->edge_index[index];
}
BMFace *EDBM_face_at_index(BMEditMesh *em, int index)
{
BLI_assert((index >= 0) && (index < em->bm->totface));
return em->face_index[index];
}
void EDBM_selectmode_flush_ex(BMEditMesh *em, const short selectmode)
{
BM_mesh_select_mode_flush_ex(em->bm, selectmode);
@ -710,7 +582,7 @@ void undo_push_mesh(bContext *C, const char *name)
/**
* Return a new UVVertMap from the editmesh
*/
UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float limit[2])
UvVertMap *BM_uv_vert_map_create(BMesh *bm, bool use_select, const float limit[2])
{
BMVert *ev;
BMFace *efa;
@ -723,15 +595,15 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
MLoopUV *luv;
unsigned int a;
int totverts, i, totuv;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
totverts = em->bm->totvert;
totverts = bm->totvert;
totuv = 0;
/* generate UvMapVert array */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if ((use_select == false) || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
totuv += efa->len;
}
@ -754,7 +626,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
}
a = 0;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if ((use_select == false) || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
i = 0;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@ -775,7 +647,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
/* sort individual uvs for each vert */
a = 0;
BM_ITER_MESH (ev, &iter, em->bm, BM_VERTS_OF_MESH) {
BM_ITER_MESH (ev, &iter, bm, BM_VERTS_OF_MESH) {
UvMapVert *newvlist = NULL, *vlist = vmap->vert[a];
UvMapVert *iterv, *v, *lastv, *next;
float *uv, *uv2, uvdiff[2];
@ -786,10 +658,10 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
v->next = newvlist;
newvlist = v;
efa = EDBM_face_at_index(em, v->f);
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
efa = BM_face_at_index(bm, v->f);
/* tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
l = BM_iter_at_index(bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
uv = luv->uv;
@ -798,10 +670,10 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
while (iterv) {
next = iterv->next;
efa = EDBM_face_at_index(em, iterv->f);
/* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
efa = BM_face_at_index(bm, iterv->f);
/* tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
l = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
l = BM_iter_at_index(bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
uv2 = luv->uv;
@ -831,7 +703,7 @@ UvVertMap *EDBM_uv_vert_map_create(BMEditMesh *em, bool use_select, const float
}
UvMapVert *EDBM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v)
UvMapVert *BM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v)
{
return vmap->vert[v];
}
@ -840,7 +712,7 @@ UvMapVert *EDBM_uv_vert_map_at_index(UvVertMap *vmap, unsigned int v)
/* A specialized vert map used by stitch operator */
UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, const bool do_islands)
UvElementMap *BM_uv_element_map_create(BMesh *bm, const bool selected, const bool do_islands)
{
BMVert *ev;
BMFace *efa;
@ -860,20 +732,20 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
BMFace **stack;
int stacksize = 0;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_FACE);
totverts = em->bm->totvert;
totverts = bm->totvert;
totuv = 0;
island_number = MEM_mallocN(sizeof(*stack) * em->bm->totface, "uv_island_number_face");
island_number = MEM_mallocN(sizeof(*stack) * bm->totface, "uv_island_number_face");
if (!island_number) {
return NULL;
}
/* generate UvElement array */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
totuv += efa->len;
}
@ -893,13 +765,13 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
buf = element_map->buf = (UvElement *)MEM_callocN(sizeof(*element_map->buf) * totuv, "UvElement");
if (!element_map->vert || !element_map->buf) {
EDBM_uv_element_map_free(element_map);
BM_uv_element_map_free(element_map);
MEM_freeN(island_number);
return NULL;
}
j = 0;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
island_number[j++] = INVALID_ISLAND;
if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
@ -918,7 +790,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
/* sort individual uvs for each vert */
i = 0;
BM_ITER_MESH (ev, &iter, em->bm, BM_VERTS_OF_MESH) {
BM_ITER_MESH (ev, &iter, bm, BM_VERTS_OF_MESH) {
UvElement *newvlist = NULL, *vlist = element_map->vert[i];
UvElement *iterv, *v, *lastv, *next;
float *uv, *uv2, uvdiff[2];
@ -968,7 +840,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
if (do_islands) {
/* map holds the map from current vmap->buf to the new, sorted map */
map = MEM_mallocN(sizeof(*map) * totuv, "uvelement_remap");
stack = MEM_mallocN(sizeof(*stack) * em->bm->totface, "uv_island_face_stack");
stack = MEM_mallocN(sizeof(*stack) * bm->totface, "uv_island_face_stack");
islandbuf = MEM_callocN(sizeof(*islandbuf) * totuv, "uvelement_island_buffer");
/* at this point, every UvElement in vert points to a UvElement sharing the same vertex. Now we should sort uv's in islands. */
@ -1019,7 +891,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
}
/* remap */
for (i = 0; i < em->bm->totvert; i++) {
for (i = 0; i < bm->totvert; i++) {
/* important since we may do selection only. Some of these may be NULL */
if (element_map->vert[i])
element_map->vert[i] = &islandbuf[map[element_map->vert[i] - element_map->buf]];
@ -1030,7 +902,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
MEM_freeN(islandbuf);
MEM_freeN(stack);
MEM_freeN(map);
EDBM_uv_element_map_free(element_map);
BM_uv_element_map_free(element_map);
MEM_freeN(island_number);
}
@ -1060,7 +932,7 @@ UvElementMap *EDBM_uv_element_map_create(BMEditMesh *em, const bool selected, co
return element_map;
}
void EDBM_uv_vert_map_free(UvVertMap *vmap)
void BM_uv_vert_map_free(UvVertMap *vmap)
{
if (vmap) {
if (vmap->vert) MEM_freeN(vmap->vert);
@ -1069,7 +941,7 @@ void EDBM_uv_vert_map_free(UvVertMap *vmap)
}
}
void EDBM_uv_element_map_free(UvElementMap *element_map)
void BM_uv_element_map_free(UvElementMap *element_map)
{
if (element_map) {
if (element_map->vert) MEM_freeN(element_map->vert);
@ -1079,7 +951,7 @@ void EDBM_uv_element_map_free(UvElementMap *element_map)
}
}
UvElement *ED_uv_element_get(UvElementMap *map, BMFace *efa, BMLoop *l)
UvElement *BM_uv_element_get(UvElementMap *map, BMFace *efa, BMLoop *l)
{
UvElement *element;
@ -1182,7 +1054,7 @@ void EDBM_verts_mirror_cache_begin_ex(BMEditMesh *em, const int axis, const bool
struct BMBVHTree *tree = NULL;
MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1};
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(bm, BM_VERT);
if (r_index == NULL) {
const char *layer_id = BM_CD_LAYER_ID;
@ -1270,13 +1142,13 @@ BMVert *EDBM_verts_mirror_get(BMEditMesh *em, BMVert *v)
BLI_assert(em->mirror_cdlayer != -1); /* invalid use */
if (mirr && *mirr >= 0 && *mirr < em->bm->totvert) {
if (!em->vert_index) {
if (!em->bm->vtable) {
printf("err: should only be called between "
"EDBM_verts_mirror_cache_begin and EDBM_verts_mirror_cache_end");
return NULL;
}
return em->vert_index[*mirr];
return em->bm->vtable[*mirr];
}
return NULL;
@ -1335,7 +1207,7 @@ void EDBM_verts_mirror_apply(BMEditMesh *em, const int sel_from, const int sel_t
BMIter iter;
BMVert *v;
BLI_assert(em->vert_index != NULL);
BLI_assert((em->bm->vtable != NULL) && ((em->bm->elem_table_dirty & BM_VERT) == 0));
BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(v, BM_ELEM_SELECT) == sel_from) {
@ -1447,11 +1319,12 @@ void EDBM_update_generic(BMEditMesh *em, const bool do_tessface, const bool is_d
}
if (is_destructive) {
EDBM_index_arrays_free(em);
/* TODO. we may be able to remove this now! - Campbell */
// BM_mesh_elem_table_free(em->bm, BM_ALL_NOLOOP);
}
else {
/* in debug mode double check we didn't need to recalculate */
BLI_assert(EDBM_index_arrays_check(em) == true);
BLI_assert(BM_mesh_elem_table_check(em->bm) == true);
}
}

@ -389,7 +389,7 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
}
/* need to rebuild entirely because array size changes */
EDBM_index_arrays_init(em, BM_VERT);
BM_mesh_elem_table_init(em->bm, BM_VERT);
/* create faces */
for (j = 0; j < trinum; j++) {
@ -404,9 +404,9 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
face[k] = uniquevbase + tri[k] - nv; /* unique vertex */
}
newFace = BM_face_create_quad_tri(em->bm,
EDBM_vert_at_index(em, face[0]),
EDBM_vert_at_index(em, face[2]),
EDBM_vert_at_index(em, face[1]), NULL,
BM_vert_at_index(em->bm, face[0]),
BM_vert_at_index(em->bm, face[2]),
BM_vert_at_index(em->bm, face[1]), NULL,
NULL, false);
/* set navigation polygon idx to the custom layer */

@ -1014,7 +1014,7 @@ BMVert *editbmesh_get_x_mirror_vert(Object *ob, struct BMEditMesh *em, BMVert *e
/**
* Wrapper for objectmode/editmode.
*
* call #EDBM_index_arrays_ensure first for editmesh.
* call #BM_mesh_elem_table_ensure first for editmesh.
*/
int ED_mesh_mirror_get_vert(Object *ob, int index)
{
@ -1025,7 +1025,7 @@ int ED_mesh_mirror_get_vert(Object *ob, int index)
if (em) {
BMVert *eve, *eve_mirr;
eve = EDBM_vert_at_index(em, index);
eve = BM_vert_at_index(em->bm, index);
eve_mirr = editbmesh_get_x_mirror_vert(ob, em, eve, eve->co, index, use_topology);
index_mirr = eve_mirr ? BM_elem_index_get(eve_mirr) : -1;
}

@ -348,7 +348,7 @@ void ED_vgroup_parray_mirror_sync(Object *ob,
return;
}
if (em) {
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
}
for (i = 0; i < dvert_tot; i++) {
@ -390,7 +390,7 @@ void ED_vgroup_parray_mirror_assign(Object *ob,
}
BLI_assert(dvert_tot == dvert_tot_all);
if (em) {
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
}
for (i = 0; i < dvert_tot; i++) {
@ -1283,8 +1283,8 @@ static float get_vert_def_nr(Object *ob, const int def_nr, const int vertnum)
if (cd_dvert_offset != -1) {
BMVert *eve;
EDBM_index_arrays_ensure(em, BM_VERT);
eve = EDBM_vert_at_index(em, vertnum);
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
eve = BM_vert_at_index(em->bm, vertnum);
dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
}
else {
@ -2179,7 +2179,7 @@ static void vgroup_blend_subset(Object *ob, const bool *vgroup_validmap, const i
memset(vgroup_subset_weights, 0, sizeof(*vgroup_subset_weights) * subset_count);
if (bm) {
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(bm, BM_VERT);
emap = NULL;
emap_mem = NULL;
@ -2197,7 +2197,7 @@ static void vgroup_blend_subset(Object *ob, const bool *vgroup_validmap, const i
/* in case its not selected */
if (bm) {
BMVert *v = EDBM_vert_at_index(em, i);
BMVert *v = BM_vert_at_index(bm, i);
if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
BMIter eiter;
BMEdge *e;

@ -480,7 +480,7 @@ static void uv_sculpt_stroke_exit(bContext *C, wmOperator *op)
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), data->timer);
}
if (data->elementMap) {
EDBM_uv_element_map_free(data->elementMap);
BM_uv_element_map_free(data->elementMap);
}
if (data->uv) {
MEM_freeN(data->uv);
@ -501,7 +501,7 @@ static void uv_sculpt_stroke_exit(bContext *C, wmOperator *op)
static int uv_element_offset_from_face_get(UvElementMap *map, BMFace *efa, BMLoop *l, int island_index, int doIslands)
{
UvElement *element = ED_uv_element_get(map, efa, l);
UvElement *element = BM_uv_element_get(map, efa, l);
if (!element || (doIslands && element->island != island_index)) {
return -1;
}
@ -566,18 +566,18 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
if (do_island_optimization) {
/* We will need island information */
if (ts->uv_flag & UV_SYNC_SELECTION) {
data->elementMap = EDBM_uv_element_map_create(em, 0, 1);
data->elementMap = BM_uv_element_map_create(bm, false, true);
}
else {
data->elementMap = EDBM_uv_element_map_create(em, 1, 1);
data->elementMap = BM_uv_element_map_create(bm, true, true);
}
}
else {
if (ts->uv_flag & UV_SYNC_SELECTION) {
data->elementMap = EDBM_uv_element_map_create(em, 0, 0);
data->elementMap = BM_uv_element_map_create(bm, false, false);
}
else {
data->elementMap = EDBM_uv_element_map_create(em, 1, 0);
data->elementMap = BM_uv_element_map_create(bm, true, false);
}
}
@ -596,7 +596,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
Image *ima = CTX_data_edit_image(C);
uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
element = ED_uv_element_get(data->elementMap, hit.efa, hit.l);
element = BM_uv_element_get(data->elementMap, hit.efa, hit.l);
island_index = element->island;
}

@ -574,7 +574,7 @@ static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int index)
if (UNLIKELY(index >= em->bm->totface))
return DM_DRAW_OPTION_NORMAL;
efa = EDBM_face_at_index(em, index);
efa = BM_face_at_index(em->bm, index);
if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
return DM_DRAW_OPTION_SKIP;
@ -936,7 +936,7 @@ static bool tex_mat_set_face_editmesh_cb(void *userData, int index)
if (UNLIKELY(index >= em->bm->totface))
return DM_DRAW_OPTION_NORMAL;
efa = EDBM_face_at_index(em, index);
efa = BM_face_at_index(em->bm, index);
return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
}

@ -103,7 +103,7 @@ typedef enum eWireDrawMode {
} eWireDrawMode;
typedef struct drawDMVerts_userData {
BMEditMesh *em;
BMesh *bm;
BMVert *eve_act;
char sel;
@ -121,7 +121,7 @@ typedef struct drawDMVerts_userData {
} drawDMVerts_userData;
typedef struct drawDMEdgesSel_userData {
BMEditMesh *em;
BMesh *bm;
unsigned char *baseCol, *selCol, *actCol;
BMEdge *eed_act;
@ -135,7 +135,7 @@ typedef struct drawDMFacesSel_userData {
#endif
DerivedMesh *dm;
BMEditMesh *em;
BMesh *bm;
BMFace *efa_act;
int *orig_index_mf_to_mpoly;
@ -143,7 +143,7 @@ typedef struct drawDMFacesSel_userData {
} drawDMFacesSel_userData;
typedef struct drawDMNormal_userData {
BMEditMesh *em;
BMesh *bm;
int uniform_scale;
float normalsize;
float tmat[3][3];
@ -156,7 +156,7 @@ typedef struct bbsObmodeMeshVerts_userData {
} bbsObmodeMeshVerts_userData;
typedef struct drawDMLayer_userData {
BMEditMesh *em;
BMesh *bm;
int cd_layer_offset;
} drawDMLayer_userData;
@ -2038,7 +2038,7 @@ static void calcDrawDMNormalScale(Object *ob, drawDMNormal_userData *data)
static void draw_dm_face_normals__mapFunc(void *userData, int index, const float cent[3], const float no[3])
{
drawDMNormal_userData *data = userData;
BMFace *efa = EDBM_face_at_index(data->em, index);
BMFace *efa = BM_face_at_index(data->bm, index);
float n[3];
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
@ -2062,7 +2062,7 @@ static void draw_dm_face_normals(BMEditMesh *em, Scene *scene, Object *ob, Deriv
{
drawDMNormal_userData data;
data.em = em;
data.bm = em->bm;
data.normalsize = scene->toolsettings->normalsize;
calcDrawDMNormalScale(ob, &data);
@ -2074,7 +2074,7 @@ static void draw_dm_face_normals(BMEditMesh *em, Scene *scene, Object *ob, Deriv
static void draw_dm_face_centers__mapFunc(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
{
BMFace *efa = EDBM_face_at_index(((void **)userData)[0], index);
BMFace *efa = BM_face_at_index(((void **)userData)[0], index);
const char sel = *(((char **)userData)[1]);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) &&
@ -2085,7 +2085,7 @@ static void draw_dm_face_centers__mapFunc(void *userData, int index, const float
}
static void draw_dm_face_centers(BMEditMesh *em, DerivedMesh *dm, char sel)
{
void *ptrs[2] = {em, &sel};
void *ptrs[2] = {em->bm, &sel};
bglBegin(GL_POINTS);
dm->foreachMappedFaceCenter(dm, draw_dm_face_centers__mapFunc, ptrs, DM_FOREACH_NOP);
@ -2095,7 +2095,7 @@ static void draw_dm_face_centers(BMEditMesh *em, DerivedMesh *dm, char sel)
static void draw_dm_vert_normals__mapFunc(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3])
{
drawDMNormal_userData *data = userData;
BMVert *eve = EDBM_vert_at_index(data->em, index);
BMVert *eve = BM_vert_at_index(data->bm, index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
float no[3], n[3];
@ -2127,7 +2127,7 @@ static void draw_dm_vert_normals(BMEditMesh *em, Scene *scene, Object *ob, Deriv
{
drawDMNormal_userData data;
data.em = em;
data.bm = em->bm;
data.normalsize = scene->toolsettings->normalsize;
calcDrawDMNormalScale(ob, &data);
@ -2142,7 +2142,7 @@ static void draw_dm_verts__mapFunc(void *userData, int index, const float co[3],
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
{
drawDMVerts_userData *data = userData;
BMVert *eve = EDBM_vert_at_index(data->em, index);
BMVert *eve = BM_vert_at_index(data->bm, index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->sel) {
/* skin nodes: draw a red circle around the root
@ -2188,7 +2188,7 @@ static void draw_dm_verts(BMEditMesh *em, DerivedMesh *dm, const char sel, BMVer
drawDMVerts_userData data;
data.sel = sel;
data.eve_act = eve_act;
data.em = em;
data.bm = em->bm;
/* Cache theme values */
UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, data.th_editmesh_active);
@ -2216,7 +2216,7 @@ static DMDrawOption draw_dm_edges_sel__setDrawOptions(void *userData, int index)
drawDMEdgesSel_userData *data = userData;
unsigned char *col;
eed = EDBM_edge_at_index(data->em, index);
eed = BM_edge_at_index(data->bm, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
if (eed == data->eed_act) {
@ -2249,7 +2249,7 @@ static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba
data.baseCol = baseCol;
data.selCol = selCol;
data.actCol = actCol;
data.em = em;
data.bm = em->bm;
data.eed_act = eed_act;
dm->drawMappedEdges(dm, draw_dm_edges_sel__setDrawOptions, &data);
}
@ -2257,7 +2257,7 @@ static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba
/* Draw edges */
static DMDrawOption draw_dm_edges__setDrawOptions(void *userData, int index)
{
if (BM_elem_flag_test(EDBM_edge_at_index(userData, index), BM_ELEM_HIDDEN))
if (BM_elem_flag_test(BM_edge_at_index(userData, index), BM_ELEM_HIDDEN))
return DM_DRAW_OPTION_SKIP;
else
return DM_DRAW_OPTION_NORMAL;
@ -2265,20 +2265,20 @@ static DMDrawOption draw_dm_edges__setDrawOptions(void *userData, int index)
static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm)
{
dm->drawMappedEdges(dm, draw_dm_edges__setDrawOptions, em);
dm->drawMappedEdges(dm, draw_dm_edges__setDrawOptions, em->bm);
}
/* Draw edges with color interpolated based on selection */
static DMDrawOption draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index)
{
if (BM_elem_flag_test(EDBM_edge_at_index(((void **)userData)[0], index), BM_ELEM_HIDDEN))
if (BM_elem_flag_test(BM_edge_at_index(((void **)userData)[0], index), BM_ELEM_HIDDEN))
return DM_DRAW_OPTION_SKIP;
else
return DM_DRAW_OPTION_NORMAL;
}
static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int index, float t)
{
BMEdge *eed = EDBM_edge_at_index(((void **)userData)[0], index);
BMEdge *eed = BM_edge_at_index(((void **)userData)[0], index);
unsigned char **cols = userData;
unsigned char *col0 = cols[(BM_elem_flag_test(eed->v1, BM_ELEM_SELECT)) ? 2 : 1];
unsigned char *col1 = cols[(BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)) ? 2 : 1];
@ -2291,7 +2291,7 @@ static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int i
static void draw_dm_edges_sel_interp(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol)
{
void *cols[3] = {em, baseCol, selCol};
void *cols[3] = {em->bm, baseCol, selCol};
dm->drawMappedEdgesInterp(dm, draw_dm_edges_sel_interp__setDrawOptions, draw_dm_edges_sel_interp__setDrawInterpOptions, cols);
}
@ -2299,7 +2299,7 @@ static void draw_dm_edges_sel_interp(BMEditMesh *em, DerivedMesh *dm, unsigned c
/* Draw only seam edges */
static DMDrawOption draw_dm_edges_seams__setDrawOptions(void *userData, int index)
{
BMEdge *eed = EDBM_edge_at_index(userData, index);
BMEdge *eed = BM_edge_at_index(userData, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SEAM))
return DM_DRAW_OPTION_NORMAL;
@ -2315,7 +2315,7 @@ static void draw_dm_edges_seams(BMEditMesh *em, DerivedMesh *dm)
/* Draw only sharp edges */
static DMDrawOption draw_dm_edges_sharp__setDrawOptions(void *userData, int index)
{
BMEdge *eed = EDBM_edge_at_index(userData, index);
BMEdge *eed = BM_edge_at_index(userData, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && !BM_elem_flag_test(eed, BM_ELEM_SMOOTH))
return DM_DRAW_OPTION_NORMAL;
@ -2330,9 +2330,9 @@ static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm)
#ifdef WITH_FREESTYLE
static int draw_dm_test_freestyle_edge_mark(BMEditMesh *em, BMEdge *eed)
static int draw_dm_test_freestyle_edge_mark(BMesh *bm, BMEdge *eed)
{
FreestyleEdge *fed = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
FreestyleEdge *fed = CustomData_bmesh_get(&bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
if (!fed)
return 0;
return (fed->flag & FREESTYLE_EDGE_MARK) != 0;
@ -2341,7 +2341,7 @@ static int draw_dm_test_freestyle_edge_mark(BMEditMesh *em, BMEdge *eed)
/* Draw only Freestyle feature edges */
static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int index)
{
BMEdge *eed = EDBM_edge_at_index(userData, index);
BMEdge *eed = BM_edge_at_index(userData, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && draw_dm_test_freestyle_edge_mark(userData, eed))
return DM_DRAW_OPTION_NORMAL;
@ -2351,12 +2351,12 @@ static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int
static void draw_dm_edges_freestyle(BMEditMesh *em, DerivedMesh *dm)
{
dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em);
dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em->bm);
}
static int draw_dm_test_freestyle_face_mark(BMEditMesh *em, BMFace *efa)
static int draw_dm_test_freestyle_face_mark(BMesh *bm, BMFace *efa)
{
FreestyleFace *ffa = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
FreestyleFace *ffa = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
if (!ffa)
return 0;
return (ffa->flag & FREESTYLE_FACE_MARK) != 0;
@ -2369,7 +2369,7 @@ static int draw_dm_test_freestyle_face_mark(BMEditMesh *em, BMFace *efa)
static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
{
drawDMFacesSel_userData *data = userData;
BMFace *efa = EDBM_face_at_index(data->em, index);
BMFace *efa = BM_face_at_index(data->bm, index);
unsigned char *col;
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
@ -2379,7 +2379,7 @@ static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
}
else {
#ifdef WITH_FREESTYLE
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->em, efa) ? 3 : 0];
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
#else
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
#endif
@ -2406,9 +2406,9 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
return 0;
i = DM_origindex_mface_mpoly(data->orig_index_mf_to_mpoly, data->orig_index_mp_to_orig, index);
efa = (i != ORIGINDEX_NONE) ? EDBM_face_at_index(data->em, i) : NULL;
efa = (i != ORIGINDEX_NONE) ? BM_face_at_index(data->bm, i) : NULL;
i = DM_origindex_mface_mpoly(data->orig_index_mf_to_mpoly, data->orig_index_mp_to_orig, next_index);
next_efa = (i != ORIGINDEX_NONE) ? EDBM_face_at_index(data->em, i) : NULL;
next_efa = (i != ORIGINDEX_NONE) ? BM_face_at_index(data->bm, i) : NULL;
if (ELEM(NULL, efa, next_efa))
return 0;
@ -2420,8 +2420,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
return 0;
#ifdef WITH_FREESTYLE
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->em, efa) ? 3 : 0];
next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->em, efa) ? 3 : 0];
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
#else
col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : 0];
@ -2445,7 +2445,7 @@ static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba
drawDMFacesSel_userData data;
data.dm = dm;
data.cols[0] = baseCol;
data.em = em;
data.bm = em->bm;
data.cols[1] = selCol;
data.cols[2] = actCol;
#ifdef WITH_FREESTYLE
@ -2465,8 +2465,8 @@ static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba
static DMDrawOption draw_dm_creases__setDrawOptions(void *userData, int index)
{
drawDMLayer_userData *data = userData;
BMEditMesh *em = data->em;
BMEdge *eed = EDBM_edge_at_index(em, index);
BMesh *bm = data->bm;
BMEdge *eed = BM_edge_at_index(bm, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
const float crease = BM_ELEM_CD_GET_FLOAT(eed, data->cd_layer_offset);
@ -2481,7 +2481,7 @@ static void draw_dm_creases(BMEditMesh *em, DerivedMesh *dm)
{
drawDMLayer_userData data;
data.em = em;
data.bm = em->bm;
data.cd_layer_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE);
if (data.cd_layer_offset != -1) {
@ -2494,8 +2494,8 @@ static void draw_dm_creases(BMEditMesh *em, DerivedMesh *dm)
static DMDrawOption draw_dm_bweights__setDrawOptions(void *userData, int index)
{
drawDMLayer_userData *data = userData;
BMEditMesh *em = data->em;
BMEdge *eed = EDBM_edge_at_index(em, index);
BMesh *bm = data->bm;
BMEdge *eed = BM_edge_at_index(bm, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
const float bweight = BM_ELEM_CD_GET_FLOAT(eed, data->cd_layer_offset);
@ -2510,8 +2510,8 @@ static void draw_dm_bweights__mapFunc(void *userData, int index, const float co[
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
{
drawDMLayer_userData *data = userData;
BMEditMesh *em = data->em;
BMVert *eve = EDBM_vert_at_index(em, index);
BMesh *bm = data->bm;
BMVert *eve = BM_vert_at_index(bm, index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
const float bweight = BM_ELEM_CD_GET_FLOAT(eve, data->cd_layer_offset);
@ -2528,7 +2528,7 @@ static void draw_dm_bweights(BMEditMesh *em, Scene *scene, DerivedMesh *dm)
if (ts->selectmode & SCE_SELECT_VERTEX) {
drawDMLayer_userData data;
data.em = em;
data.bm = em->bm;
data.cd_layer_offset = CustomData_get_offset(&em->bm->vdata, CD_BWEIGHT);
if (data.cd_layer_offset != -1) {
@ -2541,7 +2541,7 @@ static void draw_dm_bweights(BMEditMesh *em, Scene *scene, DerivedMesh *dm)
else {
drawDMLayer_userData data;
data.em = em;
data.bm = em->bm;
data.cd_layer_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT);
if (data.cd_layer_offset != -1) {
@ -3060,7 +3060,7 @@ static DMDrawOption draw_em_fancy__setFaceOpts(void *userData, int index)
if (UNLIKELY(index >= em->bm->totface))
return DM_DRAW_OPTION_NORMAL;
efa = EDBM_face_at_index(em, index);
efa = BM_face_at_index(em->bm, index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
GPU_enable_material(efa->mat_nr + 1, NULL);
return DM_DRAW_OPTION_NORMAL;
@ -3078,7 +3078,7 @@ static DMDrawOption draw_em_fancy__setGLSLFaceOpts(void *userData, int index)
if (UNLIKELY(index >= em->bm->totface))
return DM_DRAW_OPTION_NORMAL;
efa = EDBM_face_at_index(em, index);
efa = BM_face_at_index(em->bm, index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
return DM_DRAW_OPTION_NORMAL;
@ -3116,7 +3116,7 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d,
}
}
EDBM_index_arrays_ensure(em, BM_VERT | BM_EDGE | BM_FACE);
BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
if (check_object_draw_editweight(me, finalDM)) {
if (dt > OB_WIRE) {
@ -3128,7 +3128,7 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d,
else {
glEnable(GL_DEPTH_TEST);
draw_mesh_paint_weight_faces(finalDM, false, draw_em_fancy__setFaceOpts, me->edit_btmesh);
draw_mesh_paint_weight_edges(rv3d, finalDM, true, draw_dm_edges__setDrawOptions, me->edit_btmesh);
draw_mesh_paint_weight_edges(rv3d, finalDM, true, draw_dm_edges__setDrawOptions, me->edit_btmesh->bm);
glDisable(GL_DEPTH_TEST);
}
}
@ -7382,7 +7382,7 @@ static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3]
{
void **ptrs = userData;
int offset = (intptr_t) ptrs[0];
BMVert *eve = EDBM_vert_at_index(ptrs[1], index);
BMVert *eve = BM_vert_at_index(ptrs[1], index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
WM_framebuffer_index_set(offset + index);
@ -7391,7 +7391,7 @@ static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3]
}
static void bbs_mesh_verts(BMEditMesh *em, DerivedMesh *dm, int offset)
{
void *ptrs[2] = {(void *)(intptr_t) offset, em};
void *ptrs[2] = {(void *)(intptr_t) offset, em->bm};
glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
bglBegin(GL_POINTS);
@ -7404,7 +7404,7 @@ static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
{
void **ptrs = userData;
int offset = (intptr_t) ptrs[0];
BMEdge *eed = EDBM_edge_at_index(ptrs[1], index);
BMEdge *eed = BM_edge_at_index(ptrs[1], index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
WM_framebuffer_index_set(offset + index);
@ -7416,13 +7416,13 @@ static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
}
static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset)
{
void *ptrs[2] = {(void *)(intptr_t) offset, em};
void *ptrs[2] = {(void *)(intptr_t) offset, em->bm};
dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, ptrs);
}
static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int index)
{
BMFace *efa = EDBM_face_at_index(((void **)userData)[0], index);
BMFace *efa = BM_face_at_index(((void **)userData)[0], index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
if (((void **)userData)[1]) {
@ -7437,7 +7437,7 @@ static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int inde
static void bbs_mesh_solid__drawCenter(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
{
BMFace *efa = EDBM_face_at_index(((void **)userData)[0], index);
BMFace *efa = BM_face_at_index(((void **)userData)[0], index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
WM_framebuffer_index_set(index + 1);
@ -7450,7 +7450,7 @@ static void bbs_mesh_solid__drawCenter(void *userData, int index, const float ce
static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d,
Object *ob, DerivedMesh *dm, int facecol)
{
void *ptrs[2] = {em, NULL}; //second one being null means to draw black
void *ptrs[2] = {em->bm, NULL}; //second one being null means to draw black
cpack(0);
if (facecol) {
@ -7548,7 +7548,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
DerivedMesh *dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
EDBM_index_arrays_ensure(em, BM_VERT | BM_EDGE | BM_FACE);
BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
bbs_mesh_solid_EM(em, scene, v3d, ob, dm, ts->selectmode & SCE_SELECT_FACE);
if (ts->selectmode & SCE_SELECT_FACE)

@ -40,6 +40,7 @@
#include "BKE_curve.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_editmesh.h"
#include "bmesh.h"
@ -133,7 +134,7 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, const flo
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
{
foreachScreenVert_userData *data = userData;
BMVert *eve = EDBM_vert_at_index(data->vc.em, index);
BMVert *eve = BM_vert_at_index(data->vc.em->bm, index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
float screen_co[2];
@ -165,7 +166,7 @@ void mesh_foreachScreenVert(
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
}
EDBM_index_arrays_ensure(vc->em, BM_VERT);
BM_mesh_elem_table_ensure(vc->em->bm, BM_VERT);
dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data, DM_FOREACH_NOP);
dm->release(dm);
@ -176,7 +177,7 @@ void mesh_foreachScreenVert(
static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, const float v0co[3], const float v1co[3])
{
foreachScreenEdge_userData *data = userData;
BMEdge *eed = EDBM_edge_at_index(data->vc.em, index);
BMEdge *eed = BM_edge_at_index(data->vc.em->bm, index);
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
float screen_co_a[2];
@ -225,7 +226,7 @@ void mesh_foreachScreenEdge(
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
}
EDBM_index_arrays_ensure(vc->em, BM_EDGE);
BM_mesh_elem_table_ensure(vc->em->bm, BM_EDGE);
dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
dm->release(dm);
@ -236,7 +237,7 @@ void mesh_foreachScreenEdge(
static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
{
foreachScreenFace_userData *data = userData;
BMFace *efa = EDBM_face_at_index(data->vc.em, index);
BMFace *efa = BM_face_at_index(data->vc.em->bm, index);
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
float screen_co[2];
@ -261,7 +262,7 @@ void mesh_foreachScreenFace(
data.userData = userData;
data.clip_flag = clip_flag;
EDBM_index_arrays_ensure(vc->em, BM_FACE);
BM_mesh_elem_table_ensure(vc->em->bm, BM_FACE);
dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data, DM_FOREACH_NOP);
dm->release(dm);

@ -214,7 +214,7 @@ static void set_mapped_co(void *vuserdata, int index, const float co[3],
void **userdata = vuserdata;
BMEditMesh *em = userdata[0];
TransVert *tv = userdata[1];
BMVert *eve = EDBM_vert_at_index(em, index);
BMVert *eve = BM_vert_at_index(em->bm, index);
if (BM_elem_index_get(eve) != TM_INDEX_SKIP) {
tv = &tv[BM_elem_index_get(eve)];
@ -342,7 +342,7 @@ static void make_trans_verts(Object *obedit, float min[3], float max[3], int mod
}
if (transvmain && em->derivedCage) {
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(bm, BM_VERT);
em->derivedCage->foreachMappedVert(em->derivedCage, set_mapped_co, userdata, DM_FOREACH_NOP);
}
}

@ -2008,8 +2008,8 @@ static struct TransIslandData *editmesh_islands_info_calc(BMEditMesh *em, int *r
* its possible we have a selected vertex thats not in a face, for now best not crash in that case. */
fill_vn_i(vert_map, bm->totvert, -1);
EDBM_index_arrays_ensure(em, htype);
ele_array = (htype == BM_FACE) ? (void **)em->face_index : (void **)em->edge_index;
BM_mesh_elem_table_ensure(bm, htype);
ele_array = (htype == BM_FACE) ? (void **)bm->ftable : (void **)bm->etable;
BM_mesh_elem_index_ensure(bm, BM_VERT);
@ -2576,10 +2576,10 @@ static void createTransUVs(bContext *C, TransInfo *t)
if (propconnected) {
/* create element map with island information */
if (ts->uv_flag & UV_SYNC_SELECTION) {
elementmap = EDBM_uv_element_map_create(em, false, true);
elementmap = BM_uv_element_map_create(em->bm, false, true);
}
else {
elementmap = EDBM_uv_element_map_create(em, true, true);
elementmap = BM_uv_element_map_create(em->bm, true, true);
}
island_enabled = MEM_callocN(sizeof(*island_enabled) * elementmap->totalIslands, "TransIslandData(UV Editing)");
}
@ -2598,7 +2598,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
countsel++;
if (propconnected) {
UvElement *element = ED_uv_element_get(elementmap, efa, l);
UvElement *element = BM_uv_element_get(elementmap, efa, l);
island_enabled[element->island] = TRUE;
}
@ -2634,7 +2634,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
continue;
if (propconnected) {
UvElement *element = ED_uv_element_get(elementmap, efa, l);
UvElement *element = BM_uv_element_get(elementmap, efa, l);
if (!island_enabled[element->island]) {
count_rejected++;
continue;
@ -2648,7 +2648,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
if (propconnected) {
t->total -= count_rejected;
EDBM_uv_element_map_free(elementmap);
BM_uv_element_map_free(elementmap);
MEM_freeN(island_enabled);
}

@ -1429,7 +1429,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
if (em != NULL) {
index_array = dm->getVertDataArray(dm, CD_ORIGINDEX);
EDBM_index_arrays_ensure(em, BM_VERT);
BM_mesh_elem_table_ensure(em->bm, BM_VERT);
}
for (i = 0; i < totvert; i++) {
@ -1450,7 +1450,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
test = 0;
}
else {
eve = EDBM_vert_at_index(em, index);
eve = BM_vert_at_index(em->bm, index);
if ((BM_elem_flag_test(eve, BM_ELEM_HIDDEN) ||
BM_elem_flag_test(eve, BM_ELEM_SELECT)))
@ -1479,7 +1479,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
if (em != NULL) {
index_array = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
EDBM_index_arrays_ensure(em, BM_EDGE);
BM_mesh_elem_table_ensure(em->bm, BM_EDGE);
}
for (i = 0; i < totedge; i++) {
@ -1499,7 +1499,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
test = 0;
}
else {
BMEdge *eed = EDBM_edge_at_index(em, index);
BMEdge *eed = BM_edge_at_index(em->bm, index);
if ((BM_elem_flag_test(eed, BM_ELEM_HIDDEN) ||
BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||

@ -924,7 +924,7 @@ static void uv_select_edgeloop_vertex_loop_flag(UvMapVert *first)
static UvMapVert *uv_select_edgeloop_vertex_map_get(UvVertMap *vmap, BMFace *efa, BMLoop *l)
{
UvMapVert *iterv, *first;
first = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
first = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
for (iterv = first; iterv; iterv = iterv->next) {
if (iterv->separate)
@ -953,7 +953,7 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, UvMapVert *first1,
if (iterv1->f == iterv2->f) {
/* if face already tagged, don't do this edge */
efa = EDBM_face_at_index(em, iterv1->f);
efa = BM_face_at_index(em->bm, iterv1->f);
if (BM_elem_flag_test(efa, BM_ELEM_TAG))
return false;
@ -978,7 +978,7 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, UvMapVert *first1,
break;
if (iterv1->f == iterv2->f) {
efa = EDBM_face_at_index(em, iterv1->f);
efa = BM_face_at_index(em->bm, iterv1->f);
BM_elem_flag_enable(efa, BM_ELEM_TAG);
break;
}
@ -1005,8 +1005,8 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
/* setup */
EDBM_index_arrays_ensure(em, BM_FACE);
vmap = EDBM_uv_vert_map_create(em, 0, limit);
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
vmap = BM_uv_vert_map_create(em->bm, 0, limit);
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
@ -1085,7 +1085,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
}
/* cleanup */
EDBM_uv_vert_map_free(vmap);
BM_uv_vert_map_free(vmap);
return (select) ? 1 : -1;
}
@ -1108,8 +1108,8 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
EDBM_index_arrays_ensure(em, BM_FACE); /* we can use this too */
vmap = EDBM_uv_vert_map_create(em, 1, limit);
BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */
vmap = BM_uv_vert_map_create(em->bm, 1, limit);
if (vmap == NULL)
return;
@ -1152,12 +1152,12 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
stacksize--;
a = stack[stacksize];
efa = EDBM_face_at_index(em, a);
efa = BM_face_at_index(em->bm, a);
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
/* make_uv_vert_map_EM sets verts tmp.l to the indices */
vlist = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
startv = vlist;
@ -1241,7 +1241,7 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
MEM_freeN(stack);
MEM_freeN(flag);
EDBM_uv_vert_map_free(vmap);
BM_uv_vert_map_free(vmap);
}
/* WATCH IT: this returns first selected UV,
@ -2567,7 +2567,7 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, BMEditMes
uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
vlist_iter = EDBM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
vlist_iter = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
while (vlist_iter) {
if (vlist_iter->separate)
@ -2587,7 +2587,7 @@ static void uv_select_flush_from_tag_sticky_loc_internal(Scene *scene, BMEditMes
if (efa_index != vlist_iter->f) {
BMLoop *l_other;
efa_vlist = EDBM_face_at_index(em, vlist_iter->f);
efa_vlist = BM_face_at_index(em->bm, vlist_iter->f);
/* tf_vlist = BM_ELEM_CD_GET_VOID_P(efa_vlist, cd_poly_tex_offset); */ /* UNUSED */
l_other = BM_iter_at_index(em->bm, BM_LOOPS_OF_FACE, efa_vlist, vlist_iter->tfindex);
@ -2657,8 +2657,8 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object
uvedit_pixel_to_float(sima, limit, 0.05);
EDBM_index_arrays_ensure(em, BM_FACE);
vmap = EDBM_uv_vert_map_create(em, 0, limit);
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
vmap = BM_uv_vert_map_create(em->bm, 0, limit);
if (vmap == NULL) {
return;
}
@ -2673,7 +2673,7 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object
}
}
}
EDBM_uv_vert_map_free(vmap);
BM_uv_vert_map_free(vmap);
}
else { /* SI_STICKY_DISABLE or ts->uv_flag & UV_SYNC_SELECTION */
@ -2748,8 +2748,8 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object
uvedit_pixel_to_float(sima, limit, 0.05);
EDBM_index_arrays_ensure(em, BM_FACE);
vmap = EDBM_uv_vert_map_create(em, 0, limit);
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
vmap = BM_uv_vert_map_create(em->bm, 0, limit);
if (vmap == NULL) {
return;
}
@ -2764,7 +2764,7 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object
}
}
}
EDBM_uv_vert_map_free(vmap);
BM_uv_vert_map_free(vmap);
}
else { /* SI_STICKY_DISABLE or ts->uv_flag & UV_SYNC_SELECTION */
@ -3963,8 +3963,8 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
}
/* This code sets editvert->tmp.l to the index. This will be useful later on. */
EDBM_index_arrays_ensure(em, BM_FACE);
vmap = EDBM_uv_vert_map_create(em, 0, limit);
BM_mesh_elem_table_ensure(bm, BM_FACE);
vmap = BM_uv_vert_map_create(bm, 0, limit);
BM_ITER_MESH (editedge, &iter, bm, BM_EDGES_OF_MESH) {
/* flags to determine if we uv is separated from first editface match */
@ -3992,14 +3992,14 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
v1coincident = 0;
separated2 = 0;
efa1 = EDBM_face_at_index(em, mv1->f);
efa1 = BM_face_at_index(bm, mv1->f);
mvinit2 = vmap->vert[BM_elem_index_get(editedge->v2)];
for (mv2 = mvinit2; mv2; mv2 = mv2->next) {
if (mv2->separate)
mv2sep = mv2;
efa2 = EDBM_face_at_index(em, mv2->f);
efa2 = BM_face_at_index(bm, mv2->f);
if (efa1 == efa2) {
/* if v1 is not coincident no point in comparing */
if (v1coincident) {
@ -4042,7 +4042,7 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
me->drawflag |= ME_DRAWSEAMS;
EDBM_uv_vert_map_free(vmap);
BM_uv_vert_map_free(vmap);
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);

@ -600,7 +600,7 @@ static void state_delete(StitchState *state)
{
if (state) {
if (state->element_map) {
EDBM_uv_element_map_free(state->element_map);
BM_uv_element_map_free(state->element_map);
}
if (state->uvs) {
MEM_freeN(state->uvs);
@ -661,9 +661,9 @@ static void stitch_uv_edge_generate_linked_edges(GHash *edge_hash, StitchState *
/* check to see if other vertex of edge belongs to same vertex as */
if (BM_elem_index_get(iter1->l->next->v) == elemindex2)
iter2 = ED_uv_element_get(element_map, iter1->l->f, iter1->l->next);
iter2 = BM_uv_element_get(element_map, iter1->l->f, iter1->l->next);
else if (BM_elem_index_get(iter1->l->prev->v) == elemindex2)
iter2 = ED_uv_element_get(element_map, iter1->l->f, iter1->l->prev);
iter2 = BM_uv_element_get(element_map, iter1->l->f, iter1->l->prev);
if (iter2) {
int index1 = map[iter1 - first_element];
@ -1017,7 +1017,7 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final)
/* copy data from MLoopUVs to the preview display buffers */
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
/* just to test if face was added for processing. uvs of inselected vertices will return NULL */
UvElement *element = ED_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa));
UvElement *element = BM_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa));
if (element) {
int numoftris = efa->len - 2;
@ -1568,8 +1568,8 @@ static UvEdge *uv_edge_get(BMLoop *l, StitchState *state)
{
UvEdge tmp_edge;
UvElement *element1 = ED_uv_element_get(state->element_map, l->f, l);
UvElement *element2 = ED_uv_element_get(state->element_map, l->f, l->next);
UvElement *element1 = BM_uv_element_get(state->element_map, l->f, l);
UvElement *element2 = BM_uv_element_get(state->element_map, l->f, l->next);
int uv1 = state->map[element1 - state->element_map->buf];
int uv2 = state->map[element2 - state->element_map->buf];
@ -1651,10 +1651,10 @@ static int stitch_init(bContext *C, wmOperator *op)
state->draw_handle = ED_region_draw_cb_activate(ar->type, stitch_draw, state, REGION_DRAW_POST_VIEW);
/* in uv synch selection, all uv's are visible */
if (ts->uv_flag & UV_SYNC_SELECTION) {
state->element_map = EDBM_uv_element_map_create(state->em, FALSE, TRUE);
state->element_map = BM_uv_element_map_create(state->em->bm, false, true);
}
else {
state->element_map = EDBM_uv_element_map_create(state->em, TRUE, TRUE);
state->element_map = BM_uv_element_map_create(state->em->bm, true, true);
}
if (!state->element_map) {
state_delete(state);
@ -1715,9 +1715,9 @@ static int stitch_init(bContext *C, wmOperator *op)
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
UvElement *element = ED_uv_element_get(state->element_map, efa, l);
UvElement *element = BM_uv_element_get(state->element_map, efa, l);
int offset1, itmp1 = element - state->element_map->buf;
int offset2, itmp2 = ED_uv_element_get(state->element_map, efa, l->next) - state->element_map->buf;
int offset2, itmp2 = BM_uv_element_get(state->element_map, efa, l->next) - state->element_map->buf;
UvEdge *edge;
offset1 = map[itmp1];
@ -1814,7 +1814,7 @@ static int stitch_init(bContext *C, wmOperator *op)
UvElement *element;
enum StitchModes stored_mode = RNA_enum_get(op->ptr, "stored_mode");
EDBM_index_arrays_ensure(em, BM_FACE);
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
if (stored_mode == STITCH_VERT) {
state->selection_stack = MEM_mallocN(sizeof(*state->selection_stack) * state->total_separate_uvs, "uv_stitch_selection_stack");
@ -1823,8 +1823,8 @@ static int stitch_init(bContext *C, wmOperator *op)
{
faceIndex = RNA_int_get(&itemptr, "face_index");
elementIndex = RNA_int_get(&itemptr, "element_index");
efa = EDBM_face_at_index(em, faceIndex);
element = ED_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, elementIndex));
efa = BM_face_at_index(em->bm, faceIndex);
element = BM_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, elementIndex));
stitch_select_uv(element, state, 1);
}
RNA_END;
@ -1838,11 +1838,11 @@ static int stitch_init(bContext *C, wmOperator *op)
int uv1, uv2;
faceIndex = RNA_int_get(&itemptr, "face_index");
elementIndex = RNA_int_get(&itemptr, "element_index");
efa = EDBM_face_at_index(em, faceIndex);
element = ED_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, elementIndex));
efa = BM_face_at_index(em->bm, faceIndex);
element = BM_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, elementIndex));
uv1 = map[element - state->element_map->buf];
element = ED_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, (elementIndex + 1) % efa->len));
element = BM_uv_element_get(state->element_map, efa, BM_iter_at_index(NULL, BM_LOOPS_OF_FACE, efa, (elementIndex + 1) % efa->len));
uv2 = map[element - state->element_map->buf];
if (uv1 < uv2) {
@ -1877,7 +1877,7 @@ static int stitch_init(bContext *C, wmOperator *op)
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
UvElement *element = ED_uv_element_get(state->element_map, efa, l);
UvElement *element = BM_uv_element_get(state->element_map, efa, l);
if (element) {
stitch_select_uv(element, state, 1);
}
@ -1913,7 +1913,7 @@ static int stitch_init(bContext *C, wmOperator *op)
}
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
UvElement *element = ED_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa));
UvElement *element = BM_uv_element_get(state->element_map, efa, BM_FACE_FIRST_LOOP(efa));
if (element) {
state->tris_per_island[element->island] += (efa->len > 2) ? efa->len - 2 : 0;
@ -2039,7 +2039,7 @@ static void stitch_select(bContext *C, Scene *scene, const wmEvent *event, Stitc
* you can do stuff like deselect the opposite stitchable vertex and the initial still gets deselected */
/* This works due to setting of tmp in find nearest uv vert */
UvElement *element = ED_uv_element_get(state->element_map, hit.efa, hit.l);
UvElement *element = BM_uv_element_get(state->element_map, hit.efa, hit.l);
stitch_select_uv(element, state, FALSE);
}

@ -421,11 +421,11 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
faceMap = MEM_mallocN(numOfFaces * sizeof(BMFace *), "unwrap_edit_face_map");
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
EDBM_index_arrays_ensure(em, BM_EDGE | BM_FACE);
BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_FACE);
/* map subsurfed faces to original editFaces */
for (i = 0; i < numOfFaces; i++)
faceMap[i] = EDBM_face_at_index(em, DM_origindex_mface_mpoly(origFaceIndices, origPolyIndices, i));
faceMap[i] = BM_face_at_index(em->bm, DM_origindex_mface_mpoly(origFaceIndices, origPolyIndices, i));
edgeMap = MEM_mallocN(numOfEdges * sizeof(BMEdge *), "unwrap_edit_edge_map");
@ -433,7 +433,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
for (i = 0; i < numOfEdges; i++) {
/* not all edges correspond to an old edge */
edgeMap[i] = (origEdgeIndices[i] != ORIGINDEX_NONE) ?
EDBM_edge_at_index(em, origEdgeIndices[i]) : NULL;
BM_edge_at_index(em->bm, origEdgeIndices[i]) : NULL;
}
/* Prepare and feed faces to the solver */

@ -196,9 +196,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* update for display only */
dmd->face_count = bm->totface;
result = CDDM_from_bmesh(bm, FALSE);
BLI_assert(bm->vtoolflagpool == NULL); /* make sure we never alloc'd this */
BLI_assert(bm->etoolflagpool == NULL);
BLI_assert(bm->ftoolflagpool == NULL);
BLI_assert(bm->vtoolflagpool == NULL &&
bm->etoolflagpool == NULL &&
bm->ftoolflagpool == NULL); /* make sure we never alloc'd these */
BLI_assert(bm->vtable == NULL &&
bm->etable == NULL &&
bm->ftable == NULL);
BM_mesh_free(bm);
#ifdef USE_TIMEIT

@ -3722,47 +3722,11 @@ char *BPy_BMElem_StringFromHType(const char htype)
/* -------------------------------------------------------------------- */
/* keep at bottom */
/* BAD INCLUDES */
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_editmesh.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "MEM_guardedalloc.h"
/* there are cases where this warning isnt needed, otherwise it could be made into an error */
static void bm_dealloc_warn(const char *mesh_name)
{
PySys_WriteStdout("Modified BMesh '%.200s' from a wrapped editmesh is freed without a call "
"to bmesh.update_edit_mesh(mesh, destructive=True), this is will likely cause a crash\n",
mesh_name);
}
/* this function is called on free, it should stay quite fast */
static void bm_dealloc_editmode_warn(BPy_BMesh *self)
{
if (self->flag & BPY_BMFLAG_IS_WRAPPED) {
/* likely editmesh */
BMesh *bm = self->bm;
Scene *scene;
for (scene = G.main->scene.first; scene; scene = scene->id.next) {
Base *base = scene->basact;
if (base && base->object->type == OB_MESH) {
Mesh *me = base->object->data;
BMEditMesh *em = me->edit_btmesh;
if (em && em->bm == bm) {
/* not foolproof, scripter may have added/removed verts */
if (((em->vert_index && (MEM_allocN_len(em->vert_index) / sizeof(*em->vert_index)) != bm->totvert)) ||
((em->edge_index && (MEM_allocN_len(em->edge_index) / sizeof(*em->edge_index)) != bm->totedge)) ||
((em->face_index && (MEM_allocN_len(em->face_index) / sizeof(*em->face_index)) != bm->totface)))
{
bm_dealloc_warn(me->id.name + 2);
break;
}
}
}
}
/* currently nop - this works without warnings now */
}
}