svn merge ^/trunk/blender -r40644:40720
[blender-staging.git] / source / blender / editors / space_view3d / view3d_buttons.c
index e1fb287d79c093fbaa766e35f18086d3ae79b23f..7fefc4ae0fefb183bc870ed7915bcd656a7916c7 100644 (file)
@@ -60,6 +60,7 @@
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_screen.h"
+#include "BKE_tessmesh.h"
 #include "BKE_deform.h"
 
 #include "WM_api.h"
@@ -153,32 +154,36 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
        
        if(ob->type==OB_MESH) {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve, *evedef=NULL;
-               EditEdge *eed;
+               BMEditMesh *em = me->edit_btmesh;
+               BMesh *bm = em->bm;
+               BMVert *eve, *evedef=NULL;
+               BMEdge *eed;
+               BMIter iter;
                
-               eve= em->verts.first;
-               while(eve) {
-                       if(eve->f & SELECT) {
+               BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eve, BM_SELECT)) {
                                evedef= eve;
                                tot++;
                                add_v3_v3(median, eve->co);
                        }
-                       eve= eve->next;
                }
-               eed= em->edges.first;
-               while(eed) {
-                       if((eed->f & SELECT)) {
+
+               BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eed, BM_SELECT)) {
+                               float *f;
+
                                totedge++;
-                               median[3]+= eed->crease;
-                               median[6]+= eed->bweight;
+                               f = bm_get_cd_float(&bm->edata, eed->head.data, CD_CREASE);
+                               median[3]+= f ? *f : 0.0f;
+
+                               f = bm_get_cd_float(&bm->edata, eed->head.data, CD_BWEIGHT);
+                               median[6]+= f ? *f : 0.0f;
                        }
-                       eed= eed->next;
                }
 
                /* check for defgroups */
                if(evedef)
-                       dvert= CustomData_em_get(&em->vdata, evedef->data, CD_MDEFORMVERT);
+                       dvert= CustomData_bmesh_get(&em->bm->vdata, evedef->head.data, CD_MDEFORMVERT);
                if(tot==1 && dvert && dvert->totweight) {
                        bDeformGroup *dg;
                        int i, max=1, init=1;
@@ -202,8 +207,6 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                tfp->defweightp= &dvert->dw[0].weight;
                        }
                }
-
-               BKE_mesh_end_editmesh(me, em);
        }
        else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
                Curve *cu= ob->data;
@@ -396,31 +399,34 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                
                if(ob->type==OB_MESH) {
                        Mesh *me= ob->data;
-                       EditMesh *em = BKE_mesh_get_editmesh(me);
+                       BMEditMesh *em = me->edit_btmesh;
+                       BMVert *eve;
+                       BMIter iter;
 
-                       /* allow for some rounding error becasue of matrix transform */
                        if(len_v3(median) > 0.000001f) {
-                               EditVert *eve;
 
-                               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)) {
                                                add_v3_v3(eve->co, median);
                                        }
                                }
-
-                               recalc_editnormals(em);
+                               
+                               EDBM_RecalcNormals(em);
                        }
-
+                       
                        if(median[3] != 0.0f) {
-                               EditEdge *eed;
+                               BMEdge *eed;
                                const float fixed_crease= (ve_median[3] <= 0.0f ? 0.0f : (ve_median[3] >= 1.0f ? 1.0f : FLT_MAX));
-
+                               
                                if(fixed_crease != FLT_MAX) {
                                        /* simple case */
 
-                                       for(eed= em->edges.first; eed; eed= eed->next) {
-                                               if(eed->f & SELECT) {
-                                                       eed->crease= fixed_crease;
+                                       BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                                               if(BM_TestHFlag(eed, BM_SELECT)) {
+                                                       float *crease = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_CREASE);
+                                                       if (!crease) break;
+                                                       
+                                                       *crease= fixed_crease;
                                                }
                                        }
                                }
@@ -437,10 +443,14 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                                /* scale down */
                                                const float sca= median_new / median_orig;
                                                
-                                               for(eed= em->edges.first; eed; eed= eed->next) {
-                                                       if(eed->f & SELECT) {
-                                                               eed->crease *= sca;
-                                                               CLAMP(eed->crease, 0.0f, 1.0f);
+                                               BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                                                       if(BM_TestHFlag(eed, BM_SELECT) && !BM_TestHFlag(eed, BM_HIDDEN)) {
+                                                               float *crease = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_CREASE);
+                                                               
+                                                               if (!crease) break;
+                                                               
+                                                               *crease *= sca;
+                                                               CLAMP(*crease, 0.0f, 1.0f);
                                                        }
                                                }
                                        }
@@ -448,17 +458,20 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                                /* scale up */
                                                const float sca= (1.0f - median_new) / (1.0f - median_orig);
 
-                                               for(eed= em->edges.first; eed; eed= eed->next) {
-                                                       if(eed->f & SELECT) {
-                                                               eed->crease = 1.0f - ((1.0f - eed->crease) * sca);
-                                                               CLAMP(eed->crease, 0.0f, 1.0f);
+                                               BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) {
+                                                       if(BM_TestHFlag(eed, BM_SELECT) && !BM_TestHFlag(eed, BM_HIDDEN)) {
+                                                               float *crease = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_CREASE);
+                                                               if (!crease) break;
+
+                                                               *crease = 1.0f - ((1.0f - *crease) * sca);
+                                                               CLAMP(*crease, 0.0f, 1.0f);
                                                        }
                                                }
                                        }
                                }
                        }
-
                        if (median[6] != 0.0f) {
+#if 0 // BMESH_TODO
                                EditEdge *eed;
                                const float fixed_bweight= (ve_median[6] <= 0.0f ? 0.0f : (ve_median[6] >= 1.0f ? 1.0f : FLT_MAX));
 
@@ -503,8 +516,9 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                                }
                                        }
                                }
+#endif // BMESH_TODO
                        }
-                       BKE_mesh_end_editmesh(me, em);
+                       EDBM_RecalcNormals(em);
                }
                else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
                        Curve *cu= ob->data;
@@ -581,37 +595,35 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 #define B_VGRP_PNL_EDIT_SINGLE 8 /* or greater */
 #define B_VGRP_PNL_COPY_SINGLE 16384 /* or greater */
 
-static void act_vert_def(Object *ob, EditVert **eve, MDeformVert **dvert)
+static void act_vert_def(Object *ob, BMVert **eve, MDeformVert **dvert)
 {
        if(ob && ob->mode & OB_MODE_EDIT && ob->type==OB_MESH && ob->defbase.first) {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditSelection *ese = ((EditSelection*)em->selected.last);
+               BMEditMesh *em = me->edit_btmesh;
+               BMEditSelection *ese = ((BMEditSelection*)em->bm->selected.last);
 
-               if(ese && ese->type == EDITVERT) {
-                       *eve= (EditVert*)ese->data;
-                       *dvert= CustomData_em_get(&em->vdata, (*eve)->data, CD_MDEFORMVERT);
+               if(ese && ese->type == BM_VERT) {
+                       *eve= (BMVert*)ese->data;
+                       *dvert= CustomData_bmesh_get(&em->bm->vdata, (*eve)->head.data, CD_MDEFORMVERT);
                        return;
                }
-
-               BKE_mesh_end_editmesh(me, em);
        }
 
        *eve= NULL;
        *dvert= NULL;
 }
 
-static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int index)
+static void editvert_mirror_update(Object *ob, BMVert *eve, int def_nr, int index)
 {
        Mesh *me= ob->data;
-       EditMesh *em = BKE_mesh_get_editmesh(me);
-       EditVert *eve_mirr;
+       BMEditMesh *em = me->edit_btmesh;
+       BMVert *eve_mirr;
 
-       eve_mirr= editmesh_get_x_mirror_vert(ob, em, eve, eve->co, index);
+       eve_mirr= editbmesh_get_x_mirror_vert(ob, em, eve, eve->co, index);
 
        if(eve_mirr && eve_mirr != eve) {
-               MDeformVert *dvert_src= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
-               MDeformVert *dvert_dst= CustomData_em_get(&em->vdata, eve_mirr->data, CD_MDEFORMVERT);
+               MDeformVert *dvert_src= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
+               MDeformVert *dvert_dst= CustomData_bmesh_get(&em->bm->vdata, eve_mirr->head.data, CD_MDEFORMVERT);
                if(dvert_dst) {
                        if(def_nr == -1) {
                                /* all vgroups, add groups where neded  */
@@ -633,7 +645,7 @@ static void editvert_mirror_update(Object *ob, EditVert *eve, int def_nr, int in
 
 static void vgroup_adjust_active(Object *ob, int def_nr)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -646,7 +658,7 @@ static void vgroup_adjust_active(Object *ob, int def_nr)
 
 static void vgroup_copy_active_to_sel(Object *ob)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -656,14 +668,15 @@ static void vgroup_copy_active_to_sel(Object *ob)
        }
        else {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve;
+               BMEditMesh *em = me->edit_btmesh;
+               BMIter iter;
+               BMVert *eve;
                MDeformVert *dvert;
                int index= 0;
 
-               for(eve= em->verts.first; eve; eve= eve->next, index++) {
-                       if(eve->f & SELECT && eve != eve_act) {
-                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) {
+                       if(BM_TestHFlag(eve, BM_SELECT) && eve != eve_act) {
+                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                if(dvert) {
                                        defvert_copy(dvert, dvert_act);
 
@@ -672,13 +685,15 @@ static void vgroup_copy_active_to_sel(Object *ob)
 
                                }
                        }
+
+                       index++;
                }
        }
 }
 
 static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -688,8 +703,9 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
        }
        else {
                Mesh *me= ob->data;
-               EditMesh *em = BKE_mesh_get_editmesh(me);
-               EditVert *eve;
+               BMEditMesh *em = me->edit_btmesh;
+               BMIter iter;
+               BMVert *eve;
                MDeformVert *dvert;
                MDeformWeight *dw;
                float act_weight = -1.0f;
@@ -705,10 +721,11 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 
                if(act_weight < -0.5f)
                        return;
-
-               for(eve= em->verts.first; eve; eve= eve->next, index++) {
-                       if(eve->f & SELECT && eve != eve_act) {
-                               dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
+               
+               eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+               for (index=0; eve; eve=BMIter_Step(&iter), index++) {
+                       if(BM_TestHFlag(eve, BM_SELECT) && eve != eve_act) {
+                               dvert= CustomData_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
                                if(dvert) {
                                        for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
                                                if(def_nr == dw->def_nr) {
@@ -732,7 +749,7 @@ static void vgroup_copy_active_to_sel_single(Object *ob, int def_nr)
 
 static void vgroup_normalize_active(Object *ob)
 {
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -780,7 +797,7 @@ static int view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
-       EditVert *eve_act;
+       BMVert *eve_act;
        MDeformVert *dvert_act;
 
        act_vert_def(ob, &eve_act, &dvert_act);
@@ -795,7 +812,7 @@ static void view3d_panel_vgroup(const bContext *C, Panel *pa)
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
 
-       EditVert *eve;
+       BMVert *eve;
        MDeformVert *dvert;
 
        act_vert_def(ob, &eve, &dvert);