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-05-12 19:46:13 +0300
committerHans Goudey <h.goudey@me.com>2021-05-12 19:46:13 +0300
commit50bf033d3f31b9939a79dea0652731f94da9a3ed (patch)
tree055a9ae0ca4bc1560b74b9ed58cd15fd87e5033f /source/blender/blenkernel/intern/curve_eval.cc
parent3ef01692c8f068ccc083dd3d6a49ed055fe7224b (diff)
Cleanup: Splines: Add accessors to spline vector
Not allowing external direct access to the vector of splines in the curve will help for things like reallocating custom data when a spline is added or removed.
Diffstat (limited to 'source/blender/blenkernel/intern/curve_eval.cc')
-rw-r--r--source/blender/blenkernel/intern/curve_eval.cc42
1 files changed, 31 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 4c63c7f05ee..882fdbc0ec6 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -27,12 +27,34 @@ using blender::float3;
using blender::float4x4;
using blender::Span;
+blender::Span<SplinePtr> CurveEval::splines() const
+{
+ return splines_;
+}
+
+blender::MutableSpan<SplinePtr> CurveEval::splines()
+{
+ return splines_;
+}
+
+void CurveEval::add_spline(SplinePtr spline)
+{
+ splines_.append(std::move(spline));
+}
+
+void CurveEval::remove_splines(blender::IndexMask mask)
+{
+ for (int i = mask.size() - 1; i >= 0; i--) {
+ splines_.remove_and_reorder(mask.indices()[i]);
+ }
+}
+
CurveEval *CurveEval::copy()
{
CurveEval *new_curve = new CurveEval();
- for (SplinePtr &spline : this->splines) {
- new_curve->splines.append(spline->copy());
+ for (SplinePtr &spline : this->splines()) {
+ new_curve->add_spline(spline->copy());
}
return new_curve;
@@ -40,7 +62,7 @@ CurveEval *CurveEval::copy()
void CurveEval::translate(const float3 &translation)
{
- for (SplinePtr &spline : this->splines) {
+ for (SplinePtr &spline : this->splines()) {
spline->translate(translation);
spline->mark_cache_invalid();
}
@@ -48,14 +70,14 @@ void CurveEval::translate(const float3 &translation)
void CurveEval::transform(const float4x4 &matrix)
{
- for (SplinePtr &spline : this->splines) {
+ for (SplinePtr &spline : this->splines()) {
spline->transform(matrix);
}
}
void CurveEval::bounds_min_max(float3 &min, float3 &max, const bool use_evaluated) const
{
- for (const SplinePtr &spline : this->splines) {
+ for (const SplinePtr &spline : this->splines()) {
spline->bounds_min_max(min, max, use_evaluated);
}
}
@@ -115,8 +137,6 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
const ListBase *nurbs = BKE_curve_nurbs_get(&const_cast<Curve &>(dna_curve));
- curve->splines.reserve(BLI_listbase_count(nurbs));
-
/* TODO: Optimize by reserving the correct points size. */
LISTBASE_FOREACH (const Nurb *, nurb, nurbs) {
switch (nurb->type) {
@@ -135,7 +155,7 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
bezt.tilt);
}
- curve->splines.append(std::move(spline));
+ curve->add_spline(std::move(spline));
break;
}
case CU_NURBS: {
@@ -149,7 +169,7 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
spline->add_point(bp.vec, bp.radius, bp.tilt, bp.vec[3]);
}
- curve->splines.append(std::move(spline));
+ curve->add_spline(std::move(spline));
break;
}
case CU_POLY: {
@@ -160,7 +180,7 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
spline->add_point(bp.vec, bp.radius, bp.tilt);
}
- curve->splines.append(std::move(spline));
+ curve->add_spline(std::move(spline));
break;
}
default: {
@@ -174,7 +194,7 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
* from multiple curve objects, where the value may be different. */
const Spline::NormalCalculationMode normal_mode = normal_mode_from_dna_curve(
dna_curve.twist_mode);
- for (SplinePtr &spline : curve->splines) {
+ for (SplinePtr &spline : curve->splines()) {
spline->normal_mode = normal_mode;
}