snap to cursor (offset option) added for UV's too.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 21 Jul 2013 16:45:38 +0000 (16:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 21 Jul 2013 16:45:38 +0000 (16:45 +0000)
release/scripts/startup/bl_ui/space_image.py
source/blender/editors/uvedit/uvedit_ops.c

index eb0d9c5082dfb34d075f091b01402032de09613a..22e2e6e08a2a533cbe16edbbb858cbffccc42462 100644 (file)
@@ -232,6 +232,7 @@ class IMAGE_MT_uvs_snap(Menu):
 
         layout.operator("uv.snap_selected", text="Selected to Pixels").target = 'PIXELS'
         layout.operator("uv.snap_selected", text="Selected to Cursor").target = 'CURSOR'
+        layout.operator("uv.snap_selected", text="Selected to Cursor (Offset)").target = 'CURSOR_OFFSET'
         layout.operator("uv.snap_selected", text="Selected to Adjacent Unselected").target = 'ADJACENT_UNSELECTED'
 
         layout.separator()
index 1ed00c3aa20156f351caa32de70203543a92ca03..0f7caf126d333a8ab160ad5d4e6a6cf26fcaf64c 100644 (file)
@@ -3226,7 +3226,7 @@ static void UV_OT_snap_cursor(wmOperatorType *ot)
 
 /* ******************** snap selection operator **************** */
 
-static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, SpaceImage *sima)
+static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, const float cursor[2])
 {
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
        BMFace *efa;
@@ -3247,7 +3247,37 @@ static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, Spac
                BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
                        if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
                                luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                               copy_v2_v2(luv->uv, sima->cursor);
+                               copy_v2_v2 (luv->uv, cursor);
+                               change = true;
+                       }
+               }
+       }
+
+       return change;
+}
+
+static bool uv_snap_uvs_offset(Scene *scene, Image *ima, Object *obedit, const float offset[2])
+{
+       BMEditMesh *em = BKE_editmesh_from_object(obedit);
+       BMFace *efa;
+       BMLoop *l;
+       BMIter iter, liter;
+       MTexPoly *tface;
+       MLoopUV *luv;
+       bool change = 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))
+                       continue;
+
+               BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+                       if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
+                               luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+                               add_v2_v2(luv->uv, offset);
                                change = true;
                        }
                }
@@ -3365,9 +3395,19 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
                        change = uv_snap_uvs_to_pixels(sima, scene, obedit);
                        break;
                case 1:
-                       change = uv_snap_uvs_to_cursor(scene, ima, obedit, sima);
+                       change = uv_snap_uvs_to_cursor(scene, ima, obedit, sima->cursor);
                        break;
                case 2:
+               {
+                       float center[2];
+                       if (uvedit_center(scene, ima, obedit, center, sima->around)) {
+                               float offset[2];
+                               sub_v2_v2v2(offset, sima->cursor, center);
+                               change = uv_snap_uvs_offset(scene, ima, obedit, offset);
+                       }
+                       break;
+               }
+               case 3:
                        change = uv_snap_uvs_to_adjacent_unselected(scene, ima, obedit);
                        break;
        }
@@ -3387,7 +3427,8 @@ static void UV_OT_snap_selected(wmOperatorType *ot)
        static EnumPropertyItem target_items[] = {
                {0, "PIXELS", 0, "Pixels", ""},
                {1, "CURSOR", 0, "Cursor", ""},
-               {2, "ADJACENT_UNSELECTED", 0, "Adjacent Unselected", ""},
+               {2, "CURSOR_OFFSET", 0, "Cursor (Offset)", ""},
+               {3, "ADJACENT_UNSELECTED", 0, "Adjacent Unselected", ""},
                {0, NULL, 0, NULL, NULL}};
 
        /* identifiers */