From c46d4d9fad5e16daa9f50e30e6373d20b8386bbb Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 5 Jul 2022 14:56:04 +0200 Subject: Curves: move curves surface transforms to blenkernel This utility struct is useful outside of sculpting code as well. --- source/blender/editors/sculpt_paint/curves_sculpt_add.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_brush.cc | 16 +--------------- .../blender/editors/sculpt_paint/curves_sculpt_comb.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_delete.cc | 4 ++-- .../editors/sculpt_paint/curves_sculpt_density.cc | 10 +++++----- .../editors/sculpt_paint/curves_sculpt_grow_shrink.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_intern.hh | 16 ++-------------- .../blender/editors/sculpt_paint/curves_sculpt_pinch.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_puff.cc | 4 ++-- .../sculpt_paint/curves_sculpt_selection_paint.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_slide.cc | 4 ++-- .../blender/editors/sculpt_paint/curves_sculpt_smooth.cc | 4 ++-- .../editors/sculpt_paint/curves_sculpt_snake_hook.cc | 4 ++-- 13 files changed, 28 insertions(+), 54 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc index b7f496889c0..e5e6cfef8ae 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_add.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_add.cc @@ -97,7 +97,7 @@ struct AddOperationExecutor { float brush_radius_re_; float2 brush_pos_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; BVHTreeFromMesh surface_bvh_; @@ -123,7 +123,7 @@ struct AddOperationExecutor { return; } - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); surface_ob_ = curves_id_->surface; surface_ = static_cast(surface_ob_->data); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc index 7d17db515fb..10564942ab9 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_brush.cc @@ -258,7 +258,7 @@ std::optional sample_curves_surface_3d_brush( const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, - const CurvesSculptTransforms &transforms, + const CurvesSurfaceTransforms &transforms, const BVHTreeFromMesh &surface_bvh, const float2 &brush_pos_re, const float brush_radius_re) @@ -380,18 +380,4 @@ CurvesSculptCommonContext::CurvesSculptCommonContext(const bContext &C) this->rv3d = CTX_wm_region_view3d(&C); } -CurvesSculptTransforms::CurvesSculptTransforms(const Object &curves_ob, const Object *surface_ob) -{ - this->curves_to_world = curves_ob.obmat; - this->world_to_curves = this->curves_to_world.inverted(); - - if (surface_ob != nullptr) { - this->surface_to_world = surface_ob->obmat; - this->world_to_surface = this->surface_to_world.inverted(); - this->surface_to_curves = this->world_to_curves * this->surface_to_world; - this->curves_to_surface = this->world_to_surface * this->curves_to_world; - this->surface_to_curves_normal = this->surface_to_curves.inverted().transposed(); - } -} - } // 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 541bf9d8253..449f1786167 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_comb.cc @@ -100,7 +100,7 @@ struct CombOperationExecutor { float2 brush_pos_re_; float2 brush_pos_diff_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; CombOperationExecutor(const bContext &C) : ctx_(C) { @@ -128,7 +128,7 @@ struct CombOperationExecutor { return; } - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); point_factors_ = get_point_selection(*curves_id_); curve_selection_ = retrieve_selected_curves(*curves_id_, selected_curve_indices_); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc index eab7dabcd22..777ebd16110 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_delete.cc @@ -76,7 +76,7 @@ struct DeleteOperationExecutor { float2 brush_pos_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; DeleteOperationExecutor(const bContext &C) : ctx_(C) { @@ -100,7 +100,7 @@ struct DeleteOperationExecutor { brush_pos_re_ = stroke_extension.mouse_position; - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); const eBrushFalloffShape falloff_shape = static_cast( brush_->falloff_shape); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc index be936b4cbda..826b0611e81 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_density.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_density.cc @@ -74,7 +74,7 @@ struct DensityAddOperationExecutor { float brush_radius_re_; float2 brush_pos_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; BVHTreeFromMesh surface_bvh_; @@ -105,7 +105,7 @@ struct DensityAddOperationExecutor { surface_looptris_ = {BKE_mesh_runtime_looptri_ensure(surface_), BKE_mesh_runtime_looptri_len(surface_)}; - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); if (!CustomData_has_layer(&surface_->ldata, CD_NORMAL)) { BKE_mesh_calc_normals_split(surface_); @@ -449,7 +449,7 @@ struct DensitySubtractOperationExecutor { float minimum_distance_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; BVHTreeFromMesh surface_bvh_; KDTree_3d *root_points_kdtree_; @@ -489,7 +489,7 @@ struct DensitySubtractOperationExecutor { curve_selection_ = retrieve_selected_curves(*curves_id_, selected_curve_indices_); - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); const eBrushFalloffShape falloff_shape = static_cast( brush_->falloff_shape); BKE_bvhtree_from_mesh_get(&surface_bvh_, surface_, BVHTREE_FROM_LOOPTRI, 2); @@ -743,7 +743,7 @@ static bool use_add_density_mode(const BrushStrokeMode brush_mode, return true; } - const CurvesSculptTransforms transforms(curves_ob, curves_id.surface); + const CurvesSurfaceTransforms transforms(curves_ob, curves_id.surface); BVHTreeFromMesh surface_bvh; BKE_bvhtree_from_mesh_get( &surface_bvh, static_cast(curves_id.surface->data), BVHTREE_FROM_LOOPTRI, 2); 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 cf893f09fc6..709ecc79967 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc @@ -247,7 +247,7 @@ struct CurvesEffectOperationExecutor { eBrushFalloffShape falloff_shape_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; float2 brush_pos_start_re_; float2 brush_pos_end_re_; @@ -289,7 +289,7 @@ struct CurvesEffectOperationExecutor { falloff_shape_ = eBrushFalloffShape(brush_->falloff_shape); - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); brush_pos_start_re_ = self.last_mouse_position_; brush_pos_end_re_ = stroke_extension.mouse_position; diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh index 4cfaf7ebfc9..c31bba2fe1e 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/curves_sculpt_intern.hh @@ -26,6 +26,7 @@ struct BVHTreeFromMesh; namespace blender::ed::sculpt_paint { using bke::CurvesGeometry; +using bke::CurvesSurfaceTransforms; struct StrokeExtension { bool is_first; @@ -116,24 +117,11 @@ class CurvesSculptCommonContext { CurvesSculptCommonContext(const bContext &C); }; -struct CurvesSculptTransforms { - float4x4 curves_to_world; - float4x4 curves_to_surface; - float4x4 world_to_curves; - float4x4 world_to_surface; - float4x4 surface_to_world; - float4x4 surface_to_curves; - float4x4 surface_to_curves_normal; - - CurvesSculptTransforms() = default; - CurvesSculptTransforms(const Object &curves_ob, const Object *surface_ob); -}; - std::optional sample_curves_surface_3d_brush( const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, - const CurvesSculptTransforms &transforms, + const CurvesSurfaceTransforms &transforms, const BVHTreeFromMesh &surface_bvh, const float2 &brush_pos_re, const float brush_radius_re); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc b/source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc index 5b7359a3905..689b7d22e5e 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc @@ -68,7 +68,7 @@ struct PinchOperationExecutor { Vector selected_curve_indices_; IndexMask curve_selection_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; const CurvesSculpt *curves_sculpt_ = nullptr; const Brush *brush_ = nullptr; @@ -103,7 +103,7 @@ struct PinchOperationExecutor { invert_factor_ = self_->invert_pinch_ ? -1.0f : 1.0f; - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); point_factors_ = get_point_selection(*curves_id_); curve_selection_ = retrieve_selected_curves(*curves_id_, selected_curve_indices_); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc index dc747fd0bce..83cfda6dc00 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_puff.cc @@ -80,7 +80,7 @@ struct PuffOperationExecutor { eBrushFalloffShape falloff_shape_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; Object *surface_ob_ = nullptr; Mesh *surface_ = nullptr; @@ -122,7 +122,7 @@ struct PuffOperationExecutor { surface_ob_ = curves_id_->surface; surface_ = static_cast(surface_ob_->data); - transforms_ = CurvesSculptTransforms(*object_, surface_ob_); + transforms_ = CurvesSurfaceTransforms(*object_, surface_ob_); if (!CustomData_has_layer(&surface_->ldata, CD_NORMAL)) { BKE_mesh_calc_normals_split(surface_); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc b/source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc index 353b84236a3..399d2c73ec3 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc @@ -66,7 +66,7 @@ struct SelectionPaintOperationExecutor { float2 brush_pos_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; SelectionPaintOperationExecutor(const bContext &C) : ctx_(C) { @@ -104,7 +104,7 @@ struct SelectionPaintOperationExecutor { } } - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); const eBrushFalloffShape falloff_shape = static_cast( brush_->falloff_shape); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc index 2739b5869d5..dedc880988d 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_slide.cc @@ -98,7 +98,7 @@ struct SlideOperationExecutor { float2 brush_pos_re_; float2 brush_pos_diff_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; BVHTreeFromMesh surface_bvh_; @@ -136,7 +136,7 @@ struct SlideOperationExecutor { brush_pos_diff_re_ = brush_pos_re_ - brush_pos_prev_re_; BLI_SCOPED_DEFER([&]() { self_->brush_pos_last_re_ = brush_pos_re_; }); - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); surface_ob_ = curves_id_->surface; surface_ = static_cast(surface_ob_->data); diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc b/source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc index e72b17d448b..f874a9fc255 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc @@ -52,7 +52,7 @@ struct SmoothOperationExecutor { float brush_strength_; float2 brush_pos_re_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; SmoothOperationExecutor(const bContext &C) : ctx_(C) { @@ -79,7 +79,7 @@ struct SmoothOperationExecutor { point_factors_ = get_point_selection(*curves_id_); curve_selection_ = retrieve_selected_curves(*curves_id_, selected_curve_indices_); - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); const eBrushFalloffShape falloff_shape = static_cast( brush_->falloff_shape); 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 b63e5a7756b..ec0e8ff45e5 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc @@ -89,7 +89,7 @@ struct SnakeHookOperatorExecutor { Vector selected_curve_indices_; IndexMask curve_selection_; - CurvesSculptTransforms transforms_; + CurvesSurfaceTransforms transforms_; float2 brush_pos_prev_re_; float2 brush_pos_re_; @@ -123,7 +123,7 @@ struct SnakeHookOperatorExecutor { return; } - transforms_ = CurvesSculptTransforms(*object_, curves_id_->surface); + transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface); curve_factors_ = get_curves_selection(*curves_id_); curve_selection_ = retrieve_selected_curves(*curves_id_, selected_curve_indices_); -- cgit v1.2.3