[Bf-blender-cvs] [eed48a73222] blender-v3.0-release: Cleanup: reference some snap parameters in the snap context itself

Germano Cavalcante noreply at git.blender.org
Sat Nov 13 01:36:14 CET 2021


Commit: eed48a73222efb86b53cdd99079f8c26eba30e57
Author: Germano Cavalcante
Date:   Fri Nov 12 21:26:45 2021 -0300
Branches: blender-v3.0-release
https://developer.blender.org/rBeed48a73222efb86b53cdd99079f8c26eba30e57

Cleanup: reference some snap parameters in the snap context itself

This decreases the number of parameters in functions and makes important variables available in more places.

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

M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 3254d56d795..f3b8ef98101 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -125,6 +125,8 @@ struct SnapObjectContext {
     const ARegion *region;
     const View3D *v3d;
 
+    const struct SnapObjectParams *params;
+
     float mval[2];
     float pmat[4][4];  /* perspective matrix */
     float win_size[2]; /* win x and y */
@@ -444,8 +446,6 @@ static SnapObjectData *snap_object_data_editmesh_get(SnapObjectContext *sctx,
 typedef void (*IterSnapObjsCallback)(SnapObjectContext *sctx,
                                      Object *ob_eval,
                                      float obmat[4][4],
-                                     eSnapEditType edit_mode_type,
-                                     bool use_backface_culling,
                                      bool is_object_active,
                                      void *data);
 
@@ -453,20 +453,16 @@ typedef void (*IterSnapObjsCallback)(SnapObjectContext *sctx,
  * Walks through all objects in the scene to create the list of objects to snap.
  */
 static void iter_snap_objects(SnapObjectContext *sctx,
-                              const struct SnapObjectParams *params,
                               IterSnapObjsCallback sob_callback,
                               void *data)
 {
   ViewLayer *view_layer = DEG_get_input_view_layer(sctx->runtime.depsgraph);
-  const eSnapSelect snap_select = params->snap_select;
-  const eSnapEditType edit_mode_type = params->edit_mode_type;
-  const bool use_backface_culling = params->use_backface_culling;
+  const eSnapSelect snap_select = sctx->runtime.params->snap_select;
 
   Base *base_act = view_layer->basact;
   if (snap_select == SNAP_ONLY_ACTIVE) {
     Object *obj_eval = DEG_get_evaluated_object(sctx->runtime.depsgraph, base_act->object);
-    sob_callback(
-        sctx, obj_eval, obj_eval->obmat, edit_mode_type, use_backface_culling, true, data);
+    sob_callback(sctx, obj_eval, obj_eval->obmat, true, data);
     return;
   }
 
@@ -504,24 +500,12 @@ static void iter_snap_objects(SnapObjectContext *sctx,
       ListBase *lb = object_duplilist(sctx->runtime.depsgraph, sctx->scene, obj_eval);
       for (DupliObject *dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
         BLI_assert(DEG_is_evaluated_object(dupli_ob->ob));
-        sob_callback(sctx,
-                     dupli_ob->ob,
-                     dupli_ob->mat,
-                     edit_mode_type,
-                     use_backface_culling,
-                     is_object_active,
-                     data);
+        sob_callback(sctx, dupli_ob->ob, dupli_ob->mat, is_object_active, data);
       }
       free_object_duplilist(lb);
     }
 
-    sob_callback(sctx,
-                 obj_eval,
-                 obj_eval->obmat,
-                 edit_mode_type,
-                 use_backface_culling,
-                 is_object_active,
-                 data);
+    sob_callback(sctx, obj_eval, obj_eval->obmat, is_object_active, data);
   }
 }
 
@@ -688,7 +672,6 @@ static bool raycastMesh(SnapObjectContext *sctx,
                         const float obmat[4][4],
                         const uint ob_index,
                         bool use_hide,
-                        bool use_backface_culling,
                         /* read/write args */
                         float *ray_depth,
                         /* return args */
@@ -790,8 +773,9 @@ static bool raycastMesh(SnapObjectContext *sctx,
                              ray_normal_local,
                              0.0f,
                              &hit,
-                             use_backface_culling ? mesh_looptri_raycast_backface_culling_cb :
-                                                    treedata->raycast_callback,
+                             sctx->runtime.params->use_backface_culling ?
+                                 mesh_looptri_raycast_backface_culling_cb :
+                                 treedata->raycast_callback,
                              treedata) != -1) {
       hit.dist += len_diff;
       hit.dist /= local_scale;
@@ -827,7 +811,6 @@ static bool raycastEditMesh(SnapObjectContext *sctx,
                             BMEditMesh *em,
                             const float obmat[4][4],
                             const uint ob_index,
-                            bool use_backface_culling,
                             /* read/write args */
                             float *ray_depth,
                             /* return args */
@@ -960,8 +943,9 @@ static bool raycastEditMesh(SnapObjectContext *sctx,
                              ray_normal_local,
                              0.0f,
                              &hit,
-                             use_backface_culling ? editmesh_looptri_raycast_backface_culling_cb :
-                                                    treedata->raycast_callback,
+                             sctx->runtime.params->use_backface_culling ?
+                                 editmesh_looptri_raycast_backface_culling_cb :
+                                 treedata->raycast_callback,
                              treedata) != -1) {
       hit.dist += len_diff;
       hit.dist /= local_scale;
@@ -1014,13 +998,8 @@ struct RaycastObjUserData {
  *
  * \note Duplicate args here are documented at #snapObjectsRay
  */
-static void raycast_obj_fn(SnapObjectContext *sctx,
-                           Object *ob_eval,
-                           float obmat[4][4],
-                           eSnapEditType edit_mode_type,
-                           bool use_backface_culling,
-                           bool is_object_active,
-                           void *data)
+static void raycast_obj_fn(
+    SnapObjectContext *sctx, Object *ob_eval, float obmat[4][4], bool is_object_active, void *data)
 {
   struct RaycastObjUserData *dt = data;
   const uint ob_index = dt->ob_index++;
@@ -1039,6 +1018,7 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
 
   switch (ob_eval->type) {
     case OB_MESH: {
+      const eSnapEditType edit_mode_type = sctx->runtime.params->edit_mode_type;
       bool use_hide = false;
       Mesh *me_eval = mesh_for_snap(ob_eval, edit_mode_type, &use_hide);
       if (me_eval == NULL) {
@@ -1051,7 +1031,6 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
                                  em_orig,
                                  obmat,
                                  ob_index,
-                                 use_backface_culling,
                                  ray_depth,
                                  dt->r_loc,
                                  dt->r_no,
@@ -1067,7 +1046,6 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
                            obmat,
                            ob_index,
                            use_hide,
-                           use_backface_culling,
                            ray_depth,
                            dt->r_loc,
                            dt->r_no,
@@ -1089,7 +1067,6 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
                                obmat,
                                ob_index,
                                false,
-                               use_backface_culling,
                                ray_depth,
                                dt->r_loc,
                                dt->r_no,
@@ -1119,7 +1096,6 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
  * Walks through all objects in the scene to find the `hit` on object surface.
  *
  * \param sctx: Snap context to store data.
- * \param params: Snapping behavior.
  *
  * Read/Write Args
  * ---------------
@@ -1139,9 +1115,6 @@ static void raycast_obj_fn(SnapObjectContext *sctx,
  * \param r_hit_list: List of #SnapObjectHitDepth (caller must free).
  */
 static bool raycastObjects(SnapObjectContext *sctx,
-                           Depsgraph *depsgraph,
-                           const View3D *v3d,
-                           const struct SnapObjectParams *params,
                            const float ray_start[3],
                            const float ray_dir[3],
                            /* read/write args */
@@ -1156,6 +1129,8 @@ static bool raycastObjects(SnapObjectContext *sctx,
                            float r_obmat[4][4],
                            ListBase *r_hit_list)
 {
+  const struct SnapObjectParams *params = sctx->runtime.params;
+  const View3D *v3d = sctx->runtime.v3d;
   if (params->use_occlusion_test && v3d && XRAY_FLAG_ENABLED(v3d)) {
     /* General testing of occlusion geometry is disabled if the snap is not intended for the edit
      * cage. */
@@ -1164,9 +1139,6 @@ static bool raycastObjects(SnapObjectContext *sctx,
     }
   }
 
-  sctx->runtime.depsgraph = depsgraph;
-  sctx->runtime.v3d = v3d;
-
   struct RaycastObjUserData data = {
       .ray_start = ray_start,
       .ray_dir = ray_dir,
@@ -1182,7 +1154,7 @@ static bool raycastObjects(SnapObjectContext *sctx,
       .ret = false,
   };
 
-  iter_snap_objects(sctx, params, raycast_obj_fn, &data);
+  iter_snap_objects(sctx, raycast_obj_fn, &data);
 
   return data.ret;
 }
@@ -1561,7 +1533,6 @@ static void cb_snap_tri_verts(void *userdata,
 static short snap_mesh_polygon(SnapObjectContext *sctx,
                                Object *ob_eval,
                                const float obmat[4][4],
-                               bool use_backface_culling,
                                /* read/write args */
                                float *dist_px,
                                /* return args */
@@ -1593,8 +1564,10 @@ static short snap_mesh_polygon(SnapObjectContext *sctx,
   BLI_assert(sod != NULL);
 
   Nearest2dUserData nearest2d;
-  nearest2d_data_init(
-      sod, sctx->runtime.view_proj == VIEW_PROJ_PERSP, use_backface_culling, &nearest2d);
+  nearest2d_data_init(sod,
+                      sctx->runtime.view_proj == VIEW_PROJ_PERSP,
+                      sctx->runtime.params->use_backface_culling,
+                      &nearest2d);
 
   if (sod->type == SNAP_MES

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list