merge with trunk at r31523
[blender.git] / source / blender / editors / space_image / image_buttons.c
index 9871b75fa422c1d8310e8101f73b480eea812e96..44f3f5f57645d5036adddd42b7c7008d966b4884 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_mesh.h"
 #include "BKE_node.h"
 #include "BKE_screen.h"
+#include "BKE_tessmesh.h"
 
 #include "RE_pipeline.h"
 
@@ -194,39 +195,32 @@ static void image_editvertex_buts(const bContext *C, uiBlock *block)
        SpaceImage *sima= CTX_wm_space_image(C);
        Image *ima= sima->image;
        Object *obedit= CTX_data_edit_object(C);
+       BMEditMesh *em;
+       BMFace *efa;
+       MTexPoly *tf;
+       BMLoop *l;
+       MLoopUV *luv;
+       BMIter iter, liter;
        static float ocent[2];
        float cent[2]= {0.0, 0.0};
        int imx= 256, imy= 256;
        int nactive= 0, step, digits;
-       EditMesh *em;
-       EditFace *efa;
-       MTFace *tf;
        
        image_transform_but_attr(sima, &imx, &imy, &step, &digits);
        
-       em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
-       for (efa= em->faces.first; efa; efa= efa->next) {
-               tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-               if (uvedit_face_visible(scene, ima, efa, tf)) {
+       em= ((Mesh *)obedit->data)->edit_btmesh;
+       BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
+               tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
+               if (!uvedit_face_visible(scene, ima, efa, tf))
+                       continue;
+
+               BM_ITER(l, &iter, em->bm, BM_LOOPS_OF_FACE, efa) {
+                       luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
                        
-                       if (uvedit_uv_selected(scene, efa, tf, 0)) {
-                               cent[0]+= tf->uv[0][0];
-                               cent[1]+= tf->uv[0][1];
-                               nactive++;
-                       }
-                       if (uvedit_uv_selected(scene, efa, tf, 1)) {
-                               cent[0]+= tf->uv[1][0];
-                               cent[1]+= tf->uv[1][1];
-                               nactive++;
-                       }
-                       if (uvedit_uv_selected(scene, efa, tf, 2)) {
-                               cent[0]+= tf->uv[2][0];
-                               cent[1]+= tf->uv[2][1];
-                               nactive++;
-                       }
-                       if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
-                               cent[0]+= tf->uv[3][0];
-                               cent[1]+= tf->uv[3][1];
+                       if (uvedit_uv_selected(em, scene, l)) {
+                               cent[0] += luv->uv[0];
+                               cent[1] += luv->uv[1];
+
                                nactive++;
                        }
                }
@@ -269,32 +263,23 @@ static void image_editvertex_buts(const bContext *C, uiBlock *block)
                        delta[1]= ocent[1]/imy - cent[1];
                }
 
-               for (efa= em->faces.first; efa; efa= efa->next) {
-                       tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-                       if (uvedit_face_visible(scene, ima, efa, tf)) {
-                               if (uvedit_uv_selected(scene, efa, tf, 0)) {
-                                       tf->uv[0][0]+= delta[0];
-                                       tf->uv[0][1]+= delta[1];
-                               }
-                               if (uvedit_uv_selected(scene, efa, tf, 1)) {
-                                       tf->uv[1][0]+= delta[0];
-                                       tf->uv[1][1]+= delta[1];
-                               }
-                               if (uvedit_uv_selected(scene, efa, tf, 2)) {
-                                       tf->uv[2][0]+= delta[0];
-                                       tf->uv[2][1]+= delta[1];
-                               }
-                               if (efa->v4 && uvedit_uv_selected(scene, efa, tf, 3)) {
-                                       tf->uv[3][0]+= delta[0];
-                                       tf->uv[3][1]+= delta[1];
+               BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
+                       tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
+                       if (!uvedit_face_visible(scene, ima, efa, tf))
+                               continue;
+
+                       BM_ITER(l, &iter, em->bm, BM_LOOPS_OF_FACE, efa) {
+                               luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+                               
+                               if (uvedit_uv_selected(em, scene, l)) {
+                                       luv->uv[0] += delta[0];
+                                       luv->uv[1] += delta[1];
                                }
                        }
                }
-               
+
                WM_event_add_notifier(C, NC_IMAGE, sima->image);
        }
-
-       BKE_mesh_end_editmesh(obedit->data, em);
 }