From deb3b7e282c9fed045201ca39d682baf3a281ffe Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 20 Dec 2011 22:01:11 +0000 Subject: [PATCH] replace editmode topo mirror function from the one in trunk (ED_mesh_mirrtopo_init) --- source/blender/editors/include/ED_mesh.h | 3 ++- source/blender/editors/mesh/bmeshutils.c | 31 +++++++++++++++++++++--- source/blender/editors/mesh/editface.c | 11 ++++++--- source/blender/editors/mesh/meshtools.c | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 9a2bce910fc..e9884c5d8ce 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -313,7 +313,8 @@ typedef struct MirrTopoStore_t { } MirrTopoStore_t; int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); -void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); +void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, + const short skip_em_vert_array_init); void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); #ifdef __cplusplus diff --git a/source/blender/editors/mesh/bmeshutils.c b/source/blender/editors/mesh/bmeshutils.c index da8df96723d..bdfdcd89de8 100644 --- a/source/blender/editors/mesh/bmeshutils.c +++ b/source/blender/editors/mesh/bmeshutils.c @@ -796,6 +796,12 @@ int EDBM_vertColorCheck(BMEditMesh *em) return em && em->bm->totface && CustomData_has_layer(&em->bm->ldata, CD_MLOOPCOL); } +static BMVert *cache_mirr_intptr_as_bmvert(intptr_t *index_lookup, int index) +{ + intptr_t eve_i= index_lookup[index]; + return (eve_i == -1) ? NULL : (BMVert *)eve_i; +} + /* BM_SEARCH_MAXDIST is too big, copied from 2.6x MOC_THRESH, should become a * preference */ #define BM_SEARCH_MAXDIST_MIRR 0.00002f @@ -803,11 +809,14 @@ int EDBM_vertColorCheck(BMEditMesh *em) void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) { Mesh *me = em->me; - BMBVHTree *tree = BMBVH_NewBVH(em, 0, NULL, NULL); BMIter iter; BMVert *v; int li, topo = 0; + /* one or the other is used depending if topo is enabled */ + BMBVHTree *tree= NULL; + MirrTopoStore_t mesh_topo_store= {NULL, -1, -1, -1}; + if (me && (me->editflag & ME_EDIT_MIRROR_TOPO)) { topo = 1; } @@ -827,6 +836,13 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) BM_ElemIndex_Ensure(em->bm, BM_VERT); + if (topo) { + ED_mesh_mirrtopo_init(me, -1, &mesh_topo_store, TRUE); + } + else { + tree= BMBVH_NewBVH(em, 0, NULL, NULL); + } + BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { BMVert *mirr; int *idx = CustomData_bmesh_get_layer_n(&em->bm->vdata, v->head.data, li); @@ -835,9 +851,10 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) //temporary for testing, check for selection if (use_select && !BM_TestHFlag(v, BM_SELECT)) continue; - + mirr = topo ? - BMBVH_FindClosestVertTopo(tree, co, BM_SEARCH_MAXDIST_MIRR, v) : + /* BMBVH_FindClosestVertTopo(tree, co, BM_SEARCH_MAXDIST_MIRR, v) */ + cache_mirr_intptr_as_bmvert(mesh_topo_store.index_lookup, BM_GetIndex(v)) : BMBVH_FindClosestVert(tree, co, BM_SEARCH_MAXDIST_MIRR); if (mirr && mirr != v) { @@ -850,7 +867,13 @@ void EDBM_CacheMirrorVerts(BMEditMesh *em, const short use_select) } } - BMBVH_FreeBVH(tree); + + if (topo) { + ED_mesh_mirrtopo_free(&mesh_topo_store); + } + else { + BMBVH_FreeBVH(tree); + } em->mirror_cdlayer= li; } diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 5fed77c6f5d..bffb34f0a5f 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -820,7 +820,8 @@ int ED_mesh_mirrtopo_recalc_check(Mesh *me, const int ob_mode, MirrTopoStore_t * } -void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store) +void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store, + const short skip_em_vert_array_init) { MEdge *medge; BMEditMesh *em= me->edit_btmesh; @@ -914,7 +915,9 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to mesh_topo_store->index_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" ); if(em) { - EDBM_init_index_arrays(em,1,0,0); + if (skip_em_vert_array_init == FALSE) { + EDBM_init_index_arrays(em,1,0,0); + } } @@ -949,7 +952,9 @@ void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_to } } if(em) { - EDBM_free_index_arrays(em); + if (skip_em_vert_array_init == FALSE) { + EDBM_free_index_arrays(em); + } } MEM_freeN( MirrTopoPairs ); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 25648b26526..489cad2bca1 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -914,7 +914,7 @@ int mesh_mirrtopo_table(Object *ob, char mode) } } else if(mode=='s') { /* start table */ - ED_mesh_mirrtopo_init(ob->data, ob->mode, &mesh_topo_store); + ED_mesh_mirrtopo_init(ob->data, ob->mode, &mesh_topo_store, FALSE); } else if(mode=='e') { /* end table */ ED_mesh_mirrtopo_free(&mesh_topo_store);