merge from master
[blender.git] / source / blender / editors / uvedit / uvedit_ops.c
index bf5a06f0a1c9d78bc82d5271b46ec933a1d42903..61e0004915d2ea4c3db2377a793fcde06b30b7f8 100644 (file)
@@ -57,7 +57,6 @@
 
 #include "BKE_context.h"
 #include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -68,6 +67,8 @@
 #include "BKE_scene.h"
 #include "BKE_editmesh.h"
 
+#include "DEG_depsgraph.h"
+
 #include "ED_image.h"
 #include "ED_mesh.h"
 #include "ED_node.h"
@@ -88,7 +89,7 @@
 
 #include "uvedit_intern.h"
 
-static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int action);
+static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, int action);
 static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object *obedit, const bool select);
 static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object *obedit, const bool select);
 
@@ -106,7 +107,7 @@ bool ED_uvedit_test(Object *obedit)
                return 0;
 
        em = BKE_editmesh_from_object(obedit);
-       ret = EDBM_mtexpoly_check(em);
+       ret = EDBM_uv_check(em);
        
        return ret;
 }
@@ -182,7 +183,6 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I
 {
        BMEditMesh *em;
        BMIter iter;
-       MTexPoly *tf;
        bool update = false;
        const bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION);
        
@@ -206,8 +206,6 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I
                BMFace *efa;
 
                int cd_loop_uv_offset;
-               int cd_poly_tex_offset;
-
                /* old shading system, assign image to selected faces */
 #ifdef USE_SWITCH_ASPECT
                float prev_aspect[2], fprev_aspect;
@@ -221,31 +219,22 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I
 #endif
 
                /* ensure we have a uv map */
-               if (!CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) {
-                       BM_data_layer_add(em->bm, &em->bm->pdata, CD_MTEXPOLY);
+               if (!CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) {
                        BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPUV);
                        /* make UVs all nice 0-1 */
-                       ED_mesh_uv_loop_reset_ex(obedit->data, CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY));
+                       ED_mesh_uv_loop_reset_ex(obedit->data, CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV));
                        update = true;
                }
 
                cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-               cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
                /* now assign to all visible faces */
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (uvedit_face_visible_test(scene, previma, efa, tf) &&
+                       if (uvedit_face_visible_test(scene, obedit, previma, efa) &&
                            (selected == true || uvedit_face_select_test(scene, efa, cd_loop_uv_offset)))
                        {
-                               if (ima) {
-                                       tf->tpage = ima;
-                                       
-                                       if (ima->id.us == 0) id_us_plus(&ima->id);
-                                       else id_lib_extern(&ima->id);
-
 #ifdef USE_SWITCH_ASPECT
+                               if (ima) {
                                        /* we also need to correct the aspect of uvs */
                                        if (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) {
                                                /* do nothing */
@@ -261,11 +250,9 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I
                                                        luv->uv[0] /= faspect;
                                                }
                                        }
-#endif
-                               }
-                               else {
-                                       tf->tpage = NULL;
                                }
+#endif
+                               BKE_object_material_edit_image_set(obedit, efa->mat_nr, ima);
 
                                update = true;
                        }
@@ -273,49 +260,12 @@ void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, I
 
                /* and update depdency graph */
                if (update) {
-                       DAG_id_tag_update(obedit->data, 0);
+                       DEG_id_tag_update(obedit->data, 0);
                }
        }
 
 }
 
-/* dotile - 1, set the tile flag (from the space image)
- *          2, set the tile index for the faces. */
-static bool uvedit_set_tile(Object *obedit, Image *ima, int curtile)
-{
-       BMEditMesh *em;
-       BMFace *efa;
-       BMIter iter;
-       MTexPoly *tf;
-       int cd_poly_tex_offset;
-       
-       /* verify if we have something to do */
-       if (!ima || !ED_uvedit_test(obedit))
-               return false;
-
-       if ((ima->tpageflag & IMA_TILES) == 0)
-               return false;
-
-       /* skip assigning these procedural images... */
-       if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)
-               return false;
-       
-       em = BKE_editmesh_from_object(obedit);
-
-       cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
-
-       BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-               if (BM_elem_flag_test(efa, BM_ELEM_SELECT))
-                       tf->tile = curtile;  /* set tile index */
-       }
-
-       DAG_id_tag_update(obedit->data, 0);
-
-       return true;
-}
-
 /*********************** space conversion *********************/
 
 static void uvedit_pixel_to_float(SpaceImage *sima, float *dist, float pixeldist)
@@ -361,14 +311,17 @@ bool uvedit_face_visible_nolocal(Scene *scene, BMFace *efa)
                return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0 && BM_elem_flag_test(efa, BM_ELEM_SELECT));
 }
 
-bool uvedit_face_visible_test(Scene *scene, Image *ima, BMFace *efa, MTexPoly *tf)
+bool uvedit_face_visible_test(Scene *scene, Object *obedit, Image *ima, BMFace *efa)
 {
        ToolSettings *ts = scene->toolsettings;
 
-       if (ts->uv_flag & UV_SHOW_SAME_IMAGE)
-               return (tf->tpage == ima) ? uvedit_face_visible_nolocal(scene, efa) : false;
-       else
+       if (ts->uv_flag & UV_SHOW_SAME_IMAGE) {
+               const Image *face_image = BKE_object_material_edit_image_get(obedit, efa->mat_nr);
+               return (face_image == ima) ? uvedit_face_visible_nolocal(scene, efa) : false;
+       }
+       else {
                return uvedit_face_visible_nolocal(scene, efa);
+       }
 }
 
 bool uvedit_face_select_test(Scene *scene, BMFace *efa,
@@ -661,18 +614,15 @@ bool ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float r_min[2],
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        bool changed = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        INIT_MINMAX2(r_min, r_max);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
                
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -711,17 +661,14 @@ static bool ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        unsigned int sel = 0;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        zero_v2(co);
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
                
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -738,7 +685,7 @@ static bool ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[
        return (sel != 0);
 }
 
-static bool uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2], char mode)
+bool ED_uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2], char mode)
 {
        bool changed = false;
        
@@ -760,9 +707,8 @@ static bool uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2
 
 /************************** find nearest ****************************/
 
-void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float co[2], NearestHit *hit)
+void uv_find_nearest_edge(Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, const float co[2], NearestHit *hit)
 {
-       MTexPoly *tf;
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
@@ -771,7 +717,6 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float
        int i;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        mindist_squared = 1e10f;
        memset(hit, 0, sizeof(*hit));
@@ -779,8 +724,7 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float
        BM_mesh_elem_index_ensure(em->bm, BM_VERT);
        
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
                
                BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
@@ -790,7 +734,6 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float
                        dist_squared = dist_squared_to_line_segment_v2(co, luv->uv, luv_next->uv);
 
                        if (dist_squared < mindist_squared) {
-                               hit->tf = tf;
                                hit->efa = efa;
                                
                                hit->l = l;
@@ -804,27 +747,25 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float
        }
 }
 
-static void uv_find_nearest_face(Scene *scene, Image *ima, BMEditMesh *em, const float co[2], NearestHit *hit)
+static void uv_find_nearest_face(
+        Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, const float co[2], NearestHit *hit)
 {
-       MTexPoly *tf;
        BMFace *efa;
        BMIter iter;
        float mindist, dist, cent[2];
 
        const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        mindist = 1e10f;
        memset(hit, 0, sizeof(*hit));
 
        /*this will fill in hit.vert1 and hit.vert2*/
-       uv_find_nearest_edge(scene, ima, em, co, hit);
+       uv_find_nearest_edge(scene, ima, obedit, em, co, hit);
        hit->l = NULL;
        hit->luv = hit->luv_next = NULL;
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                uv_poly_center(efa, cent, cd_loop_uv_offset);
@@ -832,7 +773,6 @@ static void uv_find_nearest_face(Scene *scene, Image *ima, BMEditMesh *em, const
                dist = len_manhattan_v2v2(co, cent);
 
                if (dist < mindist) {
-                       hit->tf = tf;
                        hit->efa = efa;
                        mindist = dist;
                }
@@ -850,22 +790,21 @@ static bool uv_nearest_between(const BMLoop *l, const float co[2],
                (line_point_side_v2(uv_next, uv_curr, co) <= 0.0f));
 }
 
-void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em,
-                          float const co[2], const float penalty[2], NearestHit *hit)
+void uv_find_nearest_vert(
+        Scene *scene, Image *ima, Object *obedit, BMEditMesh *em,
+        float const co[2], const float penalty[2], NearestHit *hit)
 {
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        float mindist, dist;
        int i;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        /*this will fill in hit.vert1 and hit.vert2*/
-       uv_find_nearest_edge(scene, ima, em, co, hit);
+       uv_find_nearest_edge(scene, ima, obedit, em, co, hit);
        hit->l = NULL;
        hit->luv = hit->luv_next = NULL;
 
@@ -875,8 +814,7 @@ void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em,
        BM_mesh_elem_index_ensure(em->bm, BM_VERT);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
@@ -898,7 +836,6 @@ void uv_find_nearest_vert(Scene *scene, Image *ima, BMEditMesh *em,
                                hit->l = l;
                                hit->luv = luv;
                                hit->luv_next = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset);
-                               hit->tf = tf;
                                hit->efa = efa;
                                hit->lindex = i;
                        }
@@ -912,20 +849,17 @@ bool ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, const float
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        float mindist, dist;
        bool found = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        mindist = 1e10f;
        copy_v2_v2(r_uv, co);
        
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
                
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1029,13 +963,13 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, UvMapVert *first1,
        return true;
 }
 
-static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestHit *hit,
-                              const float limit[2], const bool extend)
+static int uv_select_edgeloop(
+        Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, NearestHit *hit,
+        const float limit[2], const bool extend)
 {
        BMFace *efa;
        BMIter iter, liter;
        BMLoop *l;
-       MTexPoly *tf;
        UvVertMap *vmap;
        UvMapVert *iterv_curr;
        UvMapVert *iterv_next;
@@ -1043,7 +977,6 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
        bool looking, select;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        /* setup */
        BM_mesh_elem_table_ensure(em->bm, BM_FACE);
@@ -1052,7 +985,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
        BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
 
        if (!extend) {
-               uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+               uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT);
        }
 
        BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false);
@@ -1076,9 +1009,7 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
                /* find correct valence edges which are not tagged yet, but connect to tagged one */
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (!BM_elem_flag_test(efa, BM_ELEM_TAG) && uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (!BM_elem_flag_test(efa, BM_ELEM_TAG) && uvedit_face_visible_test(scene, obedit, ima, efa)) {
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                                        /* check face not hidden and not tagged */
                                        if (!(iterv_curr = uv_select_edgeloop_vertex_map_get(vmap, efa, l)))
@@ -1133,12 +1064,13 @@ static int uv_select_edgeloop(Scene *scene, Image *ima, BMEditMesh *em, NearestH
 
 /*********************** linked select ***********************/
 
-static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const float limit[2], NearestHit *hit, bool extend, bool select_faces)
+static void uv_select_linked(
+        Scene *scene, Image *ima, Object *obedit, BMEditMesh *em,
+        const float limit[2], NearestHit *hit, bool extend, bool select_faces)
 {
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        UvVertMap *vmap;
        UvMapVert *vlist, *iterv, *startv;
@@ -1147,7 +1079,6 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
        char *flag;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */
 
@@ -1167,9 +1098,7 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
 
        if (!hit) {
                BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
                                if (select_faces) {
                                        if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
                                                stack[stacksize] = a;
@@ -1327,18 +1256,15 @@ static void uv_select_linked(Scene *scene, Image *ima, BMEditMesh *em, const flo
 
 /* WATCH IT: this returns first selected UV,
  * not ideal in many cases since there could be multiple */
-static float *uv_sel_co_from_eve(Scene *scene, Image *ima, BMEditMesh *em, BMVert *eve)
+static float *uv_sel_co_from_eve(Scene *scene, Object *obedit, Image *ima, BMEditMesh *em, BMVert *eve)
 {
        BMIter liter;
        BMLoop *l;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) {
-               MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
-               if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
                        continue;
 
                if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1364,7 +1290,6 @@ static int uv_select_more_less(bContext *C, const bool select)
        ToolSettings *ts = scene->toolsettings;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        if (ts->uv_flag & UV_SYNC_SELECTION) {
                if (select) {
@@ -1385,9 +1310,7 @@ static int uv_select_more_less(bContext *C, const bool select)
 
                /* mark loops to be selected */
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
 
 #define IS_SEL   1
 #define IS_UNSEL 2
@@ -1430,9 +1353,7 @@ static int uv_select_more_less(bContext *C, const bool select)
 
                /* mark loops to be selected */
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
 
                                        MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -1499,11 +1420,9 @@ static void uv_weld_align(bContext *C, int tool)
        SpaceImage *sima;
        Scene *scene;
        Image *ima;
-       MTexPoly *tf;
        float cent[2], min[2], max[2];
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        scene = CTX_data_scene(C);
        ima = CTX_data_edit_image(C);
@@ -1517,9 +1436,7 @@ static void uv_weld_align(bContext *C, int tool)
                BMLoop *l;
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1533,7 +1450,7 @@ static void uv_weld_align(bContext *C, int tool)
                tool = (max[0] - min[0] >= max[1] - min[1]) ? 'y' : 'x';
        }
 
-       uvedit_center(scene, ima, obedit, cent, 0);
+       ED_uvedit_center(scene, ima, obedit, cent, 0);
 
        if (tool == 'x' || tool == 'w') {
                BMIter iter, liter;
@@ -1541,8 +1458,7 @@ static void uv_weld_align(bContext *C, int tool)
                BMLoop *l;
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1561,8 +1477,7 @@ static void uv_weld_align(bContext *C, int tool)
                BMLoop *l;
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1588,9 +1503,7 @@ static void uv_weld_align(bContext *C, int tool)
                /* tag verts with a selected UV */
                BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                        BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) {
-                               tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
-                               if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+                               if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
                                        continue;
 
                                if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1657,8 +1570,10 @@ static void uv_weld_align(bContext *C, int tool)
                        if (BLI_array_count(eve_line) > 2) {
 
                                /* we know the returns from these must be valid */
-                               const float *uv_start = uv_sel_co_from_eve(scene, ima, em, eve_line[0]);
-                               const float *uv_end   = uv_sel_co_from_eve(scene, ima, em, eve_line[BLI_array_count(eve_line) - 1]);
+                               const float *uv_start = uv_sel_co_from_eve(
+                                       scene, obedit, ima, em, eve_line[0]);
+                               const float *uv_end   = uv_sel_co_from_eve(
+                                       scene, obedit, ima, em, eve_line[BLI_array_count(eve_line) - 1]);
                                /* For t & u modes */
                                float a = 0.0f;
 
@@ -1678,9 +1593,7 @@ static void uv_weld_align(bContext *C, int tool)
                                /* go over all verts except for endpoints */
                                for (i = 0; i < BLI_array_count(eve_line); i++) {
                                        BM_ITER_ELEM (l, &liter, eve_line[i], BM_LOOPS_OF_VERT) {
-                                               tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
-                                               if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+                                               if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
                                                        continue;
 
                                                if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1714,7 +1627,7 @@ static void uv_weld_align(bContext *C, int tool)
 
 
        uvedit_live_unwrap_update(sima, scene, obedit);
-       DAG_id_tag_update(obedit->data, 0);
+       DEG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
 }
 
@@ -1766,7 +1679,6 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
        Object *obedit = CTX_data_edit_object(C);
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
        Image *ima;
-       MTexPoly *tf;
        int uv_a_index;
        int uv_b_index;
        float *uv_a;
@@ -1777,7 +1689,6 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
        BMLoop *l;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        sima = CTX_wm_space_image(C);
        scene = CTX_data_scene(C);
@@ -1791,8 +1702,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
 
                /* TODO, use qsort as with MESH_OT_remove_doubles, this isn't optimal */
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1854,8 +1764,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
                BLI_array_declare(loop_arr_unselected);
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1892,7 +1801,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
        }
 
        uvedit_live_unwrap_update(sima, scene, obedit);
-       DAG_id_tag_update(obedit->data, 0);
+       DEG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
@@ -1939,17 +1848,15 @@ static void UV_OT_weld(wmOperatorType *ot)
 
 /* ******************** (de)select all operator **************** */
 
-static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int action)
+static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, int action)
 {
        ToolSettings *ts = scene->toolsettings;
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        if (ts->uv_flag & UV_SYNC_SELECTION) {
 
@@ -1973,9 +1880,7 @@ static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int
                if (action == SEL_TOGGLE) {
                        action = SEL_SELECT;
                        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-       
-                               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                        continue;
 
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1991,9 +1896,7 @@ static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int
        
                
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
 
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2024,7 +1927,7 @@ static int uv_select_all_exec(bContext *C, wmOperator *op)
 
        int action = RNA_enum_get(op->ptr, "action");
 
-       uv_select_all_perform(scene, ima, em, action);
+       uv_select_all_perform(scene, ima, obedit, em, action);
 
        WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
 
@@ -2082,7 +1985,6 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        NearestHit hit;
        int i, selectmode, sticky, sync, *hitv = NULL;
@@ -2092,7 +1994,6 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        float penalty[2];
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        /* notice 'limit' is the same no matter the zoom level, since this is like
         * remove doubles and could annoying if it joined points when zoomed out.
@@ -2125,7 +2026,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        /* find nearest element */
        if (loop) {
                /* find edge */
-               uv_find_nearest_edge(scene, ima, em, co, &hit);
+               uv_find_nearest_edge(scene, ima, obedit, em, co, &hit);
                if (hit.efa == NULL) {
                        return OPERATOR_CANCELLED;
                }
@@ -2134,7 +2035,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        }
        else if (selectmode == UV_SELECT_VERTEX) {
                /* find vertex */
-               uv_find_nearest_vert(scene, ima, em, co, penalty, &hit);
+               uv_find_nearest_vert(scene, ima, obedit, em, co, penalty, &hit);
                if (hit.efa == NULL) {
                        return OPERATOR_CANCELLED;
                }
@@ -2151,7 +2052,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        }
        else if (selectmode == UV_SELECT_EDGE) {
                /* find edge */
-               uv_find_nearest_edge(scene, ima, em, co, &hit);
+               uv_find_nearest_edge(scene, ima, obedit, em, co, &hit);
                if (hit.efa == NULL) {
                        return OPERATOR_CANCELLED;
                }
@@ -2170,7 +2071,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        }
        else if (selectmode == UV_SELECT_FACE) {
                /* find face */
-               uv_find_nearest_face(scene, ima, em, co, &hit);
+               uv_find_nearest_face(scene, ima, obedit, em, co, &hit);
                if (hit.efa == NULL) {
                        return OPERATOR_CANCELLED;
                }
@@ -2191,7 +2092,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
                hitlen = hit.efa->len;
        }
        else if (selectmode == UV_SELECT_ISLAND) {
-               uv_find_nearest_edge(scene, ima, em, co, &hit);
+               uv_find_nearest_edge(scene, ima, obedit, em, co, &hit);
 
                if (hit.efa == NULL) {
                        return OPERATOR_CANCELLED;
@@ -2206,10 +2107,10 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
 
        /* do selection */
        if (loop) {
-               flush = uv_select_edgeloop(scene, ima, em, &hit, limit, extend);
+               flush = uv_select_edgeloop(scene, ima, obedit, em, &hit, limit, extend);
        }
        else if (selectmode == UV_SELECT_ISLAND) {
-               uv_select_linked(scene, ima, em, limit, &hit, extend, false);
+               uv_select_linked(scene, ima, obedit, em, limit, &hit, extend, false);
        }
        else if (extend) {
                if (selectmode == UV_SELECT_VERTEX) {
@@ -2244,8 +2145,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
                        BM_mesh_elem_index_ensure(em->bm, BM_VERT);
 
                        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                        continue;
 
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2260,7 +2160,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
        }
        else {
                /* deselect all */
-               uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+               uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT);
 
                if (selectmode == UV_SELECT_VERTEX) {
                        /* select vertex */
@@ -2280,8 +2180,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
                /* select sticky uvs */
                if (sticky != SI_STICKY_DISABLE) {
                        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                        continue;
                                
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2324,7 +2223,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
 #endif
        }
 
-       DAG_id_tag_update(obedit->data, 0);
+       DEG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
 
        return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
@@ -2457,13 +2356,13 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
                        RNA_float_get_array(op->ptr, "location", co);
                }
 
-               uv_find_nearest_edge(scene, ima, em, co, &hit);
+               uv_find_nearest_edge(scene, ima, obedit, em, co, &hit);
                hit_p = &hit;
        }
 
-       uv_select_linked(scene, ima, em, limit, hit_p, extend, select_faces);
+       uv_select_linked(scene, ima, obedit, em, limit, hit_p, extend, select_faces);
 
-       DAG_id_tag_update(obedit->data, 0);
+       DEG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
 
        return OPERATOR_FINISHED;
@@ -2537,12 +2436,10 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        bool changed = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
 
        if (ts->uv_flag & UV_SYNC_SELECTION) {
                BKE_report(op->reports, RPT_ERROR, "Cannot split selection when sync selection is enabled");
@@ -2554,9 +2451,8 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
                bool is_sel = false;
                bool is_unsel = false;
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
 
-               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                /* are we all selected? */
@@ -2697,7 +2593,6 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       /* MTexPoly *tf; */
        const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
        
        if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_VERTEX) {
@@ -2782,7 +2677,6 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       /* MTexPoly *tf; */
 
        const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
 
@@ -2862,7 +2756,6 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tf;
        MLoopUV *luv;
        rctf rectf;
        bool changed, pinned, select, extend;
@@ -2871,7 +2764,6 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
                                    (ts->uv_selectmode == UV_SELECT_FACE);
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        /* get rectangle from operator */
        WM_operator_properties_border_to_rctf(op, &rectf);
@@ -2883,7 +2775,7 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
        pinned = RNA_boolean_get(op->ptr, "pinned");
 
        if (!extend)
-               uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+               uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT);
 
        /* do actual selection */
        if (use_face_center && !pinned) {
@@ -2896,8 +2788,7 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
                        /* assume not touched */
                        BM_elem_flag_disable(efa, BM_ELEM_TAG);
 
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
                                uv_poly_center(efa, cent, cd_loop_uv_offset);
                                if (BLI_rctf_isect_pt_v(&rectf, cent)) {
                                        BM_elem_flag_enable(efa, BM_ELEM_TAG);
@@ -2917,8 +2808,7 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
                BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                                continue;
                        BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                                luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -3118,13 +3008,11 @@ static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mo
                (ts->uv_selectmode == UV_SELECT_FACE));
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BMIter iter, liter;
 
        BMFace *efa;
        BMLoop *l;
-       MTexPoly *tf;
        int screen_uv[2];
        bool changed = false;
        rcti rect;
@@ -3132,7 +3020,7 @@ static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mo
        BLI_lasso_boundbox(&rect, mcords, moves);
 
        if (!extend && select) {
-               uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+               uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT);
        }
 
        if (use_face_center) { /* Face Center Sel */
@@ -3162,8 +3050,7 @@ static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short mo
                BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
 
                BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-                       tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-                       if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+                       if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
                                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                                        if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) {
                                                MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -3258,7 +3145,7 @@ static void uv_snap_cursor_to_pixels(SpaceImage *sima)
 
 static bool uv_snap_cursor_to_selection(Scene *scene, Image *ima, Object *obedit, SpaceImage *sima)
 {
-       return uvedit_center(scene, ima, obedit, sima->cursor, sima->around);
+       return ED_uvedit_center(scene, ima, obedit, sima->cursor, sima->around);
 }
 
 static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
@@ -3316,16 +3203,13 @@ static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, cons
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tface;
        MLoopUV *luv;
        bool changed = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tface))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3346,16 +3230,13 @@ static bool uv_snap_uvs_offset(Scene *scene, Image *ima, Object *obedit, const f
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *mtexpoly;
        MLoopUV *luv;
        bool changed = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               mtexpoly = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, mtexpoly))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3377,17 +3258,14 @@ static bool uv_snap_uvs_to_adjacent_unselected(Scene *scene, Image *ima, Object
        BMFace *f;
        BMLoop *l, *lsub;
        BMIter iter, liter, lsubiter;
-       MTexPoly *tface;
        MLoopUV *luv;
        bool changed = false;
        const int cd_loop_uv_offset  = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
        
        /* index every vert that has a selected UV using it, but only once so as to
         * get unique indices and to count how much to malloc */
        BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-               tface = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset);
-               if (uvedit_face_visible_test(scene, ima, f, tface)) {
+               if (uvedit_face_visible_test(scene, obedit, ima, f)) {
                        BM_elem_flag_enable(f, BM_ELEM_TAG);
                        BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
                                BM_elem_flag_set(l, BM_ELEM_TAG, uvedit_uv_select_test(scene, l, cd_loop_uv_offset));
@@ -3435,22 +3313,19 @@ static bool uv_snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tface;
        MLoopUV *luv;
        int width = 0, height = 0;
        float w, h;
        bool changed = false;
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        ED_space_image_get_size(sima, &width, &height);
        w = (float)width;
        h = (float)height;
        
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tface))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3484,7 +3359,7 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
                case 2:
                {
                        float center[2];
-                       if (uvedit_center(scene, ima, obedit, center, sima->around)) {
+                       if (ED_uvedit_center(scene, ima, obedit, center, sima->around)) {
                                float offset[2];
                                sub_v2_v2v2(offset, sima->cursor, center);
                                changed = uv_snap_uvs_offset(scene, ima, obedit, offset);
@@ -3500,7 +3375,7 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
 
        uvedit_live_unwrap_update(sima, scene, obedit);
-       DAG_id_tag_update(obedit->data, 0);
+       DEG_id_tag_update(obedit->data, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
@@ -3540,16 +3415,13 @@ static int uv_pin_exec(bContext *C, wmOperator *op)
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tface;
        MLoopUV *luv;
        const bool clear = RNA_boolean_get(op->ptr, "clear");
        
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tface))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3598,15 +3470,12 @@ static int uv_select_pinned_exec(bContext *C, wmOperator *UNUSED(op))
        BMFace *efa;
        BMLoop *l;
        BMIter iter, liter;
-       MTexPoly *tface;
        MLoopUV *luv;
        
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-               tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-               if (!uvedit_face_visible_test(scene, ima, efa, tface))
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa))
                        continue;
 
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3670,13 +3539,11 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
        BMLoop *l;
        BMIter iter, liter;
        MLoopUV *luv;
-       MTexPoly *tf;
        const bool swap = RNA_boolean_get(op->ptr, "unselected");
        Image *ima = sima ? sima->image : NULL;
        const int use_face_center = (ts->uv_selectmode == UV_SELECT_FACE);
 
        const int cd_loop_uv_offset  = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
-       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
 
        if (ts->uv_flag & UV_SYNC_SELECTION) {
                EDBM_mesh_hide(em, swap);
@@ -3688,9 +3555,7 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
        BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
                int hide = 0;
 
-               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
-               if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
+               if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
                        continue;
                }
 
@@ -3971,73 +3836,6 @@ static void UV_OT_cursor_set(wmOperatorType *ot)
                             "Cursor location in normalized (0.0-1.0) coordinates", -10.0f, 10.0f);
 }
 
-/********************** set tile operator **********************/
-
-static int set_tile_exec(bContext *C, wmOperator *op)
-{
-       Image *ima = CTX_data_edit_image(C);
-       int tile[2];
-       Object *obedit = CTX_data_edit_object(C);
-
-       RNA_int_get_array(op->ptr, "tile", tile);
-
-       if (uvedit_set_tile(obedit, ima, tile[0] + ima->xrep * tile[1])) {
-               WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
-               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL);
-
-               return OPERATOR_FINISHED;
-       }
-       
-       return OPERATOR_CANCELLED;
-}
-
-static int set_tile_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
-       SpaceImage *sima = CTX_wm_space_image(C);
-       Image *ima = CTX_data_edit_image(C);
-       ARegion *ar = CTX_wm_region(C);
-       float fx, fy;
-       int tile[2];
-
-       if (!ima || !(ima->tpageflag & IMA_TILES))
-               return OPERATOR_CANCELLED;
-
-       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
-
-       if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
-               fx = fx * ima->xrep;
-               fy = fy * ima->yrep;
-               
-               tile[0] = fx;
-               tile[1] = fy;
-               
-               sima->curtile = tile[1] * ima->xrep + tile[0];
-               RNA_int_set_array(op->ptr, "tile", tile);
-       }
-
-       return set_tile_exec(C, op);
-}
-
-static void UV_OT_tile_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Set Tile";
-       ot->description = "Set UV image tile coordinates";
-       ot->idname = "UV_OT_tile_set";
-       
-       /* api callbacks */
-       ot->exec = set_tile_exec;
-       ot->invoke = set_tile_invoke;
-       ot->poll = ED_operator_image_active;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       /* properties */
-       RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate", 0, 10);
-}
-
-
 static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
 {
        UvVertMap *vmap;
@@ -4055,7 +3853,7 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
        em = me->edit_btmesh;
        bm = em->bm;
 
-       if (!EDBM_mtexpoly_check(em)) {
+       if (!EDBM_uv_check(em)) {
                return OPERATOR_CANCELLED;
        }
 
@@ -4147,7 +3945,7 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
 
        BM_uv_vert_map_free(vmap);
 
-       DAG_id_tag_update(&me->id, 0);
+       DEG_id_tag_update(&me->id, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
 
        return OPERATOR_FINISHED;
@@ -4199,7 +3997,7 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
        if (scene->toolsettings->edge_mode_live_unwrap)
                ED_unwrap_lscm(scene, ob, false);
 
-       DAG_id_tag_update(&me->id, 0);
+       DEG_id_tag_update(&me->id, 0);
        WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
 
        return OPERATOR_FINISHED;
@@ -4289,7 +4087,6 @@ void ED_operatortypes_uvedit(void)
        WM_operatortype_append(UV_OT_hide);
 
        WM_operatortype_append(UV_OT_cursor_set);
-       WM_operatortype_append(UV_OT_tile_set);
 }
 
 void ED_keymap_uvedit(wmKeyConfig *keyconf)
@@ -4369,7 +4166,6 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
 
        /* cursor */
        WM_keymap_add_item(keymap, "UV_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "UV_OT_tile_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
        
        /* menus */
        WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_snap", SKEY, KM_PRESS, KM_SHIFT, 0);