[Bf-blender-cvs] [3b51d9065c8] master: Cleanup: deduplicate retrieving data from context in curves brushes

Jacques Lucke noreply at git.blender.org
Fri Jun 3 13:40:07 CEST 2022


Commit: 3b51d9065c8aced32b3d506b55422d471bd4f7ff
Author: Jacques Lucke
Date:   Fri Jun 3 13:39:31 2022 +0200
Branches: master
https://developer.blender.org/rB3b51d9065c8aced32b3d506b55422d471bd4f7ff

Cleanup: deduplicate retrieving data from context in curves brushes

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

M	source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_delete.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_intern.hh
M	source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc

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

diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
index fea0e862707..390f142ac0f 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc
@@ -85,10 +85,7 @@ static void initialize_straight_curve_positions(const float3 &p1,
  */
 struct AddOperationExecutor {
   AddOperation *self_ = nullptr;
-  const Depsgraph *depsgraph_ = nullptr;
-  const Scene *scene_ = nullptr;
-  ARegion *region_ = nullptr;
-  const View3D *v3d_ = nullptr;
+  CurvesSculptCommonContext ctx_;
 
   Object *object_ = nullptr;
   Curves *curves_id_ = nullptr;
@@ -143,14 +140,14 @@ struct AddOperationExecutor {
   static constexpr int max_neighbors = 5;
   using NeighborsVector = Vector<NeighborInfo, max_neighbors>;
 
+  AddOperationExecutor(const bContext &C) : ctx_(C)
+  {
+  }
+
   void execute(AddOperation &self, const bContext &C, const StrokeExtension &stroke_extension)
   {
     self_ = &self;
-    depsgraph_ = CTX_data_depsgraph_pointer(&C);
-    scene_ = CTX_data_scene(&C);
     object_ = CTX_data_active_object(&C);
-    region_ = CTX_wm_region(&C);
-    v3d_ = CTX_wm_view3d(&C);
 
     curves_id_ = static_cast<Curves *>(object_->data);
     curves_ = &CurvesGeometry::wrap(curves_id_->geometry);
@@ -176,10 +173,10 @@ struct AddOperationExecutor {
         reinterpret_cast<const float3 *>(CustomData_get_layer(&surface_->ldata, CD_NORMAL)),
         surface_->totloop};
 
-    curves_sculpt_ = scene_->toolsettings->curves_sculpt;
+    curves_sculpt_ = ctx_.scene->toolsettings->curves_sculpt;
     brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
     brush_settings_ = brush_->curves_sculpt_settings;
-    brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension);
+    brush_radius_re_ = brush_radius_get(*ctx_.scene, *brush_, stroke_extension);
     brush_pos_re_ = stroke_extension.mouse_position;
 
     use_front_face_ = brush_->flag & BRUSH_FRONTFACE;
@@ -256,7 +253,7 @@ struct AddOperationExecutor {
 
     DEG_id_tag_update(&curves_id_->id, ID_RECALC_GEOMETRY);
     WM_main_add_notifier(NC_GEOM | ND_DATA, &curves_id_->id);
-    ED_region_tag_redraw(region_);
+    ED_region_tag_redraw(ctx_.region);
   }
 
   float3 get_bary_coords(const Mesh &mesh, const MLoopTri &looptri, const float3 position) const
@@ -276,7 +273,7 @@ struct AddOperationExecutor {
   {
     float3 ray_start_wo, ray_end_wo;
     ED_view3d_win_to_segment_clipped(
-        depsgraph_, region_, v3d_, brush_pos_re_, ray_start_wo, ray_end_wo, true);
+        ctx_.depsgraph, ctx_.region, ctx_.v3d, brush_pos_re_, ray_start_wo, ray_end_wo, true);
     const float3 ray_start_su = world_to_surface_mat_ * ray_start_wo;
     const float3 ray_end_su = world_to_surface_mat_ * ray_end_wo;
 
@@ -352,7 +349,7 @@ struct AddOperationExecutor {
 
       float3 ray_start_wo, ray_end_wo;
       ED_view3d_win_to_segment_clipped(
-          depsgraph_, region_, v3d_, pos_re, ray_start_wo, ray_end_wo, true);
+          ctx_.depsgraph, ctx_.region, ctx_.v3d, pos_re, ray_start_wo, ray_end_wo, true);
       const float3 ray_start_su = brush_transform * (world_to_surface_mat_ * ray_start_wo);
       const float3 ray_end_su = brush_transform * (world_to_surface_mat_ * ray_end_wo);
       const float3 ray_direction_su = math::normalize(ray_end_su - ray_start_su);
@@ -400,17 +397,22 @@ struct AddOperationExecutor {
   {
     /* Find ray that starts in the center of the brush. */
     float3 brush_ray_start_wo, brush_ray_end_wo;
-    ED_view3d_win_to_segment_clipped(
-        depsgraph_, region_, v3d_, brush_pos_re_, brush_ray_start_wo, brush_ray_end_wo, true);
+    ED_view3d_win_to_segment_clipped(ctx_.depsgraph,
+                                     ctx_.region,
+                                     ctx_.v3d,
+                                     brush_pos_re_,
+                                     brush_ray_start_wo,
+                                     brush_ray_end_wo,
+                                     true);
     const float3 brush_ray_start_su = world_to_surface_mat_ * brush_ray_start_wo;
     const float3 brush_ray_end_su = world_to_surface_mat_ * brush_ray_end_wo;
 
     /* Find ray that starts on the boundary of the brush. That is used to compute the brush radius
      * in 3D. */
     float3 brush_radius_ray_start_wo, brush_radius_ray_end_wo;
-    ED_view3d_win_to_segment_clipped(depsgraph_,
-                                     region_,
-                                     v3d_,
+    ED_view3d_win_to_segment_clipped(ctx_.depsgraph,
+                                     ctx_.region,
+                                     ctx_.v3d,
                                      brush_pos_re_ + float2(brush_radius_re_, 0),
                                      brush_radius_ray_start_wo,
                                      brush_radius_ray_end_wo,
@@ -895,7 +897,7 @@ struct AddOperationExecutor {
 
 void AddOperation::on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension)
 {
-  AddOperationExecutor executor;
+  AddOperationExecutor executor{C};
   executor.execute(*this, C, stroke_extension);
 }
 
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
index 92ce6ba3153..6ee660434c7 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
@@ -277,4 +277,13 @@ Vector<float4x4> get_symmetry_brush_transforms(const eCurvesSymmetryType symmetr
   return matrices;
 }
 
+CurvesSculptCommonContext::CurvesSculptCommonContext(const bContext &C)
+{
+  this->depsgraph = CTX_data_depsgraph_pointer(&C);
+  this->scene = CTX_data_scene(&C);
+  this->region = CTX_wm_region(&C);
+  this->v3d = CTX_wm_view3d(&C);
+  this->rv3d = CTX_wm_region_view3d(&C);
+}
+
 }  // namespace blender::ed::sculpt_paint
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
index 46332a66f60..408eea09976 100644
--- a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
+++ b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
@@ -78,11 +78,7 @@ class CombOperation : public CurvesSculptStrokeOperation {
  */
 struct CombOperationExecutor {
   CombOperation *self_ = nullptr;
-  const Depsgraph *depsgraph_ = nullptr;
-  const Scene *scene_ = nullptr;
-  ARegion *region_ = nullptr;
-  const View3D *v3d_ = nullptr;
-  const RegionView3D *rv3d_ = nullptr;
+  CurvesSculptCommonContext ctx_;
 
   const CurvesSculpt *curves_sculpt_ = nullptr;
   const Brush *brush_ = nullptr;
@@ -116,24 +112,23 @@ struct CombOperationExecutor {
 
   BVHTreeFromMesh surface_bvh_;
 
+  CombOperationExecutor(const bContext &C) : ctx_(C)
+  {
+  }
+
   void execute(CombOperation &self, const bContext &C, const StrokeExtension &stroke_extension)
   {
     self_ = &self;
 
     BLI_SCOPED_DEFER([&]() { self_->brush_pos_last_re_ = stroke_extension.mouse_position; });
 
-    depsgraph_ = CTX_data_depsgraph_pointer(&C);
-    scene_ = CTX_data_scene(&C);
     object_ = CTX_data_active_object(&C);
-    region_ = CTX_wm_region(&C);
-    v3d_ = CTX_wm_view3d(&C);
-    rv3d_ = CTX_wm_region_view3d(&C);
 
-    curves_sculpt_ = scene_->toolsettings->curves_sculpt;
+    curves_sculpt_ = ctx_.scene->toolsettings->curves_sculpt;
     brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint);
-    brush_radius_base_re_ = BKE_brush_size_get(scene_, brush_);
+    brush_radius_base_re_ = BKE_brush_size_get(ctx_.scene, brush_);
     brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension);
-    brush_strength_ = brush_strength_get(*scene_, *brush_, stroke_extension);
+    brush_strength_ = brush_strength_get(*ctx_.scene, *brush_, stroke_extension);
 
     curves_to_world_mat_ = object_->obmat;
     world_to_curves_mat_ = curves_to_world_mat_.inverted();
@@ -196,7 +191,7 @@ struct CombOperationExecutor {
     curves_->tag_positions_changed();
     DEG_id_tag_update(&curves_id_->id, ID_RECALC_GEOMETRY);
     WM_main_add_notifier(NC_GEOM | ND_DATA, &curves_id_->id);
-    ED_region_tag_redraw(region_);
+    ED_region_tag_redraw(ctx_.region);
   }
 
   /**
@@ -219,7 +214,7 @@ struct CombOperationExecutor {
     MutableSpan<float3> positions_cu = curves_->positions_for_write();
 
     float4x4 projection;
-    ED_view3d_ob_project_mat_get(rv3d_, object_, projection.values);
+    ED_view3d_ob_project_mat_get(ctx_.rv3d, object_, projection.values);
 
     const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_;
     const float brush_radius_sq_re = pow2f(brush_radius_re);
@@ -234,7 +229,7 @@ struct CombOperationExecutor {
 
           /* Find the position of the point in screen space. */
           float2 old_pos_re;
-          ED_view3d_project_float_v2_m4(region_, old_pos_cu, old_pos_re, projection.values);
+          ED_view3d_project_float_v2_m4(ctx_.region, old_pos_cu, old_pos_re, projection.values);
 
           const float distance_to_brush_sq_re = dist_squared_to_line_segment_v2(
               old_pos_re, brush_pos_prev_re_, brush_pos_re_);
@@ -254,8 +249,11 @@ struct CombOperationExecutor {
            */
           const float2 new_position_re = old_pos_re + brush_pos_diff_re_ * weight;
           float3 new_position_wo;
-          ED_view3d_win_to_3d(
-              v3d_, region_, curves_to_world_mat_ * old_pos_cu, new_position_re, new_position_wo);
+          ED_view3d_win_to_3d(ctx_.v3d,
+                              ctx_.region,
+                              curves_to_world_mat_ * old_pos_cu,
+                              new_position_re,
+                              new_position_wo);
           const float3 new_position_cu = brush_transform *
                                          (world_to_curves_mat_ * new_position_wo);
           positions_cu[point_i] = new_position_cu;
@@ -275,16 +273,16 @@ struct CombOperationExecutor {
   void comb_spherical_with_symmetry(EnumerableThreadSpecific<Vector<int>> &r_changed_curves)
   {
     float4x4 projection;
-    ED_view3d_ob_project_mat_get(rv3d_, object_, projection.values);
+    ED_view3d

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list