From fb556c75df4ce336e61aa9ba16aa4c853548f06d Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 27 Sep 2023 16:25:55 -0300 Subject: [PATCH] Snap: New icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For Blender 4.0 we decided to support individual icons for different snap elements. This was originally contributed by Erik Abrahamsson as !107054 with some contributions by myself (Germano). This set of icons being simple geometric symbols, that should be familiar to CAD artists. Note that Face and Volume share the same icon (circle). This is deliberate since they communicate a similar functionality - are not aimed at precision snapping the same way the vertex or perpendicular are. Also note that later we should also try to change the icons shown in the snap menu to match the symbols that the artists see in the preview window. ——— On the decision process: The version currently in main (and rolled back here) was an initial attempt of aggregating more information to the icons (e.g., by aligning the icons to the target edges) while making them more suitable to Blender. After presenting both options to (parts of the) community, there was nothing fundamentally broken found with either option, though options diverged over personal preference. With that in mind, in the latest UI module meeting it was agreed to use the original proposal then. This final call was proposed by Dalai Felinto on his role of commissioner (stakeholder) for the snap polishing tasks (#73993) and designer for the related Snap Base design #66484. ——— This commit reverts commit 9c2e768f5b. The reverted icons (referred originally as minimalistic icons) may be proposed later as a separate theme option. --- .../blender/blenkernel/BKE_blender_version.h | 2 +- .../blenloader/intern/versioning_300.cc | 3 +- .../blenloader/intern/versioning_400.cc | 55 ++++++++ .../gizmo_library/gizmo_types/snap3d_gizmo.cc | 39 +++++- source/blender/editors/include/ED_view3d.hh | 9 +- .../space_view3d/view3d_cursor_snap.cc | 127 +++++++----------- .../space_view3d/view3d_gizmo_ruler.cc | 23 +++- .../editors/space_view3d/view3d_placement.cc | 2 +- source/blender/editors/transform/transform.hh | 1 + .../transform/transform_mode_snapsource.cc | 1 + .../editors/transform/transform_snap.cc | 7 +- source/blender/makesdna/DNA_scene_types.h | 36 +++-- 12 files changed, 199 insertions(+), 106 deletions(-) diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index f9de48b1e83..ab64945f45e 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -29,7 +29,7 @@ extern "C" { /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 29 +#define BLENDER_FILE_SUBVERSION 30 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenloader/intern/versioning_300.cc b/source/blender/blenloader/intern/versioning_300.cc index 5235c9edfe8..b373b2b938c 100644 --- a/source/blender/blenloader/intern/versioning_300.cc +++ b/source/blender/blenloader/intern/versioning_300.cc @@ -4518,7 +4518,8 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain) if (!MAIN_VERSION_FILE_ATLEAST(bmain, 306, 10)) { LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { /* Set default values for new members. */ - scene->toolsettings->snap_mode_tools = SCE_SNAP_TO_GEOM; + short snap_mode_geom = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 4) | (1 << 5); + scene->toolsettings->snap_mode_tools = snap_mode_geom; scene->toolsettings->plane_axis = 2; } } diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index 79b984b39f0..1a71318e002 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -17,6 +17,7 @@ #include "DNA_brush_types.h" #include "DNA_camera_types.h" +#include "DNA_defaults.h" #include "DNA_light_types.h" #include "DNA_lightprobe_types.h" #include "DNA_modifier_types.h" @@ -1559,6 +1560,60 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) FOREACH_NODETREE_END; } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 30)) { + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + ToolSettings *ts = scene->toolsettings; + auto versioning_snap_to = [](short snap_to_old, bool is_node = false) { + short snap_to_new = SCE_SNAP_TO_NONE; + if (snap_to_old & (1 << 0)) { + snap_to_new |= is_node ? SCE_SNAP_TO_NODE_X : SCE_SNAP_TO_VERTEX; + } + if (snap_to_old & (1 << 1)) { + snap_to_new |= is_node ? SCE_SNAP_TO_NODE_Y : SCE_SNAP_TO_EDGE; + } + if (snap_to_old & (1 << 2)) { + snap_to_new |= SCE_SNAP_TO_FACE; + } + if (snap_to_old & (1 << 3)) { + snap_to_new |= SCE_SNAP_TO_VOLUME; + } + if (snap_to_old & (1 << 4)) { + snap_to_new |= SCE_SNAP_TO_EDGE_MIDPOINT; + } + if (snap_to_old & (1 << 5)) { + snap_to_new |= SCE_SNAP_TO_EDGE_PERPENDICULAR; + } + if (snap_to_old & (1 << 6)) { + snap_to_new |= SCE_SNAP_TO_INCREMENT; + } + if (snap_to_old & (1 << 7)) { + snap_to_new |= SCE_SNAP_TO_GRID; + } + if (snap_to_old & (1 << 8)) { + snap_to_new |= SCE_SNAP_INDIVIDUAL_PROJECT; + } + if (snap_to_old & (1 << 9)) { + snap_to_new |= SCE_SNAP_INDIVIDUAL_NEAREST; + } + if (snap_to_old & (1 << 10)) { + snap_to_new |= SCE_SNAP_TO_FRAME; + } + if (snap_to_old & (1 << 11)) { + snap_to_new |= SCE_SNAP_TO_SECOND; + } + if (snap_to_old & (1 << 12)) { + snap_to_new |= SCE_SNAP_TO_MARKERS; + } + return snap_to_new; + }; + + ts->snap_mode = versioning_snap_to(ts->snap_mode); + ts->snap_uv_mode = versioning_snap_to(ts->snap_uv_mode); + ts->snap_node_mode = versioning_snap_to(ts->snap_node_mode, true); + ts->snap_anim_mode = versioning_snap_to(ts->snap_node_mode); + } + } + /** * Versioning code until next subversion bump goes here. * diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.cc b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.cc index 34ea756827c..ad8c113de83 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.cc +++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.cc @@ -97,7 +97,7 @@ void ED_gizmotypes_snap_3d_data_get(const bContext *C, copy_v3_v3_int(r_elem_index, snap_data->elem_index); } if (r_snap_elem) { - *r_snap_elem = snap_data->snap_elem; + *r_snap_elem = snap_data->type_target; } } @@ -171,6 +171,20 @@ static void gizmo_snap_rna_snap_elem_index_get_fn(PointerRNA * /*ptr*/, copy_v3_v3_int(values, snap_data->elem_index); } +static int gizmo_snap_rna_snap_srouce_type_get_fn(PointerRNA * /*ptr*/, PropertyRNA * /*prop*/) +{ + V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(); + return (int)snap_data->type_source; +} + +static void gizmo_snap_rna_snap_srouce_type_set_fn(PointerRNA * /*ptr*/, + PropertyRNA * /*prop*/, + const int value) +{ + V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(); + snap_data->type_source = (eSnapMode)value; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -266,7 +280,7 @@ static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, const int mval[2]) ED_view3d_cursor_snap_data_update(snap_gizmo->snap_state, C, x, y); V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get(); - if (snap_data->snap_elem != SCE_SNAP_TO_NONE) { + if (snap_data->type_target != SCE_SNAP_TO_NONE) { return 0; } return -1; @@ -305,6 +319,18 @@ static void GIZMO_GT_snap_3d(wmGizmoType *gzt) gzt->struct_size = sizeof(SnapGizmo3D); + const EnumPropertyItem *rna_enum_snap_element_items; + { + /* Get Snap Element Items enum. */ + bool free; + PointerRNA toolsettings_ptr = RNA_pointer_create(nullptr, &RNA_ToolSettings, nullptr); + PropertyRNA *prop = RNA_struct_find_property(&toolsettings_ptr, "snap_elements"); + RNA_property_enum_items( + nullptr, &toolsettings_ptr, prop, &rna_enum_snap_element_items, nullptr, &free); + + BLI_assert(free == false); + } + /* Setup. */ PropertyRNA *prop; prop = RNA_def_float_array(gzt->srna, @@ -358,6 +384,15 @@ static void GIZMO_GT_snap_3d(wmGizmoType *gzt) INT_MAX); RNA_def_property_int_array_funcs_runtime( prop, gizmo_snap_rna_snap_elem_index_get_fn, nullptr, nullptr); + + prop = RNA_def_enum(gzt->srna, + "snap_source_type", + rna_enum_snap_element_items, + SCE_SNAP_TO_NONE, + "Snap Source Type", + "Snap Source type (influences drawing)"); + RNA_def_property_enum_funcs_runtime( + prop, gizmo_snap_rna_snap_srouce_type_get_fn, gizmo_snap_rna_snap_srouce_type_set_fn, NULL); } void ED_gizmotypes_snap_3d() diff --git a/source/blender/editors/include/ED_view3d.hh b/source/blender/editors/include/ED_view3d.hh index af09d03b12e..c87c4bee636 100644 --- a/source/blender/editors/include/ED_view3d.hh +++ b/source/blender/editors/include/ED_view3d.hh @@ -301,7 +301,8 @@ enum eV3DSnapCursor { ENUM_OPERATORS(eV3DSnapCursor, V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE) struct V3DSnapCursorData { - eSnapMode snap_elem; + eSnapMode type_source; + eSnapMode type_target; float loc[3]; float nor[3]; float obmat[4][4]; @@ -342,10 +343,10 @@ SnapObjectContext *ED_view3d_cursor_snap_context_ensure(Scene *scene); void ED_view3d_cursor_snap_draw_util(RegionView3D *rv3d, const float source_loc[3], const float target_loc[3], - const float target_normal[3], + const eSnapMode source_type, + const eSnapMode target_type, const uchar source_color[4], - const uchar target_color[4], - const eSnapMode target_type); + const uchar target_color[4]); /* view3d_iterators.cc */ diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.cc b/source/blender/editors/space_view3d/view3d_cursor_snap.cc index 6b9d4406575..7da0662cbbc 100644 --- a/source/blender/editors/space_view3d/view3d_cursor_snap.cc +++ b/source/blender/editors/space_view3d/view3d_cursor_snap.cc @@ -374,30 +374,26 @@ static void cursor_box_draw(const float dimensions[3], uchar color[4]) GPU_blend(GPU_BLEND_NONE); } -static void cursor_point_draw(uint attr_pos, - const float loc[3], - const float nor[3], - const float size, - eSnapMode snap_type, - const uchar color[4], - bool is_persp) +static void cursor_point_draw( + uint attr_pos, const float loc[3], const float size, eSnapMode snap_type, const uchar color[4]) { immUniformColor4ubv(color); GPU_matrix_push(); - float rotate_view[3][3], model_view_new[4][4]; + float model_view_new[4][4]; GPU_matrix_model_view_get(model_view_new); - copy_m3_m4(rotate_view, model_view_new); translate_m4(model_view_new, UNPACK3(loc)); copy_v3_fl3(model_view_new[0], size, 0.0f, 0.0f); copy_v3_fl3(model_view_new[1], 0.0f, size, 0.0f); copy_v3_fl3(model_view_new[2], 0.0f, 0.0f, size); GPU_matrix_set(model_view_new); - float size_b = 0.8f; + float size_b = 1.0f; switch (snap_type) { - case SCE_SNAP_TO_NONE: + case SCE_SNAP_TO_POINT: + imm_draw_circle_wire_3d(attr_pos, 0.0f, 0.0f, 1.0f, 24); + immBegin(GPU_PRIM_LINES, 4); immVertex3f(attr_pos, -size_b, -size_b, 0.0f); immVertex3f(attr_pos, +size_b, +size_b, 0.0f); @@ -405,60 +401,43 @@ static void cursor_point_draw(uint attr_pos, immVertex3f(attr_pos, +size_b, -size_b, 0.0f); immEnd(); break; + case SCE_SNAP_TO_EDGE_ENDPOINT: + immBegin(GPU_PRIM_LINE_LOOP, 4); + immVertex3f(attr_pos, -size_b, -size_b, 0.0f); + immVertex3f(attr_pos, -size_b, +size_b, 0.0f); + immVertex3f(attr_pos, +size_b, +size_b, 0.0f); + immVertex3f(attr_pos, +size_b, -size_b, 0.0f); + immEnd(); + break; case SCE_SNAP_TO_EDGE_MIDPOINT: - case SCE_SNAP_TO_EDGE_PERPENDICULAR: - case SCE_SNAP_TO_EDGE: { - float x_dir[3]; - mul_v3_m3v3(x_dir, rotate_view, nor); - if (is_persp) { - float *translation = model_view_new[3]; - add_v3_v3(x_dir, translation); - float fac = translation[2] / x_dir[2]; - x_dir[0] *= fac; - x_dir[1] *= fac; - sub_v2_v2(x_dir, translation); - } - normalize_v2_length(x_dir, size); - model_view_new[0][0] = x_dir[0]; - model_view_new[0][1] = x_dir[1]; - model_view_new[1][0] = x_dir[1]; - model_view_new[1][1] = -x_dir[0]; - GPU_matrix_set(model_view_new); - - immBegin(GPU_PRIM_LINES, 4); + immBegin(GPU_PRIM_LINE_LOOP, 3); immVertex3f(attr_pos, -size_b, -size_b, 0.0f); + immVertex3f(attr_pos, 0.0f, 0.866f * size_b, 0.0f); immVertex3f(attr_pos, +size_b, -size_b, 0.0f); - immVertex3f(attr_pos, -size_b, +size_b, 0.0f); - immVertex3f(attr_pos, +size_b, +size_b, 0.0f); - immEnd(); - if (snap_type == SCE_SNAP_TO_EDGE) { - break; - } - immBegin(GPU_PRIM_LINES, 4); - immVertex3f(attr_pos, -size_b, -size_b, 0.0f); - immVertex3f(attr_pos, -size_b, +size_b, 0.0f); - immVertex3f(attr_pos, +size_b, -size_b, 0.0f); - immVertex3f(attr_pos, +size_b, +size_b, 0.0f); immEnd(); break; - } - case SCE_SNAP_TO_FACE: { - float z_dir[3]; - mul_v3_m3v3(z_dir, rotate_view, nor); - copy_v3_v3(model_view_new[2], z_dir); - ortho_basis_v3v3_v3(model_view_new[0], model_view_new[1], model_view_new[2]); - mul_mat3_m4_fl(model_view_new, size * 1.4); - GPU_matrix_set(model_view_new); - - immBegin(GPU_PRIM_LINES, 2); - immVertex3f(attr_pos, 0.0f, 0.0f, 0.0f); - immVertex3f(attr_pos, 0.0f, 0.0f, size_b); + case SCE_SNAP_TO_EDGE_PERPENDICULAR: + immBegin(GPU_PRIM_LINE_STRIP, 3); + immVertex3f(attr_pos, -size_b, +size_b, 0.0f); + immVertex3f(attr_pos, -size_b, -size_b, 0.0f); + immVertex3f(attr_pos, +size_b, -size_b, 0.0f); immEnd(); - ATTR_FALLTHROUGH; - } - case SCE_SNAP_TO_POINT: - /* case SCE_SNAP_TO_EDGE_ENDPOINT: */ + immBegin(GPU_PRIM_LINE_STRIP, 3); + immVertex3f(attr_pos, -size_b, 0.0f, 0.0f); + immVertex3f(attr_pos, 0.0f, 0.0f, 0.0f); + immVertex3f(attr_pos, 0.0f, -size_b, 0.0f); + immEnd(); + break; + case SCE_SNAP_TO_EDGE: + immBegin(GPU_PRIM_LINE_LOOP, 4); + immVertex3f(attr_pos, -size_b, -size_b, 0.0f); + immVertex3f(attr_pos, +size_b, +size_b, 0.0f); + immVertex3f(attr_pos, -size_b, +size_b, 0.0f); + immVertex3f(attr_pos, +size_b, -size_b, 0.0f); + immEnd(); + break; + case SCE_SNAP_TO_FACE: default: imm_draw_circle_wire_3d(attr_pos, 0.0f, 0.0f, 1.0f, 24); break; @@ -470,10 +449,10 @@ static void cursor_point_draw(uint attr_pos, void ED_view3d_cursor_snap_draw_util(RegionView3D *rv3d, const float source_loc[3], const float target_loc[3], - const float target_normal[3], + const eSnapMode source_type, + const eSnapMode target_type, const uchar source_color[4], - const uchar target_color[4], - const eSnapMode target_type) + const uchar target_color[4]) { if (!source_loc && !target_loc) { return; @@ -492,21 +471,17 @@ void ED_view3d_cursor_snap_draw_util(RegionView3D *rv3d, if (target_loc) { cursor_point_draw(pos, target_loc, - target_normal, radius * ED_view3d_pixel_size(rv3d, target_loc), target_type, - target_color, - rv3d->is_persp); + target_color); } if (source_loc) { cursor_point_draw(pos, source_loc, - target_normal, radius * ED_view3d_pixel_size(rv3d, source_loc), - SCE_SNAP_TO_NONE, - source_color, - rv3d->is_persp); + source_type, + source_color); if (target_loc && (target_type & SCE_SNAP_TO_EDGE_PERPENDICULAR)) { /* Dashed line. */ @@ -681,7 +656,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state, if (snap_data->is_snap_invert != !(tool_settings->snap_flag & SCE_SNAP)) { snap_data->is_enabled = false; if (!calc_plane_omat) { - snap_data->snap_elem = SCE_SNAP_TO_NONE; + snap_data->type_target = SCE_SNAP_TO_NONE; return; } snap_elements = SCE_SNAP_TO_NONE; @@ -852,7 +827,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state, snap_elem_index[2] = index; } - snap_data->snap_elem = snap_elem; + snap_data->type_target = snap_elem; copy_v3_v3(snap_data->loc, co); copy_v3_v3(snap_data->nor, no); copy_m4_m4(snap_data->obmat, obmat); @@ -930,7 +905,7 @@ static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void * /*customda } const bool draw_plane = state->draw_plane || state->draw_box; - if (snap_data->snap_elem == SCE_SNAP_TO_NONE && !draw_plane) { + if (snap_data->type_target == SCE_SNAP_TO_NONE && !draw_plane) { return; } @@ -948,18 +923,18 @@ static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void * /*customda v3d_cursor_plane_draw(rv3d, scene->toolsettings->plane_axis, matrix); } - if (snap_data->snap_elem != SCE_SNAP_TO_NONE && (state->draw_point || state->draw_box)) { - const float *source_loc = (snap_data->snap_elem & SCE_SNAP_TO_EDGE_PERPENDICULAR) ? + if (snap_data->type_target != SCE_SNAP_TO_NONE && (state->draw_point || state->draw_box)) { + const float *source_loc = (snap_data->type_target & SCE_SNAP_TO_EDGE_PERPENDICULAR) ? state->prevpoint : nullptr; ED_view3d_cursor_snap_draw_util(rv3d, source_loc, snap_data->loc, - snap_data->nor, + snap_data->type_source, + snap_data->type_target, state->source_color, - state->target_color, - snap_data->snap_elem); + state->target_color); } if (state->draw_box) { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc index a4ed2e54b32..edde933c13b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc @@ -154,6 +154,7 @@ struct RulerInfo { struct { wmGizmo *gizmo; PropertyRNA *prop_prevpoint; + PropertyRNA *prop_snap_source_type; } snap_data; }; @@ -165,6 +166,7 @@ struct RulerItem { /** World-space coords, middle being optional. */ float3x3 co; + eSnapMode snap_type[3]; int flag; int raycast_dir; /* RULER_DIRECTION_* */ @@ -357,6 +359,7 @@ static bool view3d_ruler_item_mousemove(const bContext *C, if (ruler_item) { RulerInteraction *inter = static_cast(ruler_item->gz.interaction_data); float3 &co = ruler_item->co[inter->co_index]; + eSnapMode *snap_source_type = &ruler_item->snap_type[inter->co_index]; /* restore the initial depth */ co = inter->drag_start_co; view3d_ruler_item_project(ruler_info, co, mval); @@ -403,25 +406,31 @@ static bool view3d_ruler_item_mousemove(const bContext *C, View3D *v3d = static_cast(ruler_info->area->spacedata.first); if (do_snap) { float3 *prev_point = nullptr; + eSnapMode snap_type; BLI_assert(ED_gizmotypes_snap_3d_is_enabled(snap_gizmo)); if (inter->co_index != 1) { if (ruler_item->flag & RULERITEM_USE_ANGLE) { prev_point = &ruler_item->co[1]; + snap_type = ruler_item->snap_type[1]; } else if (inter->co_index == 0) { prev_point = &ruler_item->co[2]; + snap_type = ruler_item->snap_type[2]; } else { prev_point = &ruler_item->co[0]; + snap_type = ruler_item->snap_type[0]; } } if (prev_point != nullptr) { RNA_property_float_set_array( snap_gizmo->ptr, ruler_info->snap_data.prop_prevpoint, *prev_point); + RNA_property_enum_set( + snap_gizmo->ptr, ruler_info->snap_data.prop_snap_source_type, snap_type); } - ED_gizmotypes_snap_3d_data_get(C, snap_gizmo, co, nullptr, nullptr, nullptr); + ED_gizmotypes_snap_3d_data_get(C, snap_gizmo, co, nullptr, nullptr, snap_source_type); } #ifdef USE_AXIS_CONSTRAINTS @@ -1154,19 +1163,26 @@ static int gizmo_ruler_invoke(bContext *C, wmGizmo *gz, const wmEvent *event) { /* Set Snap prev point. */ float3 *prev_point; + eSnapMode snap_type; if (ruler_item_pick->flag & RULERITEM_USE_ANGLE) { prev_point = (inter->co_index != 1) ? &ruler_item_pick->co[1] : nullptr; + snap_type = (inter->co_index != 1) ? ruler_item_pick->snap_type[1] : SCE_SNAP_TO_VERTEX; } else if (inter->co_index == 0) { prev_point = &ruler_item_pick->co[2]; + snap_type = ruler_item_pick->snap_type[2]; } else { prev_point = &ruler_item_pick->co[0]; + snap_type = ruler_item_pick->snap_type[2]; } if (prev_point) { RNA_property_float_set_array( ruler_info->snap_data.gizmo->ptr, ruler_info->snap_data.prop_prevpoint, *prev_point); + RNA_property_enum_set(ruler_info->snap_data.gizmo->ptr, + ruler_info->snap_data.prop_snap_source_type, + snap_type); } else { RNA_property_unset(ruler_info->snap_data.gizmo->ptr, ruler_info->snap_data.prop_prevpoint); @@ -1260,6 +1276,8 @@ static void WIDGETGROUP_ruler_setup(const bContext *C, wmGizmoGroup *gzgroup) ruler_info->region = region; ruler_info->snap_data.gizmo = gizmo; ruler_info->snap_data.prop_prevpoint = RNA_struct_find_property(gizmo->ptr, "prev_point"); + ruler_info->snap_data.prop_snap_source_type = RNA_struct_find_property(gizmo->ptr, + "snap_source_type"); gzgroup->customdata = ruler_info; } @@ -1342,6 +1360,9 @@ static int view3d_ruler_add_invoke(bContext *C, wmOperator *op, const wmEvent *e RNA_property_float_set_array(ruler_info->snap_data.gizmo->ptr, ruler_info->snap_data.prop_prevpoint, inter->drag_start_co); + RNA_property_enum_set(ruler_info->snap_data.gizmo->ptr, + ruler_info->snap_data.prop_snap_source_type, + ruler_item->snap_type[inter->co_index]); copy_v3_v3(ruler_item->co[2], ruler_item->co[0]); ruler_item->gz.highlight_part = inter->co_index = 2; diff --git a/source/blender/editors/space_view3d/view3d_placement.cc b/source/blender/editors/space_view3d/view3d_placement.cc index 3b174081938..2825dd0d1a8 100644 --- a/source/blender/editors/space_view3d/view3d_placement.cc +++ b/source/blender/editors/space_view3d/view3d_placement.cc @@ -694,7 +694,7 @@ static bool view3d_interactive_add_calc_snap(bContext * /*C*/, if (r_is_snap_invert) { *r_is_snap_invert = snap_data->is_snap_invert; } - return snap_data->snap_elem != SCE_SNAP_TO_NONE; + return snap_data->type_target != SCE_SNAP_TO_NONE; } /** \} */ diff --git a/source/blender/editors/transform/transform.hh b/source/blender/editors/transform/transform.hh index 71d40860c9b..734c6200490 100644 --- a/source/blender/editors/transform/transform.hh +++ b/source/blender/editors/transform/transform.hh @@ -308,6 +308,7 @@ struct TransSnap { short face_nearest_steps; eTSnap status; /* Snapped Element Type (currently for objects only). */ + eSnapMode source_type; eSnapMode target_type; /** snapping from this point (in global-space). */ float snap_source[3]; diff --git a/source/blender/editors/transform/transform_mode_snapsource.cc b/source/blender/editors/transform/transform_mode_snapsource.cc index 9366459f72c..08609908d98 100644 --- a/source/blender/editors/transform/transform_mode_snapsource.cc +++ b/source/blender/editors/transform/transform_mode_snapsource.cc @@ -74,6 +74,7 @@ static void snapsource_confirm(TransInfo *t) BLI_assert(t->modifiers & MOD_EDIT_SNAP_SOURCE); getSnapPoint(t, t->tsnap.snap_source); t->tsnap.snap_source_fn = nullptr; + t->tsnap.source_type = t->tsnap.target_type; t->tsnap.status |= SNAP_SOURCE_FOUND; SnapSouceCustomData *customdata = static_cast(t->custom.mode.data); diff --git a/source/blender/editors/transform/transform_snap.cc b/source/blender/editors/transform/transform_snap.cc index d296ad3fa8e..15a22b776a3 100644 --- a/source/blender/editors/transform/transform_snap.cc +++ b/source/blender/editors/transform/transform_snap.cc @@ -248,7 +248,7 @@ void drawSnapping(TransInfo *t) } ED_view3d_cursor_snap_draw_util( - rv3d, source_loc, target_loc, t->tsnap.snapNormal, col, activeCol, t->tsnap.target_type); + rv3d, source_loc, target_loc, t->tsnap.source_type, t->tsnap.target_type, col, activeCol); /* Draw normal if needed. */ if (usingSnappingNormal(t) && validSnappingNormal(t)) { @@ -563,6 +563,7 @@ void transform_snap_mixed_apply(TransInfo *t, float *vec) void resetSnapping(TransInfo *t) { t->tsnap.status = SNAP_RESETTED; + t->tsnap.source_type = SCE_SNAP_TO_NONE; t->tsnap.target_type = SCE_SNAP_TO_NONE; t->tsnap.mode = SCE_SNAP_TO_NONE; t->tsnap.target_operation = SCE_SNAP_TARGET_ALL; @@ -1270,6 +1271,7 @@ static void snap_source_center_fn(TransInfo *t) TargetSnapOffset(t, nullptr); t->tsnap.status |= SNAP_SOURCE_FOUND; + t->tsnap.source_type = SCE_SNAP_TO_NONE; } } @@ -1280,6 +1282,7 @@ static void snap_source_active_fn(TransInfo *t) if (calculateCenterActive(t, true, t->tsnap.snap_source)) { TargetSnapOffset(t, nullptr); t->tsnap.status |= SNAP_SOURCE_FOUND; + t->tsnap.source_type = SCE_SNAP_TO_NONE; } else { /* No active, default to median, */ @@ -1296,6 +1299,7 @@ static void snap_source_median_fn(TransInfo *t) if ((t->tsnap.status & SNAP_SOURCE_FOUND) == 0) { tranform_snap_target_median_calc(t, t->tsnap.snap_source); t->tsnap.status |= SNAP_SOURCE_FOUND; + t->tsnap.source_type = SCE_SNAP_TO_NONE; } } @@ -1386,6 +1390,7 @@ static void snap_source_closest_fn(TransInfo *t) TargetSnapOffset(t, closest); t->tsnap.status |= SNAP_SOURCE_FOUND; + t->tsnap.source_type = SCE_SNAP_TO_NONE; } } diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index a30c2396e98..fa47da1ceff 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -2383,40 +2383,38 @@ typedef enum eSnapMode { SCE_SNAP_TO_NODE_X = (1 << 0), SCE_SNAP_TO_NODE_Y = (1 << 1), + /** #ToolSettings::snap_anim_mode */ + SCE_SNAP_TO_FRAME = (1 << 0), + SCE_SNAP_TO_SECOND = (1 << 1), + SCE_SNAP_TO_MARKERS = (1 << 2), + /** #ToolSettings::snap_mode and #ToolSettings::snap_node_mode and #ToolSettings.snap_uv_mode */ SCE_SNAP_TO_POINT = (1 << 0), - /* Even with the same value, there is a distinction between point and endpoint in the snap code. - * Therefore, use different enums for better code readability. */ - SCE_SNAP_TO_EDGE_ENDPOINT = (1 << 0), - SCE_SNAP_TO_EDGE = (1 << 1), - SCE_SNAP_TO_FACE = (1 << 2), - SCE_SNAP_TO_VOLUME = (1 << 3), - SCE_SNAP_TO_EDGE_MIDPOINT = (1 << 4), - SCE_SNAP_TO_EDGE_PERPENDICULAR = (1 << 5), - SCE_SNAP_TO_INCREMENT = (1 << 6), + SCE_SNAP_TO_EDGE_MIDPOINT = (1 << 1), + SCE_SNAP_TO_EDGE_ENDPOINT = (1 << 2), + SCE_SNAP_TO_EDGE_PERPENDICULAR = (1 << 3), + SCE_SNAP_TO_EDGE = (1 << 4), + SCE_SNAP_TO_FACE = (1 << 5), + SCE_SNAP_TO_VOLUME = (1 << 6), SCE_SNAP_TO_GRID = (1 << 7), + SCE_SNAP_TO_INCREMENT = (1 << 8), /** For snap individual elements. */ - SCE_SNAP_INDIVIDUAL_NEAREST = (1 << 8), - SCE_SNAP_INDIVIDUAL_PROJECT = (1 << 9), - - /** #ToolSettings::snap_anim_mode */ - SCE_SNAP_TO_FRAME = (1 << 10), - SCE_SNAP_TO_SECOND = (1 << 11), - SCE_SNAP_TO_MARKERS = (1 << 12), + SCE_SNAP_INDIVIDUAL_NEAREST = (1 << 9), + SCE_SNAP_INDIVIDUAL_PROJECT = (1 << 10), } eSnapMode; /* Due to dependency conflicts with Cycles, header cannot directly include `BLI_utildefines.h`. */ /* TODO: move this macro to a more general place. */ #ifdef ENUM_OPERATORS -ENUM_OPERATORS(eSnapMode, SCE_SNAP_TO_MARKERS) +ENUM_OPERATORS(eSnapMode, SCE_SNAP_INDIVIDUAL_PROJECT) #endif #define SCE_SNAP_TO_VERTEX (SCE_SNAP_TO_POINT | SCE_SNAP_TO_EDGE_ENDPOINT) #define SCE_SNAP_TO_GEOM \ - (SCE_SNAP_TO_VERTEX | SCE_SNAP_TO_EDGE | SCE_SNAP_TO_FACE | SCE_SNAP_TO_EDGE_PERPENDICULAR | \ - SCE_SNAP_TO_EDGE_MIDPOINT) + (SCE_SNAP_TO_VERTEX | SCE_SNAP_TO_EDGE | SCE_SNAP_TO_FACE | SCE_SNAP_TO_EDGE_MIDPOINT | \ + SCE_SNAP_TO_EDGE_PERPENDICULAR) /** #SequencerToolSettings::snap_mode */ enum {