[Bf-blender-cvs] [0b8d2ab88c7] greasepencil-object: GPencil: Improve reproject operator in surface mode

Lukas W noreply at git.blender.org
Mon May 20 11:18:54 CEST 2019


Commit: 0b8d2ab88c70e39bf31414a90cbdaafe068f30a3
Author: Lukas W
Date:   Mon May 20 11:16:39 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0b8d2ab88c70e39bf31414a90cbdaafe068f30a3

GPencil: Improve reproject operator in surface mode

See D4878 by  Lukas W (@geloescht)

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

M	source/blender/editors/gpencil/gpencil_edit.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 9ef0657ae83..c973a7564dd 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -58,6 +58,7 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_workspace.h"
+#include "BKE_scene.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
@@ -76,6 +77,7 @@
 #include "ED_gpencil.h"
 #include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_transform_snap_object_context.h"
 #include "ED_view3d.h"
 #include "ED_select_utils.h"
 #include "ED_space_api.h"
@@ -3362,11 +3364,13 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
   Scene *scene = CTX_data_scene(C);
+  Main *bmain = CTX_data_main(C);
   ToolSettings *ts = CTX_data_tool_settings(C);
   Depsgraph *depsgraph = CTX_data_depsgraph(C);
   Object *ob = CTX_data_active_object(C);
   ARegion *ar = CTX_wm_region(C);
   RegionView3D *rv3d = ar->regiondata;
+  SnapObjectContext *sctx = NULL;
 
   GP_SpaceConversion gsc = {NULL};
   eGP_ReprojectModes mode = RNA_enum_get(op->ptr, "type");
@@ -3376,10 +3380,10 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
   /* init space conversion stuff */
   gp_point_conversion_init(C, &gsc);
 
-  /* init autodist for geometry projection */
+  /* init snap context for geometry projection */
   if (mode == GP_REPROJECT_SURFACE) {
-    view3d_region_operator_needs_opengl(CTX_wm_window(C), gsc.ar);
-    ED_view3d_autodist_init(depsgraph, gsc.ar, CTX_wm_view3d(C), 0);
+    sctx = ED_transform_snap_object_context_create_view3d(
+        bmain, scene, depsgraph, 0, ar, CTX_wm_view3d(C));
   }
 
   // TODO: For deforming geometry workflow, create new frames?
@@ -3461,17 +3465,26 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
         }
         else {
           /* Geometry - Snap to surfaces of visible geometry */
-          /* XXX: There will be precision loss (possible stairstep artifacts)
-           * from this conversion to satisfy the API's */
-          const int screen_co[2] = {(int)xy[0], (int)xy[1]};
-
-          int depth_margin = 0;  // XXX: 4 for strokes, 0 for normal
-          float depth;
-
-          /* XXX: The proper procedure computes the depths into an array,
-           * to have smooth transitions when all else fails... */
-          if (ED_view3d_autodist_depth(gsc.ar, screen_co, depth_margin, &depth)) {
-            ED_view3d_autodist_simple(gsc.ar, screen_co, &pt->x, 0, &depth);
+          float ray_start[3];
+          float ray_normal[3];
+          /* magic value for initial depth copied from the default
+           * value of Python's Scene.ray_cast function
+           */
+          float depth = 1.70141e+38f;
+          float location[3] = {0.0f, 0.0f, 0.0f};
+          float normal[3] = {0.0f, 0.0f, 0.0f};
+
+          ED_view3d_win_to_ray(ar, xy, &ray_start[0], &ray_normal[0]);
+          if (ED_transform_snap_object_project_ray(sctx,
+                                                   &(const struct SnapObjectParams){
+                                                       .snap_select = SNAP_ALL,
+                                                   },
+                                                   &ray_start[0],
+                                                   &ray_normal[0],
+                                                   &depth,
+                                                   &location[0],
+                                                   &normal[0])) {
+            copy_v3_v3(&pt->x, location);
           }
           else {
             /* Default to planar */
@@ -3490,6 +3503,9 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
 
   DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
   WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+  if (sctx != NULL) {
+    ED_transform_snap_object_context_destroy(sctx);
+  }
   return OPERATOR_FINISHED;
 }



More information about the Bf-blender-cvs mailing list