From cdfa3feb911164118fcc5b574b3e1a35c8f99c72 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 16 Jan 2021 11:29:57 +1100 Subject: Add Object Tool: support incremental snapping This adds a "Snap to" option that allows using all the scenes snap settings which includes incremental & absolute grid snapping options. This is optional because always following scene snapping would not snap to geometry by default (which seems to be the most useful default). --- .../editors/gizmo_library/gizmo_types/snap3d_gizmo.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/blender/editors/gizmo_library') diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c index 8755dea51e1..b8ee1722cb3 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c @@ -80,6 +80,9 @@ typedef struct SnapGizmo3D { #endif int use_snap_override; short snap_elem; + + /** Enabled when snap is activated, even if it didn't find anything. */ + bool is_enabled; } SnapGizmo3D; /* Checks if the current event is different from the one captured in the last update. */ @@ -284,6 +287,12 @@ void ED_gizmotypes_snap_3d_toggle_clear(wmGizmo *gz) snap_gizmo->use_snap_override = -1; } +bool ED_gizmotypes_snap_3d_is_enabled(wmGizmo *gz) +{ + SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz; + return snap_gizmo->is_enabled; +} + short ED_gizmotypes_snap_3d_update(wmGizmo *gz, struct Depsgraph *depsgraph, const ARegion *region, @@ -294,6 +303,8 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz, float r_nor[3]) { SnapGizmo3D *snap_gizmo = (SnapGizmo3D *)gz; + snap_gizmo->is_enabled = false; + if (snap_gizmo->use_snap_override != -1) { if (snap_gizmo->use_snap_override == false) { snap_gizmo->snap_elem = 0; @@ -318,6 +329,8 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz, } #endif + snap_gizmo->is_enabled = true; + float co[3], no[3]; short snap_elem = 0; int snap_elem_index[3] = {-1, -1, -1}; -- cgit v1.2.3