svn merge -r40166:40279 ^/trunk/blender
[blender.git] / source / blender / editors / object / object_hook.c
index fd4581a..8559611 100644 (file)
@@ -57,6 +57,7 @@
 #include "BKE_report.h"
 #include "BKE_scene.h"
 #include "BKE_deform.h"
+#include "BKE_tessmesh.h"
 
 #include "RNA_define.h"
 #include "RNA_access.h"
 
 #include "object_intern.h"
 
-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;
        
@@ -88,8 +90,8 @@ static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float
        nr= 0;
        zero_v3(cent);
        
-       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++;
                        add_v3_v3(cent, eve->co);
                }
@@ -101,7 +103,7 @@ 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)
 {
        zero_v3(cent);
 
@@ -110,11 +112,12 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa
                int totvert=0;
 
                MDeformVert *dvert;
-               EditVert *eve;
+               BMVert *eve;
+               BMIter iter;
 
                /* 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_bmesh_get(&em->bm->vdata, eve->head.data, CD_MDEFORMVERT);
 
                        if(dvert) {
                                if(defvert_find_weight(dvert, defgrp_index) > 0.0f) {
@@ -134,25 +137,27 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa
        return 0;
 }      
 
-static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
+static void select_editbmesh_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;
        
        if (hmd->indexar == NULL)
                return;
        
-       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);
+       EDBM_selectmode_flush(em);
 }
 
 static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar, float *cent)
@@ -302,15 +307,13 @@ static int object_hook_index_array(Object *obedit, int *tot, int **indexar, char
                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;
                        }
                }
@@ -379,7 +382,7 @@ static void object_hook_select(Object *ob, HookModifierData *hmd)
        if (hmd->indexar == NULL)
                return;
        
-       if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd);
+       if(ob->type==OB_MESH) select_editbmesh_hook(ob, hmd);
        else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
        else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd);
        else if(ob->type==OB_SURF) select_editcurve_hook(ob, hmd);