From ed62b65474f007025bc19d1f8758257b12cbc8b3 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 17 May 2022 13:06:14 +0200 Subject: Cleanup: Use const in curves sculpt code This makes it much clearer what data is supposed to be modified and what data is just used to influence the operation. The new `BKE_paint_brush_for_read` function isn't great design, but it can be removed or renamed if similar changes are applied to more places. Also pass pointers explicitly to `sample_curves_3d_brush` rather than reusing the `bContext`. This makes it clearer what data the function actually needs. Differential Revision: https://developer.blender.org/D14967 --- source/blender/blenkernel/BKE_paint.h | 1 + source/blender/blenkernel/intern/paint.c | 5 ++ .../editors/sculpt_paint/curves_sculpt_add.cc | 40 ++++++++------- .../editors/sculpt_paint/curves_sculpt_brush.cc | 24 ++++----- .../editors/sculpt_paint/curves_sculpt_comb.cc | 38 +++++++------- .../editors/sculpt_paint/curves_sculpt_delete.cc | 39 +++++++-------- .../sculpt_paint/curves_sculpt_grow_shrink.cc | 58 ++++++++++++---------- .../editors/sculpt_paint/curves_sculpt_intern.hh | 18 ++++--- .../editors/sculpt_paint/curves_sculpt_ops.cc | 4 +- .../sculpt_paint/curves_sculpt_snake_hook.cc | 40 ++++++++------- 10 files changed, 144 insertions(+), 123 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 03cbcf575c3..c39ab22ce3a 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -180,6 +180,7 @@ struct Paint *BKE_paint_get_active_from_context(const struct bContext *C); ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C); ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref); struct Brush *BKE_paint_brush(struct Paint *paint); +const struct Brush *BKE_paint_brush_for_read(const struct Paint *p); void BKE_paint_brush_set(struct Paint *paint, struct Brush *br); struct Palette *BKE_paint_palette(struct Paint *paint); void BKE_paint_palette_set(struct Paint *p, struct Palette *palette); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index caada8da0de..cff7eb20b05 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -605,6 +605,11 @@ ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref) } Brush *BKE_paint_brush(Paint *p) +{ + return (Brush *)BKE_paint_brush_for_read((const Paint *)p); +} + +const Brush *BKE_paint_brush_for_read(const Paint *p) { return p ? p->brush : NULL; } diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc index 5539fda750f..04ae6c62aee 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc @@ -66,7 +66,7 @@ class AddOperation : public CurvesSculptStrokeOperation { } } - void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; + void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override; }; static void initialize_straight_curve_positions(const float3 &p1, @@ -85,11 +85,12 @@ static void initialize_straight_curve_positions(const float3 &p1, */ struct AddOperationExecutor { AddOperation *self_ = nullptr; - Depsgraph *depsgraph_ = nullptr; - Scene *scene_ = nullptr; - Object *object_ = nullptr; + const Depsgraph *depsgraph_ = nullptr; + const Scene *scene_ = nullptr; ARegion *region_ = nullptr; - View3D *v3d_ = nullptr; + const View3D *v3d_ = nullptr; + + Object *object_ = nullptr; Curves *curves_id_ = nullptr; CurvesGeometry *curves_ = nullptr; @@ -98,9 +99,9 @@ struct AddOperationExecutor { Span surface_looptris_; Span corner_normals_su_; - CurvesSculpt *curves_sculpt_ = nullptr; - Brush *brush_ = nullptr; - BrushCurvesSculptSettings *brush_settings_ = nullptr; + const CurvesSculpt *curves_sculpt_ = nullptr; + const Brush *brush_ = nullptr; + const BrushCurvesSculptSettings *brush_settings_ = nullptr; float brush_radius_re_; float2 brush_pos_re_; @@ -142,14 +143,14 @@ struct AddOperationExecutor { static constexpr int max_neighbors = 5; using NeighborsVector = Vector; - void execute(AddOperation &self, bContext *C, const StrokeExtension &stroke_extension) + 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); + 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(object_->data); curves_ = &CurvesGeometry::wrap(curves_id_->geometry); @@ -176,7 +177,7 @@ struct AddOperationExecutor { surface_->totloop}; curves_sculpt_ = scene_->toolsettings->curves_sculpt; - brush_ = BKE_paint_brush(&curves_sculpt_->paint); + brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint); brush_settings_ = brush_->curves_sculpt_settings; brush_radius_re_ = BKE_brush_size_get(scene_, brush_); brush_pos_re_ = stroke_extension.mouse_position; @@ -864,17 +865,18 @@ struct AddOperationExecutor { } }; -void AddOperation::on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) +void AddOperation::on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) { AddOperationExecutor executor; executor.execute(*this, C, stroke_extension); } -std::unique_ptr new_add_operation(bContext &C, ReportList *reports) +std::unique_ptr new_add_operation(const bContext &C, + ReportList *reports) { - Object &ob_active = *CTX_data_active_object(&C); + const Object &ob_active = *CTX_data_active_object(&C); BLI_assert(ob_active.type == OB_CURVES); - Curves &curves_id = *static_cast(ob_active.data); + const Curves &curves_id = *static_cast(ob_active.data); if (curves_id.surface == nullptr || curves_id.surface->type != OB_MESH) { BKE_report(reports, RPT_WARNING, "Can not use Add brush when there is no surface mesh"); return {}; diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc index dee9615ce76..9ebbf72806e 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc @@ -141,23 +141,21 @@ static std::optional find_curves_brush_position(const CurvesGeometry &cu return best_candidate.position_cu; } -std::optional sample_curves_3d_brush(bContext &C, - Object &curves_object, +std::optional sample_curves_3d_brush(const Depsgraph &depsgraph, + const ARegion ®ion, + const View3D &v3d, + const RegionView3D &rv3d, + const Object &curves_object, const float2 &brush_pos_re, const float brush_radius_re) { - const Depsgraph *depsgraph = CTX_data_depsgraph_pointer(&C); - const ARegion *region = CTX_wm_region(&C); - const View3D *v3d = CTX_wm_view3d(&C); - const RegionView3D *rv3d = CTX_wm_region_view3d(&C); - const Curves &curves_id = *static_cast(curves_object.data); const CurvesGeometry &curves = CurvesGeometry::wrap(curves_id.geometry); const Object *surface_object = curves_id.surface; float3 center_ray_start_wo, center_ray_end_wo; ED_view3d_win_to_segment_clipped( - depsgraph, region, v3d, brush_pos_re, center_ray_start_wo, center_ray_end_wo, true); + &depsgraph, ®ion, &v3d, brush_pos_re, center_ray_start_wo, center_ray_end_wo, true); /* Shorten ray when the surface object is hit. */ if (surface_object != nullptr) { @@ -205,8 +203,8 @@ std::optional sample_curves_3d_brush(bContext &C, center_ray_start_cu, center_ray_end_cu, brush_radius_re, - *region, - *rv3d, + region, + rv3d, curves_object); if (!brush_position_optional_cu.has_value()) { /* Nothing found. */ @@ -216,9 +214,9 @@ std::optional sample_curves_3d_brush(bContext &C, /* Determine the 3D brush radius. */ float3 radius_ray_start_wo, radius_ray_end_wo; - ED_view3d_win_to_segment_clipped(depsgraph, - region, - v3d, + ED_view3d_win_to_segment_clipped(&depsgraph, + ®ion, + &v3d, brush_pos_re + float2(brush_radius_re, 0.0f), radius_ray_start_wo, radius_ray_end_wo, diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc index 41199be8886..72257659c52 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc @@ -69,7 +69,7 @@ class CombOperation : public CurvesSculptStrokeOperation { friend struct CombOperationExecutor; public: - void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; + void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override; }; /** @@ -78,21 +78,20 @@ class CombOperation : public CurvesSculptStrokeOperation { */ struct CombOperationExecutor { CombOperation *self_ = nullptr; - bContext *C_ = nullptr; - Depsgraph *depsgraph_ = nullptr; - Scene *scene_ = nullptr; - Object *object_ = nullptr; + const Depsgraph *depsgraph_ = nullptr; + const Scene *scene_ = nullptr; ARegion *region_ = nullptr; - View3D *v3d_ = nullptr; - RegionView3D *rv3d_ = nullptr; + const View3D *v3d_ = nullptr; + const RegionView3D *rv3d_ = nullptr; - CurvesSculpt *curves_sculpt_ = nullptr; - Brush *brush_ = nullptr; + const CurvesSculpt *curves_sculpt_ = nullptr; + const Brush *brush_ = nullptr; float brush_radius_re_; float brush_strength_; eBrushFalloffShape falloff_shape_; + Object *object_ = nullptr; Curves *curves_id_ = nullptr; CurvesGeometry *curves_ = nullptr; @@ -112,22 +111,21 @@ struct CombOperationExecutor { BVHTreeFromMesh surface_bvh_; - void execute(CombOperation &self, bContext *C, const StrokeExtension &stroke_extension) + 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; }); - C_ = C; - 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); + 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; - brush_ = BKE_paint_brush(&curves_sculpt_->paint); + brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint); brush_radius_re_ = BKE_brush_size_get(scene_, brush_); brush_strength_ = BKE_brush_alpha_get(scene_, brush_); @@ -344,7 +342,7 @@ struct CombOperationExecutor { void initialize_spherical_brush_reference_point() { std::optional brush_3d = sample_curves_3d_brush( - *C_, *object_, brush_pos_re_, brush_radius_re_); + *depsgraph_, *region_, *v3d_, *rv3d_, *object_, brush_pos_re_, brush_radius_re_); if (brush_3d.has_value()) { self_->brush_3d_ = *brush_3d; } @@ -396,7 +394,7 @@ struct CombOperationExecutor { } }; -void CombOperation::on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) +void CombOperation::on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) { CombOperationExecutor executor; executor.execute(*this, C, stroke_extension); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc index 87d44b63412..f07c0a65933 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc @@ -57,24 +57,23 @@ class DeleteOperation : public CurvesSculptStrokeOperation { friend struct DeleteOperationExecutor; public: - void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; + void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override; }; struct DeleteOperationExecutor { DeleteOperation *self_ = nullptr; - bContext *C_ = nullptr; - Depsgraph *depsgraph_ = nullptr; - Scene *scene_ = nullptr; - Object *object_ = nullptr; + const Depsgraph *depsgraph_ = nullptr; + const Scene *scene_ = nullptr; ARegion *region_ = nullptr; - View3D *v3d_ = nullptr; - RegionView3D *rv3d_ = nullptr; + const View3D *v3d_ = nullptr; + const RegionView3D *rv3d_ = nullptr; + Object *object_ = nullptr; Curves *curves_id_ = nullptr; CurvesGeometry *curves_ = nullptr; - CurvesSculpt *curves_sculpt_ = nullptr; - Brush *brush_ = nullptr; + const CurvesSculpt *curves_sculpt_ = nullptr; + const Brush *brush_ = nullptr; float brush_radius_re_; float2 brush_pos_re_; @@ -83,24 +82,23 @@ struct DeleteOperationExecutor { float4x4 curves_to_world_mat_; float4x4 world_to_curves_mat_; - void execute(DeleteOperation &self, bContext *C, const StrokeExtension &stroke_extension) + void execute(DeleteOperation &self, const bContext &C, const StrokeExtension &stroke_extension) { BLI_SCOPED_DEFER([&]() { self.brush_pos_prev_re_ = stroke_extension.mouse_position; }); self_ = &self; - C_ = C; - 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); + 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_id_ = static_cast(object_->data); curves_ = &CurvesGeometry::wrap(curves_id_->geometry); curves_sculpt_ = scene_->toolsettings->curves_sculpt; - brush_ = BKE_paint_brush(&curves_sculpt_->paint); + brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint); brush_radius_re_ = BKE_brush_size_get(scene_, brush_); brush_pos_re_ = stroke_extension.mouse_position; @@ -248,14 +246,15 @@ struct DeleteOperationExecutor { void initialize_spherical_brush_reference_point() { std::optional brush_3d = sample_curves_3d_brush( - *C_, *object_, brush_pos_re_, brush_radius_re_); + *depsgraph_, *region_, *v3d_, *rv3d_, *object_, brush_pos_re_, brush_radius_re_); if (brush_3d.has_value()) { self_->brush_3d_ = *brush_3d; } } }; -void DeleteOperation::on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) +void DeleteOperation::on_stroke_extended(const bContext &C, + const StrokeExtension &stroke_extension) { DeleteOperationExecutor executor; executor.execute(*this, C, stroke_extension); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc b/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc index e4963fd4ca4..d10cf239dd2 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc @@ -70,10 +70,10 @@ class CurvesEffect { */ class ShrinkCurvesEffect : public CurvesEffect { private: - Brush &brush_; + const Brush &brush_; public: - ShrinkCurvesEffect(Brush &brush) : brush_(brush) + ShrinkCurvesEffect(const Brush &brush) : brush_(brush) { } @@ -205,10 +205,10 @@ class ExtrapolateCurvesEffect : public CurvesEffect { class ScaleCurvesEffect : public CurvesEffect { private: bool scale_up_; - Brush &brush_; + const Brush &brush_; public: - ScaleCurvesEffect(bool scale_up, Brush &brush) : scale_up_(scale_up), brush_(brush) + ScaleCurvesEffect(bool scale_up, const Brush &brush) : scale_up_(scale_up), brush_(brush) { } @@ -263,7 +263,7 @@ class CurvesEffectOperation : public CurvesSculptStrokeOperation { { } - void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; + void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override; }; /** @@ -272,17 +272,17 @@ class CurvesEffectOperation : public CurvesSculptStrokeOperation { */ struct CurvesEffectOperationExecutor { CurvesEffectOperation *self_ = nullptr; - Depsgraph *depsgraph_ = nullptr; - Scene *scene_ = nullptr; - Object *object_ = nullptr; + const Depsgraph *depsgraph_ = nullptr; + const Scene *scene_ = nullptr; ARegion *region_ = nullptr; - View3D *v3d_ = nullptr; - RegionView3D *rv3d_ = nullptr; + const View3D *v3d_ = nullptr; + const RegionView3D *rv3d_ = nullptr; + Object *object_ = nullptr; Curves *curves_id_ = nullptr; CurvesGeometry *curves_ = nullptr; - Brush *brush_ = nullptr; + const Brush *brush_ = nullptr; float brush_radius_re_; float brush_radius_sq_re_; float brush_strength_; @@ -299,17 +299,19 @@ struct CurvesEffectOperationExecutor { Vector move_distances_cu; }; - void execute(CurvesEffectOperation &self, bContext *C, const StrokeExtension &stroke_extension) + void execute(CurvesEffectOperation &self, + const bContext &C, + const StrokeExtension &stroke_extension) { BLI_SCOPED_DEFER([&]() { self.last_mouse_position_ = stroke_extension.mouse_position; }); 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); - rv3d_ = CTX_wm_region_view3d(C); + 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_id_ = static_cast(object_->data); curves_ = &CurvesGeometry::wrap(curves_id_->geometry); @@ -317,8 +319,8 @@ struct CurvesEffectOperationExecutor { return; } - CurvesSculpt &curves_sculpt = *scene_->toolsettings->curves_sculpt; - brush_ = BKE_paint_brush(&curves_sculpt.paint); + const CurvesSculpt &curves_sculpt = *scene_->toolsettings->curves_sculpt; + brush_ = BKE_paint_brush_for_read(&curves_sculpt.paint); brush_radius_re_ = BKE_brush_size_get(scene_, brush_); brush_strength_ = BKE_brush_alpha_get(scene_, brush_); brush_radius_sq_re_ = pow2f(brush_radius_re_); @@ -333,7 +335,13 @@ struct CurvesEffectOperationExecutor { if (stroke_extension.is_first) { if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) { if (std::optional brush_3d = sample_curves_3d_brush( - *C, *object_, stroke_extension.mouse_position, brush_radius_re_)) { + *depsgraph_, + *region_, + *v3d_, + *rv3d_, + *object_, + stroke_extension.mouse_position, + brush_radius_re_)) { self.brush_3d_ = *brush_3d; } } @@ -520,7 +528,7 @@ struct CurvesEffectOperationExecutor { } }; -void CurvesEffectOperation::on_stroke_extended(bContext *C, +void CurvesEffectOperation::on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) { CurvesEffectOperationExecutor executor; @@ -528,10 +536,10 @@ void CurvesEffectOperation::on_stroke_extended(bContext *C, } std::unique_ptr new_grow_shrink_operation( - const BrushStrokeMode brush_mode, bContext *C) + const BrushStrokeMode brush_mode, const bContext &C) { - Scene &scene = *CTX_data_scene(C); - Brush &brush = *BKE_paint_brush(&scene.toolsettings->curves_sculpt->paint); + const Scene &scene = *CTX_data_scene(&C); + const Brush &brush = *BKE_paint_brush_for_read(&scene.toolsettings->curves_sculpt->paint); const bool use_scale_uniform = brush.curves_sculpt_settings->flag & BRUSH_CURVES_SCULPT_FLAG_SCALE_UNIFORM; const bool use_grow = (brush_mode == BRUSH_STROKE_INVERT) == ((brush.flag & BRUSH_DIR_IN) != 0); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh index 9d000649d62..00e7213b5e6 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh @@ -13,6 +13,8 @@ struct ARegion; struct RegionView3D; +struct Depsgraph; +struct View3D; struct Object; namespace blender::ed::sculpt_paint { @@ -30,15 +32,16 @@ struct StrokeExtension { class CurvesSculptStrokeOperation { public: virtual ~CurvesSculptStrokeOperation() = default; - virtual void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) = 0; + virtual void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) = 0; }; -std::unique_ptr new_add_operation(bContext &C, ReportList *reports); +std::unique_ptr new_add_operation(const bContext &C, + ReportList *reports); std::unique_ptr new_comb_operation(); std::unique_ptr new_delete_operation(); std::unique_ptr new_snake_hook_operation(); std::unique_ptr new_grow_shrink_operation( - const BrushStrokeMode brush_mode, bContext *C); + const BrushStrokeMode brush_mode, const bContext &C); struct CurvesBrush3D { float3 position_cu; @@ -48,10 +51,13 @@ struct CurvesBrush3D { /** * Find 3d brush position based on cursor position for curves sculpting. */ -std::optional sample_curves_3d_brush(bContext &C, - Object &curves_object, +std::optional sample_curves_3d_brush(const Depsgraph &depsgraph, + const ARegion ®ion, + const View3D &v3d, + const RegionView3D &rv3d, + const Object &curves_object, const float2 &brush_pos_re, - float brush_radius_re); + const float brush_radius_re); Vector get_symmetry_brush_transforms(eCurvesSymmetryType symmetry); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc index d8713c8eb1d..776da37205c 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_ops.cc @@ -92,7 +92,7 @@ static std::unique_ptr start_brush_operation(bConte case CURVES_SCULPT_TOOL_ADD: return new_add_operation(C, op.reports); case CURVES_SCULPT_TOOL_GROW_SHRINK: - return new_grow_shrink_operation(mode, &C); + return new_grow_shrink_operation(mode, C); } BLI_assert_unreachable(); return {}; @@ -138,7 +138,7 @@ static void stroke_update_step(bContext *C, } if (op_data->operation) { - op_data->operation->on_stroke_extended(C, stroke_extension); + op_data->operation->on_stroke_extended(*C, stroke_extension); } } diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc index 973751e9045..e009b443839 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc @@ -63,7 +63,7 @@ class SnakeHookOperation : public CurvesSculptStrokeOperation { friend struct SnakeHookOperatorExecutor; public: - void on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) override; + void on_stroke_extended(const bContext &C, const StrokeExtension &stroke_extension) override; }; /** @@ -72,19 +72,19 @@ class SnakeHookOperation : public CurvesSculptStrokeOperation { */ struct SnakeHookOperatorExecutor { SnakeHookOperation *self_ = nullptr; - bContext *C_ = nullptr; - Scene *scene_ = nullptr; - Object *object_ = nullptr; + const Depsgraph *depsgraph_ = nullptr; + const Scene *scene_ = nullptr; ARegion *region_ = nullptr; - View3D *v3d_ = nullptr; - RegionView3D *rv3d_ = nullptr; + const View3D *v3d_ = nullptr; + const RegionView3D *rv3d_ = nullptr; - CurvesSculpt *curves_sculpt_ = nullptr; - Brush *brush_ = nullptr; + const CurvesSculpt *curves_sculpt_ = nullptr; + const Brush *brush_ = nullptr; float brush_radius_re_; float brush_strength_; eBrushFalloffShape falloff_shape_; + Object *object_ = nullptr; Curves *curves_id_ = nullptr; CurvesGeometry *curves_ = nullptr; @@ -95,20 +95,23 @@ struct SnakeHookOperatorExecutor { float2 brush_pos_re_; float2 brush_pos_diff_re_; - void execute(SnakeHookOperation &self, bContext *C, const StrokeExtension &stroke_extension) + void execute(SnakeHookOperation &self, + const bContext &C, + const StrokeExtension &stroke_extension) { BLI_SCOPED_DEFER([&]() { self.last_mouse_position_re_ = stroke_extension.mouse_position; }); self_ = &self; - C_ = 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); + depsgraph_ = CTX_data_depsgraph_pointer(&C); + scene_ = CTX_data_scene(&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; - brush_ = BKE_paint_brush(&curves_sculpt_->paint); + brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint); brush_radius_re_ = BKE_brush_size_get(scene_, brush_); brush_strength_ = BKE_brush_alpha_get(scene_, brush_); falloff_shape_ = static_cast(brush_->falloff_shape); @@ -129,7 +132,7 @@ struct SnakeHookOperatorExecutor { if (stroke_extension.is_first) { if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) { std::optional brush_3d = sample_curves_3d_brush( - *C_, *object_, brush_pos_re_, brush_radius_re_); + *depsgraph_, *region_, *v3d_, *rv3d_, *object_, brush_pos_re_, brush_radius_re_); if (brush_3d.has_value()) { self_->brush_3d_ = *brush_3d; } @@ -295,7 +298,8 @@ struct SnakeHookOperatorExecutor { } }; -void SnakeHookOperation::on_stroke_extended(bContext *C, const StrokeExtension &stroke_extension) +void SnakeHookOperation::on_stroke_extended(const bContext &C, + const StrokeExtension &stroke_extension) { SnakeHookOperatorExecutor executor; executor.execute(*this, C, stroke_extension); -- cgit v1.2.3