merge with 2.5 (not trunk, last merge message said that on accident) at r22252
[blender.git] / source / blender / editors / object / object_edit.c
index a6bd38752ae5cd96582b0c709af6db8328f817e5..780fa526b33c52ddb93e26986e135224ca3eea77 100644 (file)
@@ -96,6 +96,7 @@
 #include "BKE_material.h"
 #include "BKE_mball.h"
 #include "BKE_mesh.h"
+#include "BKE_tessmesh.h"
 #include "BKE_nla.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
@@ -917,13 +918,14 @@ static void copy_object_set_idnew(Scene *scene, View3D *v3d, int dupflag)
        
 }
 
-static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float *cent)
+static int return_editmesh_indexar(BMEditMesh *em, int *tot, int **indexar, float *cent)
 {
-       EditVert *eve;
+       BMVert *eve;
+       BMIter iter;
        int *index, nr, totvert=0;
        
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) totvert++;
+       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+               if(BM_TestHFlag(eve, BM_SELECT)) totvert++;
        }
        if(totvert==0) return 0;
        
@@ -932,8 +934,8 @@ static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float
        nr= 0;
        cent[0]= cent[1]= cent[2]= 0.0;
        
-       for(eve= em->verts.first; eve; eve= eve->next) {
-               if(eve->f & SELECT) {
+       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+               if(BM_TestHFlag(eve, BM_SELECT)) {
                        *index= nr; index++;
                        VecAddf(cent, cent, eve->co);
                }
@@ -945,19 +947,19 @@ static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float
        return totvert;
 }
 
-static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, float *cent)
+static int return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *name, float *cent)
 {
        MDeformVert *dvert;
-       EditVert *eve;
+       BMVert *eve;
+       BMIter iter;
        int i, totvert=0;
        
        cent[0]= cent[1]= cent[2]= 0.0;
        
        if(obedit->actdef) {
-               
                /* find the vertices */
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                       dvert= CustomData_em_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
 
                        if(dvert) {
                                for(i=0; i<dvert->totweight; i++){
@@ -982,19 +984,18 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa
 static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
 {
        Mesh *me= ob->data;
-       EditMesh *em= BKE_mesh_get_editmesh(me);
-       EditVert *eve;
+       BMEditMesh *em= me->edit_btmesh;
+       BMVert *eve;
+       BMIter iter;
        int index=0, nr=0;
        
-       for(eve= em->verts.first; eve; eve= eve->next, nr++) {
+       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
                if(nr==hmd->indexar[index]) {
-                       eve->f |= SELECT;
+                       BM_Select(em->bm, eve, 1);
                        if(index < hmd->totindex-1) index++;
                }
+               nr++;
        }
-       EM_select_flush(em);
-
-       BKE_mesh_end_editmesh(me, em);
 }
 
 static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar, float *cent)
@@ -1167,16 +1168,13 @@ int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, floa
                case OB_MESH:
                {
                        Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       BMEditMesh *em = me->edit_btmesh;
 
                        /* check selected vertices first */
                        if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
-                               BKE_mesh_end_editmesh(me, em);
                                return 1;
                        } else {
-                               int ret = return_editmesh_vgroup(obedit, em, name, cent_r);
-                               BKE_mesh_end_editmesh(me, em);
-                               return ret;
+                               return return_editmesh_vgroup(obedit, em, name, cent_r);
                        }
                }
                case OB_CURVE:
@@ -2613,10 +2611,10 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
        
        if(obedit->type==OB_MESH) {
                Mesh *me= obedit->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
+               BMEditMesh *em = me->edit_btmesh;
+               BMIter iter;
 
-               eve= em->verts.first;
-               while(eve) {
+               BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
                        if(eve->f & 1) {
                                if(v1==0) v1= nr;
                                else if(v2==0) v2= nr;
@@ -2625,10 +2623,7 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
                                else break;
                        }
                        nr++;
-                       eve= eve->next;
                }
-
-               BKE_mesh_end_editmesh(me, em);
        }
        else if(ELEM(obedit->type, OB_SURF, OB_CURVE)) {
                ListBase *editnurb= curve_get_editcurve(obedit);
@@ -3363,9 +3358,10 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
        
                if(obedit->type==OB_MESH) {
                        Mesh *me= obedit->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       BMEditMesh *em = me->edit_btmesh;
+                       BMIter iter;
 
-                       for(eve= em->verts.first; eve; eve= eve->next) {
+                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
                                if(v3d->around==V3D_CENTROID) {
                                        total++;
                                        VECADD(cent, cent, eve->co);
@@ -3384,14 +3380,13 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
                                cent[2]= (min[2]+max[2])/2.0f;
                        }
                        
-                       for(eve= em->verts.first; eve; eve= eve->next) {
+                       BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
                                VecSubf(eve->co, eve->co, cent);                        
                        }
                        
-                       recalc_editnormals(em);
+                       EDBM_RecalcNormals(em);
                        tot_change++;
                        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-                       BKE_mesh_end_editmesh(me, em);
                }
        }
        
@@ -3688,16 +3683,17 @@ void ED_object_exit_editmode(bContext *C, int flag)
 //             if(retopo_mesh_paint_check())
 //                     retopo_end_okee();
                
-               if(me->edit_mesh->totvert>MESH_MAX_VERTS) {
+               if(me->edit_btmesh->bm->totvert>MESH_MAX_VERTS) {
                        error("Too many vertices");
                        return;
                }
-               load_editMesh(scene, obedit);
+
+               EDBM_LoadEditBMesh(scene, obedit);
                
                if(freedata) {
-                       free_editMesh(me->edit_mesh);
-                       MEM_freeN(me->edit_mesh);
-                       me->edit_mesh= NULL;
+                       EDBM_FreeEditBMesh(me->edit_btmesh);
+                       MEM_freeN(me->edit_btmesh);
+                       me->edit_btmesh= NULL;
                }
                
                if(G.f & G_WEIGHTPAINT)
@@ -3781,7 +3777,7 @@ void ED_object_enter_editmode(bContext *C, int flag)
                ok= 1;
                scene->obedit= ob;      // context sees this
                
-               make_editMesh(scene, ob);
+               EDBM_MakeEditBMesh(scene, ob);
 
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MESH, scene);
        }