[Bf-blender-cvs] [19b63b932d2] master: Fix transform gizmo not updating according to state

Germano Cavalcante noreply at git.blender.org
Fri Feb 3 15:07:11 CET 2023


Commit: 19b63b932d2b799c7904ebaf59911aef4926dcbb
Author: Germano Cavalcante
Date:   Thu Jan 26 07:54:04 2023 -0300
Branches: master
https://developer.blender.org/rB19b63b932d2b799c7904ebaf59911aef4926dcbb

Fix transform gizmo not updating according to state

Whenever a transform operation is activated by gizmo, the gizmo
modal is maintained, but its drawing remains the same even if the
transform mode or constrain is changed.

So update the gizmo according to the mode or constrain set.

NOTE: Currently only 3D view gizmo is affected

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/transform/transform_mode.c
M	source/blender/windowmanager/gizmo/WM_gizmo_api.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 3cff4c11cad..7f16a5796ba 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -862,6 +862,9 @@ static bool transform_event_modal_constraint(TransInfo *t, short modal_type)
     else {
       setUserConstraint(t, constraint_new, msg_3d);
     }
+
+    /* Take the opportunity to update the gizmo. */
+    transform_gizmo_3d_model_from_constraint_and_mode_set(t);
   }
   t->redraw |= TREDRAW_HARD;
   return true;
@@ -2057,6 +2060,8 @@ int transformEnd(bContext *C, TransInfo *t)
     viewRedrawPost(C, t);
 
     viewRedrawForce(C, t);
+
+    transform_gizmo_3d_model_from_constraint_and_mode_restore(t);
   }
 
   t->context = NULL;
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 82ab9039db5..08f560d16e9 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -138,6 +138,9 @@ typedef enum {
 
   /** No cursor wrapping on region bounds */
   T_NO_CURSOR_WRAP = 1 << 23,
+
+  /** Do not display Xform gizmo even though it is available. */
+  T_NO_GIZMO = 1 << 24,
 } eTFlag;
 ENUM_OPERATORS(eTFlag, T_NO_CURSOR_WRAP);
 
@@ -734,6 +737,27 @@ void transform_final_value_get(const TransInfo *t, float *value, int value_num);
 bool gimbal_axis_pose(struct Object *ob, const struct bPoseChannel *pchan, float gmat[3][3]);
 bool gimbal_axis_object(struct Object *ob, float gmat[3][3]);
 
+/**
+ * Set the #T_NO_GIZMO flag.
+ *
+ * \note This maintains the conventional behavior of not displaying the gizmo if the operator has
+ * been triggered by shortcuts.
+ */
+void transform_gizmo_3d_model_from_constraint_and_mode_init(TransInfo *t);
+
+/**
+ * Change the gizmo and its orientation to match the transform state.
+ *
+ * \note This used while the modal operator is running so changes to the constraint or mode show
+ * the gizmo associated with that state, as if it had been the initial gizmo dragged.
+ */
+void transform_gizmo_3d_model_from_constraint_and_mode_set(TransInfo *t);
+
+/**
+ * Restores the non-modal state of the gizmo.
+ */
+void transform_gizmo_3d_model_from_constraint_and_mode_restore(TransInfo *t);
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 53e346ee86a..d1f210ca772 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -640,6 +640,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 
   setTransformViewMatrices(t);
   initNumInput(&t->num);
+
+  transform_gizmo_3d_model_from_constraint_and_mode_init(t);
 }
 
 static void freeTransCustomData(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data)
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index 28b39786bbc..306502ab3bc 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -70,9 +70,13 @@
 
 #include "GPU_state.h"
 
-static void gizmo_refresh_from_matrix(wmGizmoGroup *gzgroup,
-                                      const float twmat[4][4],
-                                      const float scale[3]);
+static wmGizmoGroupType *g_GGT_xform_gizmo = NULL;
+static wmGizmoGroupType *g_GGT_xform_gizmo_context = NULL;
+
+static void gizmogroup_refresh_from_matrix(wmGizmoGroup *gzgroup,
+                                           const float twmat[4][4],
+                                           const float scale[3],
+                                           const bool ignore_hidden);
 
 /* return codes for select, and drawing flags */
 
@@ -1135,30 +1139,36 @@ static void gizmo_prepare_mat(const bContext *C,
  * Sets up \a r_start and \a r_len to define arrow line range.
  * Needed to adjust line drawing for combined gizmo axis types.
  */
-static void gizmo_line_range(const int twtype, const short axis_type, float *r_start, float *r_len)
+static void gizmo_line_range(const int twtype, const short axis_type, float *r_start, float *r_end)
 {
-  const float ofs = 0.2f;
-
-  *r_start = 0.2f;
-  *r_len = 1.0f;
+  float start = 0.2f;
+  float end = 1.0f;
 
   switch (axis_type) {
     case MAN_AXES_TRANSLATE:
       if (twtype & V3D_GIZMO_SHOW_OBJECT_SCALE) {
-        *r_start = *r_len - ofs + 0.075f;
+        start = end - 0.125f;
       }
       if (twtype & V3D_GIZMO_SHOW_OBJECT_ROTATE) {
-        *r_len += ofs;
+        /* Avoid rotate and translate gizmos overlap. */
+        const float rotate_offset = 0.215f;
+        start += rotate_offset;
+        end += rotate_offset + 0.2f;
       }
       break;
     case MAN_AXES_SCALE:
       if (twtype & (V3D_GIZMO_SHOW_OBJECT_TRANSLATE | V3D_GIZMO_SHOW_OBJECT_ROTATE)) {
-        *r_len -= ofs + 0.025f;
+        end -= 0.225f;
       }
       break;
   }
 
-  *r_len -= *r_start;
+  if (r_start) {
+    *r_start = start;
+  }
+  if (r_end) {
+    *r_end = end;
+  }
 }
 
 static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
@@ -1280,9 +1290,9 @@ static void gizmo_xform_message_subscribe(wmGizmoGroup *gzgroup,
 }
 
 static void gizmo_3d_dial_matrixbasis_calc(const ARegion *region,
-                                           float axis[3],
-                                           float center_global[3],
-                                           float mval_init[2],
+                                           const float axis[3],
+                                           const float center_global[3],
+                                           const float mval_init[2],
                                            float r_mat_basis[4][4])
 {
   copy_v3_v3(r_mat_basis[2], axis);
@@ -1329,6 +1339,169 @@ static void rotation_set_fn(const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop,
   ggd->rotation = *(const float *)value;
 }
 
+static void gizmo_3d_setup_draw_default(wmGizmo *axis, const int axis_idx)
+{
+  switch (axis_idx) {
+    /* Arrow. */
+    case MAN_AXIS_TRANS_X:
+    case MAN_AXIS_TRANS_Y:
+    case MAN_AXIS_TRANS_Z:
+      RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_NORMAL);
+      break;
+    case MAN_AXIS_SCALE_X:
+    case MAN_AXIS_SCALE_Y:
+    case MAN_AXIS_SCALE_Z:
+      RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_BOX);
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_ARROW_DRAW_FLAG_STEM);
+      break;
+
+    /* Primitive. */
+    case MAN_AXIS_TRANS_XY:
+    case MAN_AXIS_TRANS_YZ:
+    case MAN_AXIS_TRANS_ZX:
+    case MAN_AXIS_SCALE_XY:
+    case MAN_AXIS_SCALE_YZ:
+    case MAN_AXIS_SCALE_ZX: {
+      RNA_enum_set(axis->ptr, "draw_style", ED_GIZMO_PRIMITIVE_STYLE_PLANE);
+
+      const float ofs[3] = {MAN_AXIS_SCALE_PLANE_OFFSET, MAN_AXIS_SCALE_PLANE_OFFSET, 0.0f};
+      WM_gizmo_set_scale(axis, MAN_AXIS_SCALE_PLANE_SCALE);
+      WM_gizmo_set_matrix_offset_location(axis, ofs);
+      WM_gizmo_set_flag(axis, WM_GIZMO_DRAW_OFFSET_SCALE, true);
+      break;
+    }
+
+    /* Dial. */
+    case MAN_AXIS_TRANS_C:
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT);
+      WM_gizmo_set_flag(axis, WM_GIZMO_DRAW_MODAL, true);
+      WM_gizmo_set_scale(axis, 0.2f);
+
+      /* Prevent axis gizmos overlapping the center point, see: T63744. */
+      axis->select_bias = 2.0f;
+      break;
+    case MAN_AXIS_SCALE_C:
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL_SELECT);
+
+      /* Use 1/6 since this is '0.2' if the main scale is 1.2. */
+      RNA_float_set(axis->ptr, "arc_inner_factor", 1.0 / 6.0);
+      WM_gizmo_set_scale(axis, 1.2f);
+
+      /* Prevent axis gizmos overlapping the center point, see: T63744. */
+      axis->select_bias = -2.0f;
+      break;
+
+    case MAN_AXIS_ROT_X:
+    case MAN_AXIS_ROT_Y:
+    case MAN_AXIS_ROT_Z:
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_CLIP);
+      WM_gizmo_set_flag(axis, WM_GIZMO_DRAW_VALUE, true);
+      break;
+    case MAN_AXIS_ROT_C:
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_NOP);
+      WM_gizmo_set_flag(axis, WM_GIZMO_DRAW_VALUE, true);
+      WM_gizmo_set_scale(axis, 1.2f);
+      break;
+    case MAN_AXIS_ROT_T:
+      RNA_enum_set(axis->ptr, "draw_options", ED_GIZMO_DIAL_DRAW_FLAG_FILL);
+      WM_gizmo_set_flag(axis, WM_GIZMO_SELECT_BACKGROUND, true);
+      WM_gizmo_set_flag(axis, WM_GIZMO_DRAW_HOVER, true);
+      break;
+  }
+
+  switch (axis_idx) {
+    case MAN_AXIS_ROT_X:
+    case MAN_AXIS_ROT_Y:
+    case MAN_AXIS_ROT_Z:
+      /* Increased line width for better display. */
+      WM_gizmo_set_line_width(axis, GIZMO_AXIS_LINE_WIDTH + 1.0f);
+      break;
+    case MAN_AXIS_TRANS_XY:
+    case MAN_AXIS_TRANS_YZ:
+    case MAN_AXIS_TRANS_ZX:
+    case MAN_AXIS_SCALE_XY:
+    case MAN_AXIS_SCALE_YZ:
+    case MAN_AXIS_SCALE_ZX:
+      WM_gizmo_set_line_width(axis, 1.0f);
+      break;
+    default:
+      WM_gizmo_set_line_width(axis, GIZMO_AXIS_LINE_WIDTH);
+      break;
+  }
+
+  const short axis_type = gizmo_get_axis_type(axis_idx);
+  switch (axis_type) {
+    case MAN_AXES_ROTATE: {
+      RNA_float_set(axis->ptr, "incremental_angle", 0.0f);
+      axis->select_bias = 0.0f;
+      break;
+    }
+    default:
+      break;
+  }
+}
+
+static void gizmo_3d_setup_draw_from_twtype(wmGizmo *axis, const int axis_idx, const int twtype)
+{
+  switch (axis_idx) {
+    case MAN_AXIS_TRANS_X:
+    case MAN_AXIS_TRANS_Y:
+    case MAN_AXIS_TRANS_Z:
+      RNA_enum_set(axis->ptr,
+                   "draw_options",
+                   (twtype & (V3D_GIZMO_SHOW_OBJECT_ROTATE | V3D_GIZMO_SHOW_OBJECT_SCALE)) ?
+                       0 :
+                       ED_GIZMO_ARROW_DRAW_FLAG_STEM);
+      break;
+    default:
+      break;
+  }
+
+  const short axis_type = gizmo_get_axis_type(axis_idx);
+  switch (axis_idx) {
+    case MAN_AXIS_TRANS_X:
+    case MAN_AXIS_TRANS_Y:
+    case MAN_AXIS_TRANS_Z:
+    c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list