[Bf-blender-cvs] [355d1299654] master: Gizmo: lazy initialize snap context

Campbell Barton noreply at git.blender.org
Wed May 27 08:54:58 CEST 2020


Commit: 355d1299654aa9861318df500e4d532c612a1cb9
Author: Campbell Barton
Date:   Wed May 27 16:47:30 2020 +1000
Branches: master
https://developer.blender.org/rB355d1299654aa9861318df500e4d532c612a1cb9

Gizmo: lazy initialize snap context

ED_gizmotypes_snap_3d_context_get could have returned NULL,
rename _get(..) to _ensure(..) and initialize the snap context
in this function.

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

M	source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
M	source/blender/editors/include/ED_gizmo_library.h
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c

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

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 f6ad589778c..94ca34f19de 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
@@ -197,9 +197,16 @@ void ED_gizmotypes_snap_3d_draw_util(RegionView3D *rv3d,
   immUnbindProgram();
 }
 
-SnapObjectContext *ED_gizmotypes_snap_3d_context_get(wmGizmo *gz)
+SnapObjectContext *ED_gizmotypes_snap_3d_context_ensure(Scene *scene,
+                                                        const ARegion *region,
+                                                        const View3D *v3d,
+                                                        wmGizmo *gz)
 {
   SnapGizmo3D *gizmo_snap = (SnapGizmo3D *)gz;
+  if (gizmo_snap->snap_context_v3d == NULL) {
+    gizmo_snap->snap_context_v3d = ED_transform_snap_object_context_create_view3d(
+        NULL, scene, 0, region, v3d);
+  }
   return gizmo_snap->snap_context_v3d;
 }
 
@@ -252,6 +259,8 @@ short ED_gizmotypes_snap_3d_update(wmGizmo *gz,
     }
 
     float dist_px = 12.0f * U.pixelsize;
+
+    ED_gizmotypes_snap_3d_context_ensure(scene, region, v3d, gz);
     snap_elem = ED_transform_snap_object_project_view3d_ex(gizmo_snap->snap_context_v3d,
                                                            depsgraph,
                                                            snap_elements,
@@ -388,19 +397,16 @@ static int gizmo_snap_test_select(bContext *C, wmGizmo *gz, const int mval[2])
 #endif
   copy_v2_v2_int(gizmo_snap->mval, mval);
 
-  ARegion *region = CTX_wm_region(C);
-  View3D *v3d = CTX_wm_view3d(C);
-  if (gizmo_snap->snap_context_v3d == NULL) {
-    gizmo_snap->snap_context_v3d = ED_transform_snap_object_context_create_view3d(
-        NULL, CTX_data_scene(C), 0, region, v3d);
-
 #ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
+  if (gizmo_snap->keymap == NULL) {
     gizmo_snap->keymap = WM_modalkeymap_find(wm->defaultconf, "Generic Gizmo Tweak Modal Map");
     gizmo_snap->snap_on = -1;
     RNA_enum_value_from_id(gizmo_snap->keymap->modal_items, "SNAP_ON", &gizmo_snap->snap_on);
-#endif
   }
+#endif
 
+  ARegion *region = CTX_wm_region(C);
+  View3D *v3d = CTX_wm_view3d(C);
   const float mval_fl[2] = {UNPACK2(mval)};
   short snap_elem = ED_gizmotypes_snap_3d_update(
       gz, CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, mval_fl, NULL, NULL);
diff --git a/source/blender/editors/include/ED_gizmo_library.h b/source/blender/editors/include/ED_gizmo_library.h
index 47ecbd73c9a..20b7b755234 100644
--- a/source/blender/editors/include/ED_gizmo_library.h
+++ b/source/blender/editors/include/ED_gizmo_library.h
@@ -257,7 +257,10 @@ void ED_gizmotypes_snap_3d_draw_util(struct RegionView3D *rv3d,
                                      const uchar color_line[4],
                                      const uchar color_point[4],
                                      const short snap_elem_type);
-struct SnapObjectContext *ED_gizmotypes_snap_3d_context_get(struct wmGizmo *gz);
+struct SnapObjectContext *ED_gizmotypes_snap_3d_context_ensure(struct Scene *scene,
+                                                               const struct ARegion *region,
+                                                               const struct View3D *v3d,
+                                                               struct wmGizmo *gz);
 short ED_gizmotypes_snap_3d_update(struct wmGizmo *gz,
                                    struct Depsgraph *depsgraph,
                                    const struct ARegion *region,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 5d00a9ff950..1b378397420 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -59,6 +59,8 @@
 #include "WM_types.h"
 #include "wm.h"
 
+#include "DEG_depsgraph_query.h"
+
 #include "view3d_intern.h" /* own include */
 
 #include "GPU_immediate.h"
@@ -323,9 +325,10 @@ static bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph,
     copy_v3_v3(co, inter->drag_start_co);
     view3d_ruler_item_project(ruler_info, co, mval);
     if (do_thickness && inter->co_index != 1) {
-      // Scene *scene = CTX_data_scene(C);
-      // View3D *v3d = ruler_info->area->spacedata.first;
-      SnapObjectContext *snap_context = ED_gizmotypes_snap_3d_context_get(snap_gizmo);
+      Scene *scene = DEG_get_input_scene(depsgraph);
+      View3D *v3d = ruler_info->area->spacedata.first;
+      SnapObjectContext *snap_context = ED_gizmotypes_snap_3d_context_ensure(
+          scene, ruler_info->region, v3d, snap_gizmo);
       const float mval_fl[2] = {UNPACK2(mval)};
       float ray_normal[3];
       float ray_start[3];



More information about the Bf-blender-cvs mailing list