Dial3d Gizmo: Add the Incremental Angle option to snap.
authormano-wii <germano.costa@ig.com.br>
Wed, 3 Oct 2018 19:23:32 +0000 (16:23 -0300)
committermano-wii <germano.costa@ig.com.br>
Wed, 3 Oct 2018 20:45:55 +0000 (17:45 -0300)
source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c
source/blender/editors/include/ED_gizmo_library.h
source/blender/editors/include/ED_transform.h
source/blender/editors/transform/transform.c

index 7f8ff5363f164eaddd527a07bec671cb66eec0a1..3d9f5f1df6fed0f8e411486f81034343a70a233f 100644 (file)
@@ -61,6 +61,7 @@
 
 #include "ED_screen.h"
 #include "ED_view3d.h"
+#include "ED_transform.h"
 #include "ED_gizmo_library.h"
 
 /* own includes */
@@ -85,6 +86,7 @@ typedef struct DialInteraction {
        /* Number of full rotations. */
        int rotations;
        bool has_drag;
+       float angle_increment;
 
        /* Final output values, used for drawing. */
        struct {
@@ -189,6 +191,35 @@ static void dial_ghostarc_draw_helpline(
        GPU_matrix_pop();
 }
 
+/**
+ * Draws segments to indicate the position of each increment.
+ */
+static void dial_ghostarc_draw_incremental_angle(const float incremental_angle)
+{
+       const int tot_incr = (2 * M_PI) / incremental_angle;
+       GPU_line_width(1.0f);
+
+       uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+       immUniformColor3f(1.0f, 1.0f, 1.0f);
+       immBegin(GPU_PRIM_LINES, tot_incr * 2);
+
+       float v[3] = { 0 };
+       for (int i = 0; i < tot_incr; i++) {
+               v[0] = sinf(incremental_angle * i);
+               v[1] = cosf(incremental_angle * i);
+
+               mul_v2_fl(v, DIAL_WIDTH * 1.1f);
+               immVertex3fv(pos, v);
+
+               mul_v2_fl(v, 1.1f);
+               immVertex3fv(pos, v);
+       }
+
+       immEnd();
+       immUnbindProgram();
+}
+
 static void dial_ghostarc_draw(
         const float angle_ofs, const float angle_delta,
         const float arc_inner_factor, const float color[4])
@@ -319,6 +350,7 @@ static void dial_draw_intern(
        int draw_options = RNA_enum_get(gz->ptr, "draw_options");
        float angle_ofs = 0.0f;
        float angle_delta = 0.0f;
+       float angle_increment = 0.0f;
 
        if (select) {
                draw_options &= ~ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_VALUE;
@@ -331,6 +363,7 @@ static void dial_draw_intern(
                if (inter) {
                        angle_ofs = inter->output.angle_ofs;
                        angle_delta = inter->output.angle_delta;
+                       angle_increment = inter->angle_increment;
                }
                else {
                        wmGizmoProperty *gz_prop = WM_gizmo_target_property_find(gz, "offset");
@@ -343,7 +376,7 @@ static void dial_draw_intern(
        ED_gizmotypes_dial_3d_draw_util(
                gz->matrix_basis, matrix_final, gz->line_width, color, clip_plane,
                arc_partial_angle, arc_inner_factor, draw_options, angle_ofs,
-               angle_delta);
+               angle_delta, angle_increment);
 }
 
 static void gizmo_dial_draw_select(const bContext *C, wmGizmo *gz, int select_id)
@@ -401,22 +434,24 @@ static int gizmo_dial_modal(
        }
        /* Coordinate at which the arc drawing will be started. */
        const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f};
-       float angle_ofs, angle_delta;
+       float angle_ofs, angle_delta, angle_increment = 0.0f;
 
        dial_ghostarc_get_angles(
                gz, event, CTX_wm_region(C), gz->matrix_basis, co_outer, &angle_ofs, &angle_delta);
 
        if (tweak_flag & WM_GIZMO_TWEAK_SNAP) {
-               const double snap = DEG2RAD(5);
-               angle_delta = (float)roundf((double)angle_delta / snap) * snap;
+               angle_increment = RNA_float_get(gz->ptr, "incremental_angle");
+               angle_delta = (float)roundf((double)angle_delta / angle_increment) * angle_increment;
        }
        if (tweak_flag & WM_GIZMO_TWEAK_PRECISE) {
-               angle_delta *= 0.1f;
+               angle_increment *= 0.2f;
+               angle_delta *= 0.2f;
        }
        if (angle_delta != 0.0f) {
                inter->has_drag = true;
        }
 
+       inter->angle_increment = angle_increment;
        inter->output.angle_delta = angle_delta;
        inter->output.angle_ofs = angle_ofs;
 
@@ -505,7 +540,8 @@ void ED_gizmotypes_dial_3d_draw_util(
         const float arc_inner_factor,
         const int draw_options,
         const float angle_ofs,
-        const float angle_delta)
+        const float angle_delta,
+        const float angle_increment)
 {
        GPU_matrix_push();
        GPU_matrix_mul(matrix_final);
@@ -525,6 +561,10 @@ void ED_gizmotypes_dial_3d_draw_util(
                }
        }
 
+       if (angle_increment) {
+               dial_ghostarc_draw_incremental_angle(angle_increment);
+       }
+
        /* Draw actual dial gizmo. */
        dial_geom_draw(
                color, line_width, false, matrix_basis, clip_plane,
@@ -561,6 +601,9 @@ static void GIZMO_GT_dial_3d(wmGizmoType *gzt)
        RNA_def_boolean(gzt->srna, "wrap_angle", true, "Wrap Angle", "");
        RNA_def_float_factor(gzt->srna, "arc_inner_factor", 0.0f, 0.0f, 1.0f, "Arc Inner Factor", "", 0.0f, 1.0f);
        RNA_def_float_factor(gzt->srna, "arc_partial_angle", 0.0f, 0.0f, M_PI * 2, "Show Partial Dial", "", 0.0f, M_PI * 2);
+       RNA_def_float_factor(
+               gzt->srna, "incremental_angle", SNAP_INCREMENTAL_ANGLE, 0.0f,
+               M_PI * 2, "Incremental Angle", "Angle to snap in steps", 0.0f, M_PI * 2);
        RNA_def_float(
                gzt->srna, "click_value", 0.0f, -FLT_MAX, FLT_MAX,
                "Click Value", "Value to use for a single click action",
index c4096bbae9f6c6d2d4a91b53c79de51f1662bf62..a580436ccf893528d855d14d00f766a4fa805e1d 100644 (file)
@@ -245,6 +245,7 @@ void ED_gizmotypes_dial_3d_draw_util(
         const float arc_inner_factor,
         const int draw_options,
         const float angle_ofs,
-        const float angle_delta);
+        const float angle_delta,
+        const float angle_increment);
 
 #endif  /* __ED_GIZMO_LIBRARY_H__ */
index 223163264ca5c6c7a188ad552a5ab40f9cc9fcf8..4b4c995980f18ad710c30ee6e9eecc90d5c782a5 100644 (file)
@@ -173,6 +173,7 @@ void ED_widgetgroup_gizmo2d_draw_prepare(const struct bContext *C, struct wmGizm
 /* Snapping */
 
 #define SNAP_MIN_DISTANCE 30
+#define SNAP_INCREMENTAL_ANGLE DEG2RAD(5.0)
 
 bool peelObjectsTransform(
         struct TransInfo *t,
index 61a80e900e15e58ab7bef4c0d9e0bc1c9a9aeea7..49a583a36507e8ee55b5e0726868c5bd438edfd2 100644 (file)
@@ -3101,8 +3101,8 @@ static void initBend(TransInfo *t)
        t->idx_max = 1;
        t->num.idx_max = 1;
        t->snap[0] = 0.0f;
-       t->snap[1] = DEG2RAD(5.0);
-       t->snap[2] = DEG2RAD(1.0);
+       t->snap[1] = SNAP_INCREMENTAL_ANGLE;
+       t->snap[2] = t->snap[1] * 0.2;
 
        copy_v3_fl(t->num.val_inc, t->snap[1]);
        t->num.unit_sys = t->scene->unit.system;