Curves: move curves surface transforms to blenkernel
This utility struct is useful outside of sculpting code as well.
This commit is contained in:
parent
7f24d90f11
commit
c46d4d9fad
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
const float2 &brush_pos_re,
|
||||
const float brush_radius_re);
|
||||
|
|
|
@ -68,7 +68,7 @@ struct PinchOperationExecutor {
|
|||
Vector<int64_t> 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_);
|
||||
|
|
|
@ -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<Mesh *>(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_);
|
||||
|
|
|
@ -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<eBrushFalloffShape>(
|
||||
brush_->falloff_shape);
|
||||
|
|
|
@ -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<Mesh *>(surface_ob_->data);
|
||||
|
|
|
@ -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<eBrushFalloffShape>(
|
||||
brush_->falloff_shape);
|
||||
|
|
|
@ -89,7 +89,7 @@ struct SnakeHookOperatorExecutor {
|
|||
Vector<int64_t> 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_);
|
||||
|
|
Loading…
Reference in New Issue