replace editmode topo mirror function from the one in trunk (ED_mesh_mirrtopo_init)
authorCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 22:01:11 +0000 (22:01 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 20 Dec 2011 22:01:11 +0000 (22:01 +0000)
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/bmeshutils.c
source/blender/editors/mesh/editface.c
source/blender/editors/mesh/meshtools.c

index 9a2bce910fc58819edba41760abea32eae1a75cf..e9884c5d8ce012647f11e304f315e55f0dc7e39d 100644 (file)
@@ -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
index da8df96723d0de37ec009f086fe18d7509270c67..bdfdcd89de8ba5610f7ff11f6c6cbea6f1cbb4b3 100644 (file)
@@ -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;
 }
index 5fed77c6f5d1cbc88d6434f259f7f3bdae9b4105..bffb34f0a5f7030002ccccd5a52f0d0f7548e823 100644 (file)
@@ -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 );
index 25648b265263a90895393bd200b0b201c444ffd4..489cad2bca18ef1037e5de8a6838f0ee62e5c2af 100644 (file)
@@ -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);