[Bf-blender-cvs] [3b7ac10d625] master: UV: add Snap Cursor to Origin

Tomek Gubala noreply at git.blender.org
Tue Jul 19 19:30:23 CEST 2022


Commit: 3b7ac10d6252a2a9cecbb9be7850a1dea41e281d
Author: Tomek Gubala
Date:   Tue Jul 19 19:24:20 2022 +0200
Branches: master
https://developer.blender.org/rB3b7ac10d6252a2a9cecbb9be7850a1dea41e281d

UV: add Snap Cursor to Origin

Similar to snapping to the world origin in the 3D viewport. This can be found
in the Shift+S pie menu and UV > Snap menu.

Differential Revision: https://developer.blender.org/D15055

===================================================================

M	release/scripts/startup/bl_ui/space_image.py
M	source/blender/editors/uvedit/uvedit_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index 5d25d02d98e..ab3c863ea2d 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -306,6 +306,7 @@ class IMAGE_MT_uvs_snap(Menu):
 
         layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
         layout.operator("uv.snap_cursor", text="Cursor to Selected").target = 'SELECTED'
+        layout.operator("uv.snap_cursor", text="Cursor to Origin").target = 'ORIGIN'
 
 
 class IMAGE_MT_uvs_mirror(Menu):
@@ -572,6 +573,11 @@ class IMAGE_MT_uvs_snap_pie(Menu):
             text="Selected to Adjacent Unselected",
             icon='RESTRICT_SELECT_OFF',
         ).target = 'ADJACENT_UNSELECTED'
+        pie.operator(
+            "uv.snap_cursor",
+            text="Cursor to Origin",
+            icon='PIVOT_CURSOR',
+        ).target = 'ORIGIN'
 
 
 class IMAGE_MT_view_pie(Menu):
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 4e99eb3fc0f..74a9989f550 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1036,6 +1036,12 @@ static bool uv_snap_cursor_to_selection(Scene *scene,
   return ED_uvedit_center_multi(scene, objects_edit, objects_len, sima->cursor, sima->around);
 }
 
+static void uv_snap_cursor_to_origin(float uvco[2])
+{
+  uvco[0] = 0;
+  uvco[1] = 0;
+}
+
 static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
 {
   SpaceImage *sima = CTX_wm_space_image(C);
@@ -1058,6 +1064,10 @@ static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
       MEM_freeN(objects);
       break;
     }
+    case 2:
+      uv_snap_cursor_to_origin(sima->cursor);
+      changed = true;
+      break;
   }
 
   if (!changed) {
@@ -1074,6 +1084,7 @@ static void UV_OT_snap_cursor(wmOperatorType *ot)
   static const EnumPropertyItem target_items[] = {
       {0, "PIXELS", 0, "Pixels", ""},
       {1, "SELECTED", 0, "Selected", ""},
+      {2, "ORIGIN", 0, "Origin", ""},
       {0, NULL, 0, NULL, NULL},
   };



More information about the Bf-blender-cvs mailing list