diff options
author | Hans Goudey <h.goudey@me.com> | 2020-09-01 20:35:14 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-09-01 20:38:05 +0300 |
commit | baca8611e5fe4b3dcd6f5065fb125bc0a9d65934 (patch) | |
tree | bb1230387cd53b15f9621f10c4d0e5e2050b5580 /source/blender/editors/transform | |
parent | 31705201dddebf7e3be5c4533b89f380aad1ede1 (diff) | |
parent | 2930d4fcea405985f2212c5f28c061af7c4849f8 (diff) |
Merge branch 'master' into active-fcurve-keyframeactive-fcurve-keyframe
Diffstat (limited to 'source/blender/editors/transform')
36 files changed, 291 insertions, 455 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 76cce5e725f..11f0e791d14 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -560,94 +560,6 @@ static void viewRedrawPost(bContext *C, TransInfo *t) #endif } -/* ************************** TRANSFORMATIONS **************************** */ - -static void view_editmove(ushort UNUSED(event)) -{ -#if 0 // TRANSFORM_FIX_ME - int refresh = 0; - /* Regular: Zoom in */ - /* Shift: Scroll up */ - /* Ctrl: Scroll right */ - /* Alt-Shift: Rotate up */ - /* Alt-Ctrl: Rotate right */ - - /* only work in 3D window for now - * In the end, will have to send to event to a 2D window handler instead - */ - if (Trans.flag & T_2D_EDIT) { - return; - } - - switch (event) { - case WHEELUPMOUSE: - if (G.qual & LR_SHIFTKEY) { - if (G.qual & LR_ALTKEY) { - G.qual &= ~LR_SHIFTKEY; - persptoetsen(PAD2); - G.qual |= LR_SHIFTKEY; - } - else { - persptoetsen(PAD2); - } - } - else if (G.qual & LR_CTRLKEY) { - if (G.qual & LR_ALTKEY) { - G.qual &= ~LR_CTRLKEY; - persptoetsen(PAD4); - G.qual |= LR_CTRLKEY; - } - else { - persptoetsen(PAD4); - } - } - else if (U.uiflag & USER_WHEELZOOMDIR) { - persptoetsen(PADMINUS); - } - else { - persptoetsen(PADPLUSKEY); - } - - refresh = 1; - break; - case WHEELDOWNMOUSE: - if (G.qual & LR_SHIFTKEY) { - if (G.qual & LR_ALTKEY) { - G.qual &= ~LR_SHIFTKEY; - persptoetsen(PAD8); - G.qual |= LR_SHIFTKEY; - } - else { - persptoetsen(PAD8); - } - } - else if (G.qual & LR_CTRLKEY) { - if (G.qual & LR_ALTKEY) { - G.qual &= ~LR_CTRLKEY; - persptoetsen(PAD6); - G.qual |= LR_CTRLKEY; - } - else { - persptoetsen(PAD6); - } - } - else if (U.uiflag & USER_WHEELZOOMDIR) { - persptoetsen(PADPLUSKEY); - } - else { - persptoetsen(PADMINUS); - } - - refresh = 1; - break; - } - - if (refresh) { - setTransformViewMatrices(&Trans); - } -#endif -} - /* ************************************************* */ static bool transform_modal_item_poll(const wmOperator *op, int value) @@ -770,6 +682,12 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf) {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Move", ""}, {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""}, {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""}, + + {TFM_MODAL_AUTOCONSTRAINT, + "AUTOCONSTRAIN", + 0, + "Automatically detects one direction for constraint", + ""}, {0, NULL, 0, NULL, NULL}, }; @@ -778,6 +696,21 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf) keymap = WM_modalkeymap_ensure(keyconf, "Transform Modal Map", modal_items); keymap->poll_modal_item = transform_modal_item_poll; + /* Default modal map values: + * + * \code{.c} + * WM_modalkeymap_add_item(keymap, EVT_RETKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM); + * WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL); + * WM_modalkeymap_add_item(keymap, EVT_PAGEUPKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOIK_LEN_INC); + * WM_modalkeymap_add_item( + * keymap, EVT_PAGEDOWNKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOIK_LEN_DEC); + * WM_modalkeymap_add_item(keymap, EVT_GKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_TRANSLATE); + * WM_modalkeymap_add_item(keymap, EVT_RKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_ROTATE); + * WM_modalkeymap_add_item(keymap, EVT_SKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_RESIZE); + * WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_AUTOCONSTRAINT); + * \endcode + */ + return keymap; } @@ -887,6 +820,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } /* handle modal keymap first */ + /* enforce redraw of transform when modifiers are used */ else if (event->type == EVT_MODAL_MAP) { switch (event->val) { case TFM_MODAL_CANCEL: @@ -1147,40 +1081,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) t->redraw |= TREDRAW_SOFT; } break; - /* Those two are only handled in transform's own handler, see T44634! */ - case TFM_MODAL_EDGESLIDE_UP: - case TFM_MODAL_EDGESLIDE_DOWN: - default: - break; - } - } - /* else do non-mapped events */ - else if (event->val == KM_PRESS) { - switch (event->type) { - case EVT_ESCKEY: - case RIGHTMOUSE: - t->state = TRANS_CANCEL; - handled = true; - break; - - case EVT_SPACEKEY: - case EVT_PADENTER: - case EVT_RETKEY: - if (event->is_repeat) { - break; - } - t->state = TRANS_CONFIRM; - handled = true; - break; - - /* enforce redraw of transform when modifiers are used */ - case EVT_LEFTSHIFTKEY: - case EVT_RIGHTSHIFTKEY: - t->modifiers |= MOD_CONSTRAINT_PLANE; - t->redraw |= TREDRAW_HARD; - handled = true; - break; - case MIDDLEMOUSE: + case TFM_MODAL_AUTOCONSTRAINT: if ((t->flag & T_NO_CONSTRAINT) == 0) { /* exception for switching to dolly, or trackball, in camera view */ if (t->flag & T_CAMERA) { @@ -1206,59 +1107,16 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } break; - case EVT_GKEY: - if (event->is_repeat) { - break; - } - /* only switch when... */ - if (t->mode != TFM_TRANSLATION && transform_mode_is_changeable(t->mode)) { - restoreTransObjects(t); - resetTransModal(t); - resetTransRestrictions(t); - transform_mode_init(t, NULL, TFM_TRANSLATION); - initSnapping(t, NULL); // need to reinit after mode change - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; - case EVT_SKEY: - if (event->is_repeat) { - break; - } - /* only switch when... */ - if (t->mode != TFM_RESIZE && transform_mode_is_changeable(t->mode)) { - restoreTransObjects(t); - resetTransModal(t); - resetTransRestrictions(t); - transform_mode_init(t, NULL, TFM_RESIZE); - initSnapping(t, NULL); // need to reinit after mode change - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; - case EVT_RKEY: - if (event->is_repeat) { - break; - } - /* only switch when... */ - if (!(t->options & CTX_TEXTURE)) { - if (transform_mode_is_changeable(t->mode)) { - restoreTransObjects(t); - resetTransModal(t); - resetTransRestrictions(t); - - if (t->mode == TFM_ROTATION) { - transform_mode_init(t, NULL, TFM_TRACKBALL); - } - else { - transform_mode_init(t, NULL, TFM_ROTATION); - } - initSnapping(t, NULL); // need to reinit after mode change - t->redraw |= TREDRAW_HARD; - handled = true; - } - } + /* Those two are only handled in transform's own handler, see T44634! */ + case TFM_MODAL_EDGESLIDE_UP: + case TFM_MODAL_EDGESLIDE_DOWN: + default: break; + } + } + /* Else do non-mapped events. */ + else if (event->val == KM_PRESS) { + switch (event->type) { case EVT_CKEY: if (event->is_repeat) { break; @@ -1295,17 +1153,6 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } break; - case EVT_PAGEUPKEY: - case WHEELDOWNMOUSE: - if (t->flag & T_AUTOIK) { - transform_autoik_update(t, 1); - } - else { - view_editmove(event->type); - } - t->redraw = TREDRAW_HARD; - handled = true; - break; case EVT_PADMINUS: if (event->alt && t->flag & T_PROP_EDIT) { t->prop_size /= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f; @@ -1314,17 +1161,6 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } break; - case EVT_PAGEDOWNKEY: - case WHEELUPMOUSE: - if (t->flag & T_AUTOIK) { - transform_autoik_update(t, -1); - } - else { - view_editmove(event->type); - } - t->redraw = TREDRAW_HARD; - handled = true; - break; case EVT_LEFTALTKEY: case EVT_RIGHTALTKEY: if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) { @@ -1357,31 +1193,29 @@ int transformEvent(TransInfo *t, const wmEvent *event) } else if (event->val == KM_RELEASE) { switch (event->type) { - case EVT_LEFTSHIFTKEY: - case EVT_RIGHTSHIFTKEY: - t->modifiers &= ~MOD_CONSTRAINT_PLANE; - t->redraw |= TREDRAW_HARD; - handled = true; - break; - - case MIDDLEMOUSE: - if ((t->flag & T_NO_CONSTRAINT) == 0) { - t->modifiers &= ~MOD_CONSTRAINT_SELECT; - postSelectConstraint(t); - t->redraw |= TREDRAW_HARD; - handled = true; - } - break; case EVT_LEFTALTKEY: case EVT_RIGHTALTKEY: + /* TODO: Modal Map */ if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) { t->flag &= ~T_ALT_TRANSFORM; t->redraw |= TREDRAW_HARD; handled = true; } break; - default: + default: { + /* Disable modifiers. */ + int modifiers = t->modifiers; + modifiers &= ~MOD_CONSTRAINT_SELECT; + if (modifiers != t->modifiers) { + if (t->modifiers & MOD_CONSTRAINT_SELECT) { + postSelectConstraint(t); + } + t->modifiers = modifiers; + t->redraw |= TREDRAW_HARD; + handled = true; + } break; + } } /* confirm transform if launch key is released after mouse move */ @@ -1544,16 +1378,14 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *region) #endif /* autokey recording icon... */ - GPU_blend_set_func_separate( - GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - GPU_blend(true); + GPU_blend(GPU_BLEND_ALPHA); xco -= U.widget_unit; yco -= (int)printable_size[1] / 2; UI_icon_draw(xco, yco, ICON_REC); - GPU_blend(false); + GPU_blend(GPU_BLEND_NONE); } static void drawTransformPixel(const struct bContext *C, ARegion *region, void *arg) diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 1917d9463f4..1e4992e5f1a 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -79,7 +79,6 @@ typedef struct TransSnap { bool project; bool snap_self; bool peel; - bool snap_spatial_grid; bool use_backface_culling; char status; /* Snapped Element Type (currently for objects only). */ @@ -498,7 +497,6 @@ enum { MOD_PRECISION = 1 << 1, MOD_SNAP = 1 << 2, MOD_SNAP_INVERT = 1 << 3, - MOD_CONSTRAINT_PLANE = 1 << 4, }; /* use node center for transform instead of upper-left corner. @@ -576,6 +574,8 @@ enum { TFM_MODAL_PROPSIZE = 26, /* node editor insert offset (aka auto-offset) direction toggle */ TFM_MODAL_INSERTOFS_TOGGLE_DIR = 27, + + TFM_MODAL_AUTOCONSTRAINT = 28, }; bool initTransform(struct bContext *C, diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index d0e37f22236..8fdee0e8eec 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -167,7 +167,7 @@ static void postConstraintChecks(TransInfo *t, float vec[3]) { mul_m3_v3(t->spacemtx_inv, vec); - snapGridIncrement(t, vec); + transform_snap_increment(t, vec); if (t->flag & T_NULL_ONE) { if (!(t->con.mode & CON_AXIS0)) { @@ -785,7 +785,6 @@ void drawConstraint(TransInfo *t) else { if (tc->mode & CON_SELECT) { float vec[3]; - int depth_test_enabled; convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1])); add_v3_v3(vec, t->center_global); @@ -794,9 +793,9 @@ void drawConstraint(TransInfo *t) drawLine(t, t->center_global, t->spacemtx[1], 'Y', 0); drawLine(t, t->center_global, t->spacemtx[2], 'Z', 0); - depth_test_enabled = GPU_depth_test_enabled(); + eGPUDepthTest depth_test_enabled = GPU_depth_test_get(); if (depth_test_enabled) { - GPU_depth_test(false); + GPU_depth_test(GPU_DEPTH_NONE); } const uint shdr_pos = GPU_vertformat_attr_add( @@ -821,7 +820,7 @@ void drawConstraint(TransInfo *t) immUnbindProgram(); if (depth_test_enabled) { - GPU_depth_test(true); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } } @@ -843,7 +842,6 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) if (t->flag & T_PROP_EDIT) { RegionView3D *rv3d = CTX_wm_region_view3d(C); float tmat[4][4], imat[4][4]; - int depth_test_enabled; if (t->spacetype == SPACE_VIEW3D && rv3d != NULL) { copy_m4_m4(tmat, rv3d->viewmat); @@ -873,9 +871,9 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) GPU_matrix_scale_2f(1.0f, (ysize / xsize) * (xmask / ymask)); } - depth_test_enabled = GPU_depth_test_enabled(); + eGPUDepthTest depth_test_enabled = GPU_depth_test_get(); if (depth_test_enabled) { - GPU_depth_test(false); + GPU_depth_test(GPU_DEPTH_NONE); } uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -884,7 +882,7 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) float viewport[4]; GPU_viewport_size_get_f(viewport); - GPU_blend(true); + GPU_blend(GPU_BLEND_ALPHA); immUniform2fv("viewportSize", &viewport[2]); immUniform1f("lineWidth", 3.0f * U.pixelsize); @@ -899,7 +897,7 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) immUnbindProgram(); if (depth_test_enabled) { - GPU_depth_test(true); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } GPU_matrix_pop(); @@ -1081,34 +1079,16 @@ static void setNearestAxis3d(TransInfo *t) } if (len[0] <= len[1] && len[0] <= len[2]) { - if (t->modifiers & MOD_CONSTRAINT_PLANE) { - t->con.mode |= (CON_AXIS1 | CON_AXIS2); - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s X axis"), t->spacename); - } - else { - t->con.mode |= CON_AXIS0; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s X axis"), t->spacename); - } + t->con.mode |= CON_AXIS0; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s X axis"), t->spacename); } else if (len[1] <= len[0] && len[1] <= len[2]) { - if (t->modifiers & MOD_CONSTRAINT_PLANE) { - t->con.mode |= (CON_AXIS0 | CON_AXIS2); - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s Y axis"), t->spacename); - } - else { - t->con.mode |= CON_AXIS1; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Y axis"), t->spacename); - } + t->con.mode |= CON_AXIS1; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Y axis"), t->spacename); } else if (len[2] <= len[1] && len[2] <= len[0]) { - if (t->modifiers & MOD_CONSTRAINT_PLANE) { - t->con.mode |= (CON_AXIS0 | CON_AXIS1); - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" locking %s Z axis"), t->spacename); - } - else { - t->con.mode |= CON_AXIS2; - BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Z axis"), t->spacename); - } + t->con.mode |= CON_AXIS2; + BLI_snprintf(t->con.text, sizeof(t->con.text), TIP_(" along %s Z axis"), t->spacename); } } diff --git a/source/blender/editors/transform/transform_convert_mesh.c b/source/blender/editors/transform/transform_convert_mesh.c index 573f4550fec..7ad54a56545 100644 --- a/source/blender/editors/transform/transform_convert_mesh.c +++ b/source/blender/editors/transform/transform_convert_mesh.c @@ -507,7 +507,7 @@ static void editmesh_mirror_data_calc(BMEditMesh *em, index[a] = MEM_mallocN(totvert * sizeof(*index[a]), __func__); EDBM_verts_mirror_cache_begin_ex( - em, a, false, test_selected_only, use_topology, TRANSFORM_MAXDIST_MIRROR, index[a]); + em, a, false, test_selected_only, true, use_topology, TRANSFORM_MAXDIST_MIRROR, index[a]); flag = TD_MIRROR_X << a; BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { diff --git a/source/blender/editors/transform/transform_convert_object.c b/source/blender/editors/transform/transform_convert_object.c index 2e92b4e5c09..4bf0f842f2f 100644 --- a/source/blender/editors/transform/transform_convert_object.c +++ b/source/blender/editors/transform/transform_convert_object.c @@ -346,7 +346,7 @@ static void set_trans_object_base_flags(TransInfo *t) ViewLayer *view_layer = t->view_layer; View3D *v3d = t->view; Scene *scene = t->scene; - Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, true); + Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer); /* NOTE: if Base selected and has parent selected: * base->flag_legacy = BA_WAS_SEL */ @@ -357,7 +357,7 @@ static void set_trans_object_base_flags(TransInfo *t) /* Makes sure base flags and object flags are identical. */ BKE_scene_base_flag_to_objects(t->view_layer); /* Make sure depsgraph is here. */ - DEG_graph_relations_update(depsgraph, bmain, scene, view_layer); + DEG_graph_relations_update(depsgraph); /* Clear all flags we need. It will be used to detect dependencies. */ trans_object_base_deps_flag_prepare(view_layer); /* Traverse all bases and set all possible flags. */ @@ -421,7 +421,7 @@ static int count_proportional_objects(TransInfo *t) View3D *v3d = t->view; struct Main *bmain = CTX_data_main(t->context); Scene *scene = t->scene; - Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, true); + Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer); /* Clear all flags we need. It will be used to detect dependencies. */ trans_object_base_deps_flag_prepare(view_layer); /* Rotations around local centers are allowed to propagate, so we take all objects. */ diff --git a/source/blender/editors/transform/transform_draw_cursors.c b/source/blender/editors/transform/transform_draw_cursors.c index 95ca5ae0c30..84fc45e2b45 100644 --- a/source/blender/editors/transform/transform_draw_cursors.c +++ b/source/blender/editors/transform/transform_draw_cursors.c @@ -191,7 +191,7 @@ void transform_draw_cursor_draw(bContext *UNUSED(C), int x, int y, void *customd } GPU_line_smooth(true); - GPU_blend(true); + GPU_blend(GPU_BLEND_ALPHA); GPU_matrix_push(); @@ -339,6 +339,6 @@ void transform_draw_cursor_draw(bContext *UNUSED(C), int x, int y, void *customd GPU_matrix_pop(); GPU_line_smooth(false); - GPU_blend(false); + GPU_blend(GPU_BLEND_NONE); } } diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 6155042f555..14ef5e87534 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -1343,8 +1343,8 @@ void drawDial3d(const TransInfo *t) BLI_assert(axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END); gizmo_get_axis_color(axis_idx, NULL, color, color); - GPU_depth_test(false); - GPU_blend(true); + GPU_depth_test(GPU_DEPTH_NONE); + GPU_blend(GPU_BLEND_ALPHA); GPU_line_smooth(true); ED_gizmotypes_dial_3d_draw_util(mat_basis, @@ -1359,8 +1359,8 @@ void drawDial3d(const TransInfo *t) }); GPU_line_smooth(false); - GPU_depth_test(true); - GPU_blend(false); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); + GPU_blend(GPU_BLEND_NONE); } } diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c index 495c21bc755..edc0781e18e 100644 --- a/source/blender/editors/transform/transform_mode.c +++ b/source/blender/editors/transform/transform_mode.c @@ -1014,7 +1014,7 @@ void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, float ma /* scale stroke thickness */ if (td->val) { - snapGridIncrement(t, t->values_final); + transform_snap_increment(t, t->values_final); applyNumInput(&t->num, t->values_final); float ratio = t->values_final[0]; diff --git a/source/blender/editors/transform/transform_mode_baketime.c b/source/blender/editors/transform/transform_mode_baketime.c index 4e7fc3578ce..235b04b1858 100644 --- a/source/blender/editors/transform/transform_mode_baketime.c +++ b/source/blender/editors/transform/transform_mode_baketime.c @@ -67,7 +67,7 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) time = (float)(t->center2d[0] - mval[0]) * fac; } - snapGridIncrement(t, &time); + transform_snap_increment(t, &time); applyNumInput(&t->num, &time); diff --git a/source/blender/editors/transform/transform_mode_bbone_resize.c b/source/blender/editors/transform/transform_mode_bbone_resize.c index 80a5b307a91..d067c9df418 100644 --- a/source/blender/editors/transform/transform_mode_bbone_resize.c +++ b/source/blender/editors/transform/transform_mode_bbone_resize.c @@ -124,7 +124,7 @@ static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2])) copy_v3_fl(t->values_final, ratio); - snapGridIncrement(t, t->values_final); + transform_snap_increment(t, t->values_final); if (applyNumInput(&t->num, t->values_final)) { constraintNumInput(t, t->values_final); diff --git a/source/blender/editors/transform/transform_mode_bend.c b/source/blender/editors/transform/transform_mode_bend.c index 3b51626b170..86de40448b7 100644 --- a/source/blender/editors/transform/transform_mode_bend.c +++ b/source/blender/editors/transform/transform_mode_bend.c @@ -104,7 +104,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) const float radius_snap = 0.1f; const float snap_hack = (t->snap[1] * data->warp_init_dist) / radius_snap; values.scale *= snap_hack; - snapGridIncrement(t, values.vector); + transform_snap_increment(t, values.vector); values.scale /= snap_hack; } #endif diff --git a/source/blender/editors/transform/transform_mode_boneenvelope.c b/source/blender/editors/transform/transform_mode_boneenvelope.c index b7a34769f5a..7f5a8fedeef 100644 --- a/source/blender/editors/transform/transform_mode_boneenvelope.c +++ b/source/blender/editors/transform/transform_mode_boneenvelope.c @@ -53,7 +53,7 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_boneroll.c b/source/blender/editors/transform/transform_mode_boneroll.c index 1503519c519..8805d54e1f8 100644 --- a/source/blender/editors/transform/transform_mode_boneroll.c +++ b/source/blender/editors/transform/transform_mode_boneroll.c @@ -54,7 +54,7 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - snapGridIncrement(t, &final); + transform_snap_increment(t, &final); applyNumInput(&t->num, &final); diff --git a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c index 84e4e950804..fd65b019fe0 100644 --- a/source/blender/editors/transform/transform_mode_curveshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_curveshrinkfatten.c @@ -53,7 +53,7 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_edge_bevelweight.c b/source/blender/editors/transform/transform_mode_edge_bevelweight.c index 399cec2d62c..4d6e25dbe34 100644 --- a/source/blender/editors/transform/transform_mode_edge_bevelweight.c +++ b/source/blender/editors/transform/transform_mode_edge_bevelweight.c @@ -55,7 +55,7 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) CLAMP_MAX(weight, 1.0f); - snapGridIncrement(t, &weight); + transform_snap_increment(t, &weight); applyNumInput(&t->num, &weight); diff --git a/source/blender/editors/transform/transform_mode_edge_crease.c b/source/blender/editors/transform/transform_mode_edge_crease.c index 53c948c742b..a1822d99ff9 100644 --- a/source/blender/editors/transform/transform_mode_edge_crease.c +++ b/source/blender/editors/transform/transform_mode_edge_crease.c @@ -55,7 +55,7 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) CLAMP_MAX(crease, 1.0f); - snapGridIncrement(t, &crease); + transform_snap_increment(t, &crease); applyNumInput(&t->num, &crease); diff --git a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c index fde0d5b187e..5b929c39915 100644 --- a/source/blender/editors/transform/transform_mode_edge_rotate_normal.c +++ b/source/blender/editors/transform/transform_mode_edge_rotate_normal.c @@ -99,7 +99,7 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2])) float angle = t->values[0]; copy_v3_v3(axis, axis_final); - snapGridIncrement(t, &angle); + transform_snap_increment(t, &angle); applySnapping(t, &angle); diff --git a/source/blender/editors/transform/transform_mode_edge_seq_slide.c b/source/blender/editors/transform/transform_mode_edge_seq_slide.c index c1cb4325c09..141f9acdeb4 100644 --- a/source/blender/editors/transform/transform_mode_edge_seq_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_seq_slide.c @@ -102,7 +102,7 @@ static void applySeqSlide(TransInfo *t, const int mval[2]) copy_v3_v3(t->values_final, tvec); } else { - // snapGridIncrement(t, t->values); + // transform_snap_increment(t, t->values); applyNumInput(&t->num, t->values); copy_v3_v3(t->values_final, t->values); } diff --git a/source/blender/editors/transform/transform_mode_edge_slide.c b/source/blender/editors/transform/transform_mode_edge_slide.c index 1886f95beae..7d0e555e362 100644 --- a/source/blender/editors/transform/transform_mode_edge_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_slide.c @@ -1147,11 +1147,9 @@ void drawEdgeSlide(TransInfo *t) const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f; - GPU_depth_test(false); + GPU_depth_test(GPU_DEPTH_NONE); - GPU_blend(true); - GPU_blend_set_func_separate( - GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + GPU_blend(GPU_BLEND_ALPHA); GPU_matrix_push(); GPU_matrix_mul(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat); @@ -1266,9 +1264,9 @@ void drawEdgeSlide(TransInfo *t) GPU_matrix_pop(); - GPU_blend(false); + GPU_blend(GPU_BLEND_NONE); - GPU_depth_test(true); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } static void edge_slide_snap_apply(TransInfo *t, float *value) @@ -1465,7 +1463,9 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; applySnapping(t, &final); - snapGridIncrement(t, &final); + if (!validSnap(t)) { + transform_snap_increment(t, &final); + } /* only do this so out of range values are not displayed */ if (is_constrained) { diff --git a/source/blender/editors/transform/transform_mode_gpopacity.c b/source/blender/editors/transform/transform_mode_gpopacity.c index 4712fb7ba01..11c63be156c 100644 --- a/source/blender/editors/transform/transform_mode_gpopacity.c +++ b/source/blender/editors/transform/transform_mode_gpopacity.c @@ -53,7 +53,7 @@ static void applyGPOpacity(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c index ab9a0aa79ed..c025dbcaccb 100644 --- a/source/blender/editors/transform/transform_mode_gpshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_gpshrinkfatten.c @@ -53,7 +53,7 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c index 68f3abda85b..3ac35ae7780 100644 --- a/source/blender/editors/transform/transform_mode_maskshrinkfatten.c +++ b/source/blender/editors/transform/transform_mode_maskshrinkfatten.c @@ -54,7 +54,7 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_push_pull.c b/source/blender/editors/transform/transform_mode_push_pull.c index 4a2f979ec38..2b17f208e79 100644 --- a/source/blender/editors/transform/transform_mode_push_pull.c +++ b/source/blender/editors/transform/transform_mode_push_pull.c @@ -55,7 +55,7 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) distance = t->values[0]; - snapGridIncrement(t, &distance); + transform_snap_increment(t, &distance); applyNumInput(&t->num, &distance); diff --git a/source/blender/editors/transform/transform_mode_resize.c b/source/blender/editors/transform/transform_mode_resize.c index 5fb46b30e0d..b4245abcc12 100644 --- a/source/blender/editors/transform/transform_mode_resize.c +++ b/source/blender/editors/transform/transform_mode_resize.c @@ -91,7 +91,7 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2])) copy_v3_fl(t->values_final, ratio); - snapGridIncrement(t, t->values_final); + transform_snap_increment(t, t->values_final); if (applyNumInput(&t->num, t->values_final)) { constraintNumInput(t, t->values_final); diff --git a/source/blender/editors/transform/transform_mode_rotate.c b/source/blender/editors/transform/transform_mode_rotate.c index 4fa5dffc473..c0ddd4eb2a6 100644 --- a/source/blender/editors/transform/transform_mode_rotate.c +++ b/source/blender/editors/transform/transform_mode_rotate.c @@ -200,7 +200,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - snapGridIncrement(t, &final); + transform_snap_increment(t, &final); float axis_final[3]; /* Use the negative axis to match the default Z axis of the view matrix. */ diff --git a/source/blender/editors/transform/transform_mode_shear.c b/source/blender/editors/transform/transform_mode_shear.c index e508a1fa4c2..18968494395 100644 --- a/source/blender/editors/transform/transform_mode_shear.c +++ b/source/blender/editors/transform/transform_mode_shear.c @@ -128,7 +128,7 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) value = t->values[0]; - snapGridIncrement(t, &value); + transform_snap_increment(t, &value); applyNumInput(&t->num, &value); diff --git a/source/blender/editors/transform/transform_mode_shrink_fatten.c b/source/blender/editors/transform/transform_mode_shrink_fatten.c index 6302bc96330..2f221181d12 100644 --- a/source/blender/editors/transform/transform_mode_shrink_fatten.c +++ b/source/blender/editors/transform/transform_mode_shrink_fatten.c @@ -56,7 +56,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) distance = t->values[0]; - snapGridIncrement(t, &distance); + transform_snap_increment(t, &distance); applyNumInput(&t->num, &distance); diff --git a/source/blender/editors/transform/transform_mode_skin_resize.c b/source/blender/editors/transform/transform_mode_skin_resize.c index 23d83050613..665c616bc2b 100644 --- a/source/blender/editors/transform/transform_mode_skin_resize.c +++ b/source/blender/editors/transform/transform_mode_skin_resize.c @@ -55,7 +55,7 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) else { copy_v3_fl(t->values_final, t->values[0]); - snapGridIncrement(t, t->values_final); + transform_snap_increment(t, t->values_final); if (applyNumInput(&t->num, t->values_final)) { constraintNumInput(t, t->values_final); diff --git a/source/blender/editors/transform/transform_mode_tilt.c b/source/blender/editors/transform/transform_mode_tilt.c index ca0a8818477..5ab23000039 100644 --- a/source/blender/editors/transform/transform_mode_tilt.c +++ b/source/blender/editors/transform/transform_mode_tilt.c @@ -54,7 +54,7 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - snapGridIncrement(t, &final); + transform_snap_increment(t, &final); applyNumInput(&t->num, &final); diff --git a/source/blender/editors/transform/transform_mode_tosphere.c b/source/blender/editors/transform/transform_mode_tosphere.c index f6c5448a906..e747f0e75d0 100644 --- a/source/blender/editors/transform/transform_mode_tosphere.c +++ b/source/blender/editors/transform/transform_mode_tosphere.c @@ -54,7 +54,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) ratio = t->values[0]; - snapGridIncrement(t, &ratio); + transform_snap_increment(t, &ratio); applyNumInput(&t->num, &ratio); diff --git a/source/blender/editors/transform/transform_mode_trackball.c b/source/blender/editors/transform/transform_mode_trackball.c index ca5a749b275..2656411e8ab 100644 --- a/source/blender/editors/transform/transform_mode_trackball.c +++ b/source/blender/editors/transform/transform_mode_trackball.c @@ -93,7 +93,7 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2])) copy_v2_v2(phi, t->values); - snapGridIncrement(t, phi); + transform_snap_increment(t, phi); applyNumInput(&t->num, phi); diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index c083e1654dc..36be26049d3 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -362,15 +362,28 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) } else { copy_v3_v3(global_dir, t->values); - if ((t->con.mode & CON_APPLY) == 0) { - snapGridIncrement(t, global_dir); - } - if (applyNumInput(&t->num, global_dir)) { removeAspectRatio(t, global_dir); } + else { + applySnapping(t, global_dir); + + if (!validSnap(t) && !(t->con.mode & CON_APPLY)) { + float dist_sq = FLT_MAX; + if (transform_snap_grid(t, global_dir)) { + dist_sq = len_squared_v3v3(t->values, global_dir); + } - applySnapping(t, global_dir); + /* Check the snap distance to the initial value to work with mixed snap. */ + float increment_loc[3]; + copy_v3_v3(increment_loc, t->values); + if (transform_snap_increment(t, increment_loc)) { + if ((dist_sq == FLT_MAX) || (len_squared_v3v3(t->values, increment_loc) < dist_sq)) { + copy_v3_v3(global_dir, increment_loc); + } + } + } + } } if (t->con.mode & CON_APPLY) { diff --git a/source/blender/editors/transform/transform_mode_vert_slide.c b/source/blender/editors/transform/transform_mode_vert_slide.c index 38537194af3..75b973b6b14 100644 --- a/source/blender/editors/transform/transform_mode_vert_slide.c +++ b/source/blender/editors/transform/transform_mode_vert_slide.c @@ -390,11 +390,9 @@ void drawVertSlide(TransInfo *t) const int alpha_shade = -160; int i; - GPU_depth_test(false); + GPU_depth_test(GPU_DEPTH_NONE); - GPU_blend(true); - GPU_blend_set_func_separate( - GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + GPU_blend(GPU_BLEND_ALPHA); GPU_matrix_push(); GPU_matrix_mul(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat); @@ -487,7 +485,7 @@ void drawVertSlide(TransInfo *t) GPU_matrix_pop(); - GPU_depth_test(true); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } } } @@ -589,7 +587,9 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; applySnapping(t, &final); - snapGridIncrement(t, &final); + if (!validSnap(t)) { + transform_snap_increment(t, &final); + } /* only do this so out of range values are not displayed */ if (is_constrained) { diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index ab9548ad52e..d35c2f07482 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -993,8 +993,7 @@ static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot) { /* identifiers */ ot->name = "To Sphere"; - // added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" - ot->description = "Move selected vertices outward in a spherical shape around mesh center"; + ot->description = "Move selected items outward in a spherical shape around geometric center"; ot->idname = OP_TOSPHERE; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index a700dd320b7..1813acadb9e 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -184,7 +184,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) const float *loc_prev = NULL; const float *normal = NULL; - GPU_depth_test(false); + GPU_depth_test(GPU_DEPTH_NONE); RegionView3D *rv3d = CTX_wm_region_view3d(C); if (!BLI_listbase_is_empty(&t->tsnap.points)) { @@ -228,7 +228,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) ED_gizmotypes_snap_3d_draw_util( rv3d, loc_prev, loc_cur, normal, col, activeCol, t->tsnap.snapElem); - GPU_depth_test(true); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); } } else if (t->spacetype == SPACE_IMAGE) { @@ -245,7 +245,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); - GPU_blend(true); + GPU_blend(GPU_BLEND_ALPHA); uint pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -271,7 +271,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t) immUnbindProgram(); - GPU_blend(false); + GPU_blend(GPU_BLEND_NONE); } } } @@ -378,30 +378,14 @@ void applyProject(TransInfo *t) void applyGridAbsolute(TransInfo *t) { - float grid_size = 0.0f; - GearsType grid_action; int i; if (!(activeSnap(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) { return; } - grid_action = BIG_GEARS; - if (t->modifiers & MOD_PRECISION) { - grid_action = SMALL_GEARS; - } + float grid_size = (t->modifiers & MOD_PRECISION) ? t->snap_spatial[2] : t->snap_spatial[1]; - switch (grid_action) { - case NO_GEARS: - grid_size = t->snap_spatial[0]; - break; - case BIG_GEARS: - grid_size = t->snap_spatial[1]; - break; - case SMALL_GEARS: - grid_size = t->snap_spatial[2]; - break; - } /* early exit on unusable grid size */ if (grid_size == 0.0f) { return; @@ -445,7 +429,12 @@ void applyGridAbsolute(TransInfo *t) void applySnapping(TransInfo *t, float *vec) { /* Each Trans Data already makes the snap to face */ - if (doForceIncrementSnap(t) || (t->tsnap.project && t->tsnap.mode == SCE_SNAP_MODE_FACE)) { + if (doForceIncrementSnap(t)) { + return; + } + + if (t->tsnap.project && t->tsnap.mode == SCE_SNAP_MODE_FACE) { + /* The snap has already been resolved for each transdata. */ return; } @@ -559,6 +548,12 @@ static void initSnappingMode(TransInfo *t) } t->tsnap.mode = ts->snap_mode; + if ((t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) && (ts->snap_flag & SCE_SNAP_ABS_GRID) && + (t->mode == TFM_TRANSLATION)) { + /* Special case in which snap to increments is transformed to snap to grid. */ + t->tsnap.mode &= ~SCE_SNAP_MODE_INCREMENT; + t->tsnap.mode |= SCE_SNAP_MODE_GRID; + } } if ((t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) && (t->flag & T_CAMERA) == 0) { @@ -600,7 +595,7 @@ static void initSnappingMode(TransInfo *t) } } else { - /* Grid if snap is not possible */ + /* Increment if snap is not possible */ t->tsnap.mode = SCE_SNAP_MODE_INCREMENT; } } @@ -613,7 +608,7 @@ static void initSnappingMode(TransInfo *t) t->tsnap.mode = SCE_SNAP_MODE_GRID; /* Dummy, should we rather add a NOP mode? */ } else { - /* Always grid outside of 3D view */ + /* Always increment outside of 3D view */ t->tsnap.mode = SCE_SNAP_MODE_INCREMENT; } @@ -686,11 +681,6 @@ void initSnapping(TransInfo *t, wmOperator *op) t->tsnap.snap_self = !((t->settings->snap_flag & SCE_SNAP_NO_SELF) != 0); t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) != 0); } - - /* for now only 3d view (others can be added if we want) */ - if (t->spacetype == SPACE_VIEW3D) { - t->tsnap.snap_spatial_grid = ((t->settings->snap_flag & SCE_SNAP_ABS_GRID) != 0); - } } t->tsnap.target = snap_target; @@ -832,11 +822,6 @@ void getSnapPoint(const TransInfo *t, float vec[3]) /** \name Calc Snap (Generic) * \{ */ -static void UNUSED_FUNCTION(CalcSnapGrid)(TransInfo *t, float *UNUSED(vec)) -{ - snapGridIncrementAction(t, t->tsnap.snapPoint, BIG_GEARS); -} - static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) { if (t->spacetype == SPACE_VIEW3D) { @@ -1407,77 +1392,160 @@ void snapFrameTransform(TransInfo *t, /*================================================================*/ -static void applyGridIncrement( - TransInfo *t, float *val, int max_index, const float fac[3], GearsType action); - -void snapGridIncrementAction(TransInfo *t, float *val, GearsType action) +void snapSequenceBounds(TransInfo *t, const int mval[2]) { - float fac[3]; + /* Reuse increment, strictly speaking could be another snap mode, but leave as is. */ + if (!(t->modifiers & MOD_SNAP_INVERT)) { + return; + } + + /* Convert to frame range. */ + float xmouse, ymouse; + UI_view2d_region_to_view(&t->region->v2d, mval[0], mval[1], &xmouse, &ymouse); + const int frame_curr = round_fl_to_int(xmouse); - fac[NO_GEARS] = t->snap[0]; - fac[BIG_GEARS] = t->snap[1]; - fac[SMALL_GEARS] = t->snap[2]; + /* Now find the closest sequence. */ + const int frame_near = BKE_sequencer_find_next_prev_edit( + t->scene, frame_curr, SEQ_SIDE_BOTH, true, false, true); - applyGridIncrement(t, val, t->idx_max, fac, action); + const int frame_snap = transform_convert_sequencer_get_snap_bound(t); + t->values[0] = frame_near - frame_snap; } -void snapGridIncrement(TransInfo *t, float *val) +static void snap_grid_apply_ex( + TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3]) { - GearsType action; + const float *center_global = t->center_global; + const float *asp = t->aspect; + bool use_local_axis = false; - /* only do something if using absolute or incremental grid snapping - * and there is no valid snap point */ - if ((!(t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)) || validSnap(t)) && - !doForceIncrementSnap(t)) { - return; + /* use a fallback for cursor selection, + * this isn't useful as a global center for absolute grid snapping + * since its not based on the position of the selection. */ + if (t->around == V3D_AROUND_CURSOR) { + const TransCenterData *cd = transformCenter_from_type(t, V3D_AROUND_CENTER_MEDIAN); + center_global = cd->global; } - action = activeSnap(t) ? BIG_GEARS : NO_GEARS; - - if (action == BIG_GEARS && (t->modifiers & MOD_PRECISION)) { - action = SMALL_GEARS; + if (t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2)) { + use_local_axis = true; } - snapGridIncrementAction(t, val, action); + for (int i = 0; i <= max_index; i++) { + /* do not let unconstrained axis jump to absolute grid increments */ + if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) { + const float iter_fac = grid_dist * asp[i]; + + if (use_local_axis) { + float local_axis[3]; + float pos_on_axis[3]; + + copy_v3_v3(local_axis, t->spacemtx[i]); + copy_v3_v3(pos_on_axis, t->spacemtx[i]); + + /* amount of movement on axis from initial pos */ + mul_v3_fl(pos_on_axis, loc[i]); + + /* actual global position on axis */ + add_v3_v3(pos_on_axis, center_global); + + float min_dist = INFINITY; + for (int j = 0; j < 3; j++) { + if (fabs(local_axis[j]) < 0.01f) { + /* Ignore very small (normalized) axis changes */ + continue; + } + + /* closest point on grid */ + float grid_p = iter_fac * roundf(pos_on_axis[j] / iter_fac); + float dist_p = fabs((grid_p - pos_on_axis[j]) / local_axis[j]); + + /* The amount of distance needed to travel along the + * local axis to snap to the closest grid point */ + /* in the global j axis direction */ + float move_dist = (grid_p - center_global[j]) / local_axis[j]; + + if (dist_p < min_dist) { + min_dist = dist_p; + r_out[i] = move_dist; + } + } + } + else { + r_out[i] = iter_fac * roundf((loc[i] + center_global[i]) / iter_fac) - center_global[i]; + } + } + } } -void snapSequenceBounds(TransInfo *t, const int mval[2]) +static void snap_grid_apply(TransInfo *t, int max_index, const float grid_dist, float *r_val) { - /* Reuse increment, strictly speaking could be another snap mode, but leave as is. */ - if (!(t->modifiers & MOD_SNAP_INVERT)) { + BLI_assert(t->tsnap.mode & SCE_SNAP_MODE_GRID); + BLI_assert(max_index <= 2); + + /* Early bailing out if no need to snap */ + if (grid_dist == 0.0f) { return; } - /* Convert to frame range. */ - float xmouse, ymouse; - UI_view2d_region_to_view(&t->region->v2d, mval[0], mval[1], &xmouse, &ymouse); - const int frame_curr = round_fl_to_int(xmouse); + /* absolute snapping on grid based on global center. + * for now only 3d view (others can be added if we want) */ + snap_grid_apply_ex(t, max_index, grid_dist, r_val, r_val); +} - /* Now find the closest sequence. */ - const int frame_near = BKE_sequencer_find_next_prev_edit( - t->scene, frame_curr, SEQ_SIDE_BOTH, true, false, true); +bool transform_snap_grid(TransInfo *t, float *val) +{ + if ((!(t->tsnap.mode & SCE_SNAP_MODE_GRID)) || validSnap(t)) { + /* Don't do grid snapping if there is a valid snap point. */ + return false; + } - const int frame_snap = transform_convert_sequencer_get_snap_bound(t); - t->values[0] = frame_near - frame_snap; + if (t->spacetype != SPACE_VIEW3D) { + return false; + } + + if (t->mode != TFM_TRANSLATION) { + return false; + } + + float grid_dist = activeSnap(t) ? (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1] : + t->snap[0]; + + snap_grid_apply(t, t->idx_max, grid_dist, val); + return true; } -static void applyGridIncrement( - TransInfo *t, float *val, int max_index, const float fac[3], GearsType action) +static void snap_increment_apply_ex(TransInfo *UNUSED(t), + const int max_index, + const float increment_val, + const float aspect[3], + const float loc[3], + float r_out[3]) { - float asp_local[3] = {1, 1, 1}; - const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); - const float *asp = use_aspect ? t->aspect : asp_local; - int i; + /* relative snapping in fixed increments */ + for (int i = 0; i <= max_index; i++) { + const float iter_fac = increment_val * aspect[i]; + r_out[i] = iter_fac * roundf(loc[i] / iter_fac); + } +} - BLI_assert((t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)) || - doForceIncrementSnap(t)); +static void snap_increment_apply(TransInfo *t, + int max_index, + const float increment_dist, + float *r_val) +{ + BLI_assert((t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) || doForceIncrementSnap(t)); BLI_assert(max_index <= 2); /* Early bailing out if no need to snap */ - if (fac[action] == 0.0f) { + if (increment_dist == 0.0f) { return; } + float asp_local[3] = {1, 1, 1}; + const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION); + const float *asp = use_aspect ? t->aspect : asp_local; + if (use_aspect) { /* custom aspect for fcurve */ if (t->spacetype == SPACE_GRAPH) { @@ -1491,76 +1559,26 @@ static void applyGridIncrement( } } - /* absolute snapping on grid based on global center */ - if ((t->tsnap.snap_spatial_grid) && (t->mode == TFM_TRANSLATION)) { - const float *center_global = t->center_global; - bool use_local_axis = false; - - /* use a fallback for cursor selection, - * this isn't useful as a global center for absolute grid snapping - * since its not based on the position of the selection. */ - if (t->around == V3D_AROUND_CURSOR) { - const TransCenterData *cd = transformCenter_from_type(t, V3D_AROUND_CENTER_MEDIAN); - center_global = cd->global; - } - - if (t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2)) { - use_local_axis = true; - } - - for (i = 0; i <= max_index; i++) { - /* do not let unconstrained axis jump to absolute grid increments */ - if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) { - const float iter_fac = fac[action] * asp[i]; - - if (use_local_axis) { - float local_axis[3]; - float pos_on_axis[3]; - - copy_v3_v3(local_axis, t->spacemtx[i]); - copy_v3_v3(pos_on_axis, t->spacemtx[i]); - - /* amount of movement on axis from initial pos */ - mul_v3_fl(pos_on_axis, val[i]); - - /* actual global position on axis */ - add_v3_v3(pos_on_axis, center_global); + snap_increment_apply_ex(t, max_index, increment_dist, asp, r_val, r_val); +} - float min_dist = INFINITY; - for (int j = 0; j < 3; j++) { - if (fabs(local_axis[j]) < 0.01f) { - /* Ignore very small (normalized) axis changes */ - continue; - } +bool transform_snap_increment(TransInfo *t, float *val) +{ + if (!(t->tsnap.mode & SCE_SNAP_MODE_INCREMENT) && !doForceIncrementSnap(t)) { + return false; + } - /* closest point on grid */ - float grid_p = iter_fac * roundf(pos_on_axis[j] / iter_fac); - float dist_p = fabs((grid_p - pos_on_axis[j]) / local_axis[j]); + if (t->spacetype != SPACE_VIEW3D && validSnap(t)) { + /* Only do something if using absolute or incremental grid snapping + * and there is no valid snap point. */ + return false; + } - /* The amount of distance needed to travel along the - * local axis to snap to the closest grid point */ - /* in the global j axis direction */ - float move_dist = (grid_p - center_global[j]) / local_axis[j]; + float increment_dist = activeSnap(t) ? (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1] : + t->snap[0]; - if (dist_p < min_dist) { - min_dist = dist_p; - val[i] = move_dist; - } - } - } - else { - val[i] = iter_fac * roundf((val[i] + center_global[i]) / iter_fac) - center_global[i]; - } - } - } - } - else { - /* relative snapping in fixed increments */ - for (i = 0; i <= max_index; i++) { - const float iter_fac = fac[action] * asp[i]; - val[i] = iter_fac * roundf(val[i] / iter_fac); - } - } + snap_increment_apply(t, t->idx_max, increment_dist, val); + return true; } /** \} */ diff --git a/source/blender/editors/transform/transform_snap.h b/source/blender/editors/transform/transform_snap.h index b97a9dc882c..5bee572c603 100644 --- a/source/blender/editors/transform/transform_snap.h +++ b/source/blender/editors/transform/transform_snap.h @@ -54,16 +54,10 @@ void snapFrameTransform(struct TransInfo *t, /* return args */ float *r_val); -typedef enum { - NO_GEARS = 0, - BIG_GEARS = 1, - SMALL_GEARS = 2, -} GearsType; - bool transformModeUseSnap(const TransInfo *t); -void snapGridIncrement(TransInfo *t, float *val); -void snapGridIncrementAction(TransInfo *t, float *val, GearsType action); +bool transform_snap_increment(TransInfo *t, float *val); +bool transform_snap_grid(TransInfo *t, float *val); void snapSequenceBounds(TransInfo *t, const int mval[2]); |