Commit: c46d4d9fad5e16daa9f50e30e6373d20b8386bbb Author: Jacques Lucke Date: Tue Jul 5 14:56:04 2022 +0200 Branches: master https://developer.blender.org/rBc46d4d9fad5e16daa9f50e30e6373d20b8386bbb
Curves: move curves surface transforms to blenkernel This utility struct is useful outside of sculpting code as well. =================================================================== M source/blender/blenkernel/BKE_curves.hh M source/blender/blenkernel/intern/curves.cc 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_density.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_pinch.cc M source/blender/editors/sculpt_paint/curves_sculpt_puff.cc M source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc M source/blender/editors/sculpt_paint/curves_sculpt_slide.cc M source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc M source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc =================================================================== diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh index cc0c607f9bb..767936e2a26 100644 --- a/source/blender/blenkernel/BKE_curves.hh +++ b/source/blender/blenkernel/BKE_curves.hh @@ -836,4 +836,17 @@ inline float3 calculate_vector_handle(const float3 &point, const float3 &next_po } // namespace curves::bezier +struct CurvesSurfaceTransforms { + 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; + + CurvesSurfaceTransforms() = default; + CurvesSurfaceTransforms(const Object &curves_ob, const Object *surface_ob); +}; + } // namespace blender::bke diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc index 7ad83263b73..78791b55b4d 100644 --- a/source/blender/blenkernel/intern/curves.cc +++ b/source/blender/blenkernel/intern/curves.cc @@ -388,4 +388,18 @@ Curves *curves_new_nomain(CurvesGeometry curves) return curves_id; } +CurvesSurfaceTransforms::CurvesSurfaceTransforms(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::bke 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<Mesh *>(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<CurvesBrush3D> 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<eBrushFalloffShape>( 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<eBrushFalloffShape>( 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<const Mesh *>(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<CurvesBrush3D> sample_curves_surface_3d_brush( const Depsgraph &depsgraph, const ARegion ®ion, const View3D &v3d, - const CurvesSculptTransforms &transforms, + const CurvesSurfaceTransforms &transforms, const BVHTreeFromMesh &surface_bvh, @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs