Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-06-22 19:32:50 +0300
committerHans Goudey <h.goudey@me.com>2021-06-22 19:32:50 +0300
commitf3eecfe386098cf0a18df7ff4d8ffda9a43e9495 (patch)
tree52a9429269c803ae3a4f0bb8a6c235850c12f124 /source/blender/blenkernel/intern
parent026de343e3528fe2b2f8d8daba7fa2fd4b807337 (diff)
Cleanup: Refactor spline copying functions
Make the virtual functions protected and simpler, so that the logic is better contained in the base class's implementation. Also introduce a `copy_without_attributes` method to be used for realizing instances.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/spline_base.cc54
-rw-r--r--source/blender/blenkernel/intern/spline_bezier.cc19
-rw-r--r--source/blender/blenkernel/intern/spline_nurbs.cc22
-rw-r--r--source/blender/blenkernel/intern/spline_poly.cc13
4 files changed, 86 insertions, 22 deletions
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc
index c18f44e07b2..aa0d95d4d61 100644
--- a/source/blender/blenkernel/intern/spline_base.cc
+++ b/source/blender/blenkernel/intern/spline_base.cc
@@ -40,6 +40,60 @@ Spline::Type Spline::type() const
return type_;
}
+void Spline::copy_base_settings(const Spline &src, Spline &dst)
+{
+ dst.normal_mode = src.normal_mode;
+ dst.is_cyclic_ = src.is_cyclic_;
+}
+
+static SplinePtr create_spline(const Spline::Type type)
+{
+ switch (type) {
+ case Spline::Type::Poly:
+ return std::make_unique<PolySpline>();
+ case Spline::Type::Bezier:
+ return std::make_unique<BezierSpline>();
+ case Spline::Type::NURBS:
+ return std::make_unique<NURBSpline>();
+ }
+ BLI_assert_unreachable();
+ return {};
+}
+
+/**
+ * Return a new spline with the same data, settings, and attributes.
+ */
+SplinePtr Spline::copy() const
+{
+ SplinePtr dst = this->copy_without_attributes();
+ dst->attributes = this->attributes;
+ return dst;
+}
+
+/**
+ * Return a new spline with the same type and settings like "cyclic", but without any data.
+ */
+SplinePtr Spline::copy_only_settings() const
+{
+ SplinePtr dst = create_spline(type_);
+ this->copy_base_settings(*this, *dst);
+ this->copy_settings(*dst);
+ return dst;
+}
+
+/**
+ * The same as #copy, but skips copying dynamic attributes to the new spline.
+ */
+SplinePtr Spline::copy_without_attributes() const
+{
+ SplinePtr dst = this->copy_only_settings();
+ this->copy_data(*dst);
+
+ /* Though the attributes storage is empty, it still needs to know the correct size. */
+ dst->attributes.reallocate(dst->size());
+ return dst;
+}
+
void Spline::translate(const blender::float3 &translation)
{
for (float3 &position : this->positions()) {
diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc
index daae03167ef..02d26ac715b 100644
--- a/source/blender/blenkernel/intern/spline_bezier.cc
+++ b/source/blender/blenkernel/intern/spline_bezier.cc
@@ -29,17 +29,22 @@ using blender::fn::GVArray;
using blender::fn::GVArray_For_ArrayContainer;
using blender::fn::GVArrayPtr;
-SplinePtr BezierSpline::copy() const
+void BezierSpline::copy_settings(Spline &dst) const
{
- return std::make_unique<BezierSpline>(*this);
+ BezierSpline &bezier = static_cast<BezierSpline &>(dst);
+ bezier.resolution_ = resolution_;
}
-SplinePtr BezierSpline::copy_settings() const
+void BezierSpline::copy_data(Spline &dst) const
{
- std::unique_ptr<BezierSpline> copy = std::make_unique<BezierSpline>();
- copy_base_settings(*this, *copy);
- copy->resolution_ = resolution_;
- return copy;
+ BezierSpline &bezier = static_cast<BezierSpline &>(dst);
+ bezier.positions_ = positions_;
+ bezier.handle_types_left_ = handle_types_left_;
+ bezier.handle_positions_left_ = handle_positions_left_;
+ bezier.handle_types_right_ = handle_types_right_;
+ bezier.handle_positions_right_ = handle_positions_right_;
+ bezier.radii_ = radii_;
+ bezier.tilts_ = tilts_;
}
int BezierSpline::size() const
diff --git a/source/blender/blenkernel/intern/spline_nurbs.cc b/source/blender/blenkernel/intern/spline_nurbs.cc
index 31ac23589be..85fb9730e83 100644
--- a/source/blender/blenkernel/intern/spline_nurbs.cc
+++ b/source/blender/blenkernel/intern/spline_nurbs.cc
@@ -31,19 +31,23 @@ using blender::fn::GVArray_For_ArrayContainer;
using blender::fn::GVArray_Typed;
using blender::fn::GVArrayPtr;
-SplinePtr NURBSpline::copy() const
+void NURBSpline::copy_settings(Spline &dst) const
{
- return std::make_unique<NURBSpline>(*this);
+ NURBSpline &nurbs = static_cast<NURBSpline &>(dst);
+ nurbs.knots_mode = knots_mode;
+ nurbs.resolution_ = resolution_;
+ nurbs.order_ = order_;
}
-SplinePtr NURBSpline::copy_settings() const
+void NURBSpline::copy_data(Spline &dst) const
{
- std::unique_ptr<NURBSpline> copy = std::make_unique<NURBSpline>();
- copy_base_settings(*this, *copy);
- copy->knots_mode = knots_mode;
- copy->resolution_ = resolution_;
- copy->order_ = order_;
- return copy;
+ NURBSpline &nurbs = static_cast<NURBSpline &>(dst);
+ nurbs.positions_ = positions_;
+ nurbs.weights_ = weights_;
+ nurbs.knots_ = knots_;
+ nurbs.knots_dirty_ = false;
+ nurbs.radii_ = radii_;
+ nurbs.tilts_ = tilts_;
}
int NURBSpline::size() const
diff --git a/source/blender/blenkernel/intern/spline_poly.cc b/source/blender/blenkernel/intern/spline_poly.cc
index e344b8d4910..dfd24b2566e 100644
--- a/source/blender/blenkernel/intern/spline_poly.cc
+++ b/source/blender/blenkernel/intern/spline_poly.cc
@@ -25,16 +25,17 @@ using blender::Span;
using blender::fn::GVArray;
using blender::fn::GVArrayPtr;
-SplinePtr PolySpline::copy() const
+void PolySpline::copy_settings(Spline &UNUSED(dst)) const
{
- return std::make_unique<PolySpline>(*this);
+ /* Poly splines have no settings not covered by the base class. */
}
-SplinePtr PolySpline::copy_settings() const
+void PolySpline::copy_data(Spline &dst) const
{
- std::unique_ptr<PolySpline> copy = std::make_unique<PolySpline>();
- copy_base_settings(*this, *copy);
- return copy;
+ PolySpline &poly = static_cast<PolySpline &>(dst);
+ poly.positions_ = positions_;
+ poly.radii_ = radii_;
+ poly.tilts_ = tilts_;
}
int PolySpline::size() const