[Bf-blender-cvs] [43f53078a20] greasepencil-object: GPencil: New operator to clear UV transformations

Antonio Vazquez noreply at git.blender.org
Wed Oct 2 15:43:12 CEST 2019


Commit: 43f53078a20d3d9621404541eda4a75a0bfa2b1a
Author: Antonio Vazquez
Date:   Wed Oct 2 11:04:14 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB43f53078a20d3d9621404541eda4a75a0bfa2b1a

GPencil: New operator to clear UV transformations

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_uv.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index aca8ea701ce..5a7935c4aa5 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4585,6 +4585,7 @@ class VIEW3D_MT_edit_gpencil_stroke(Menu):
         layout.menu("GPENCIL_MT_move_to_layer")
         layout.menu("VIEW3D_MT_assign_material")
         layout.operator("gpencil.set_active_material", text="Set as Active Material")
+        layout.operator_menu_enum("gpencil.clear_uv_transform", "mode", text="Clear UV Transform")
         layout.operator_menu_enum("gpencil.stroke_arrange", "direction", text="Arrange Strokes")
 
         layout.separator()
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index be526186709..9ecb58f0f65 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -493,6 +493,7 @@ void GPENCIL_OT_stroke_trim(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_merge_by_distance(struct wmOperatorType *ot);
 
 void GPENCIL_OT_transform_uv(struct wmOperatorType *ot);
+void GPENCIL_OT_clear_uv_transform(struct wmOperatorType *ot);
 
 void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 6c960bd46e7..7f7bbb9fb3b 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -323,6 +323,7 @@ void ED_operatortypes_gpencil(void)
   WM_operatortype_append(GPENCIL_OT_stroke_merge_by_distance);
 
   WM_operatortype_append(GPENCIL_OT_transform_uv);
+  WM_operatortype_append(GPENCIL_OT_clear_uv_transform);
 
   WM_operatortype_append(GPENCIL_OT_brush_presets_create);
 
diff --git a/source/blender/editors/gpencil/gpencil_uv.c b/source/blender/editors/gpencil/gpencil_uv.c
index 78cbdd93b0f..f57e7137666 100644
--- a/source/blender/editors/gpencil/gpencil_uv.c
+++ b/source/blender/editors/gpencil/gpencil_uv.c
@@ -81,6 +81,7 @@ enum {
   GP_UV_ROTATE = 0,
   GP_UV_TRANSLATE = 1,
   GP_UV_SCALE = 2,
+  GP_UV_ALL = 3,
 };
 
 #define SMOOTH_FACTOR 0.3f
@@ -531,3 +532,65 @@ void GPENCIL_OT_transform_uv(wmOperatorType *ot)
   prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "");
   RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 }
+
+/* Clear UV transformations. */
+static int gpencil_clear_uv_transform_exec(bContext *C, wmOperator *op)
+{
+  const int mode = RNA_enum_get(op->ptr, "mode");
+  Object *ob = CTX_data_active_object(C);
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bool changed = false;
+
+  /* Loop all selected strokes and reset. */
+  GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
+    if (gps->flag & GP_STROKE_SELECT) {
+      if ((mode == GP_UV_TRANSLATE) || (mode == GP_UV_ALL)) {
+        zero_v2(gps->uv_translation);
+      }
+      if ((mode == GP_UV_ROTATE) || (mode == GP_UV_ALL)) {
+        gps->uv_rotation = 0.0f;
+      }
+      if ((mode == GP_UV_SCALE) || (mode == GP_UV_ALL)) {
+        gps->uv_scale = 1.0f;
+      }
+      gps->tot_triangles = 0;
+      changed = true;
+      break;
+    }
+  }
+  GP_EDITABLE_STROKES_END(gpstroke_iter);
+
+  /* notifiers */
+  if (changed) {
+    DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
+    WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_clear_uv_transform(wmOperatorType *ot)
+{
+  static const EnumPropertyItem uv_clear_mode[] = {
+      {GP_UV_ALL, "ALL", 0, "All", ""},
+      {GP_UV_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
+      {GP_UV_ROTATE, "ROTATE", 0, "Rotate", ""},
+      {GP_UV_SCALE, "SCALE", 0, "Scale", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  /* identifiers */
+  ot->name = "Clear UV Transformations";
+  ot->idname = "GPENCIL_OT_clear_uv_transform";
+  ot->description = "Reset any UV transformation and back to default values";
+
+  /* callbacks */
+  ot->exec = gpencil_clear_uv_transform_exec;
+  ot->poll = gpencil_uv_transform_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  /* properties */
+  ot->prop = RNA_def_enum(ot->srna, "mode", uv_clear_mode, 0, "Mode", "");
+}



More information about the Bf-blender-cvs mailing list