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
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')
-rw-r--r--source/blender/blenkernel/BKE_spline.hh9
-rw-r--r--source/blender/blenkernel/intern/curve_eval.cc42
-rw-r--r--source/blender/blenkernel/intern/geometry_component_curve.cc49
-rw-r--r--source/blender/blenkernel/intern/geometry_set_instances.cc4
4 files changed, 67 insertions, 37 deletions
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 35bbc23b21a..f1ffeb664f5 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -478,8 +478,15 @@ class PolySpline final : public Spline {
* more of the data is stored in the splines, but also just to be different than the name in DNA.
*/
class CurveEval {
+ private:
+ blender::Vector<SplinePtr> splines_;
+
public:
- blender::Vector<SplinePtr> splines;
+ blender::Span<SplinePtr> splines() const;
+ blender::MutableSpan<SplinePtr> splines();
+
+ void add_spline(SplinePtr spline);
+ void remove_splines(blender::IndexMask mask);
CurveEval *copy();
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;
}
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 216f0930cf9..97a8129278e 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -125,13 +125,13 @@ int CurveComponent::attribute_domain_size(const AttributeDomain domain) const
}
if (domain == ATTR_DOMAIN_POINT) {
int total = 0;
- for (const SplinePtr &spline : curve_->splines) {
+ for (const SplinePtr &spline : curve_->splines()) {
total += spline->size();
}
return total;
}
if (domain == ATTR_DOMAIN_CURVE) {
- return curve_->splines.size();
+ return curve_->splines().size();
}
return 0;
}
@@ -245,7 +245,7 @@ static void set_spline_resolution(SplinePtr &spline, const int resolution)
static GVArrayPtr make_resolution_read_attribute(const CurveEval &curve)
{
return std::make_unique<fn::GVArray_For_DerivedSpan<SplinePtr, int, get_spline_resolution>>(
- curve.splines.as_span());
+ curve.splines());
}
static GVMutableArrayPtr make_resolution_write_attribute(CurveEval &curve)
@@ -254,7 +254,7 @@ static GVMutableArrayPtr make_resolution_write_attribute(CurveEval &curve)
int,
get_spline_resolution,
set_spline_resolution>>(
- curve.splines.as_mutable_span());
+ curve.splines());
}
static bool get_cyclic_value(const SplinePtr &spline)
@@ -273,14 +273,14 @@ static void set_cyclic_value(SplinePtr &spline, const bool value)
static GVArrayPtr make_cyclic_read_attribute(const CurveEval &curve)
{
return std::make_unique<fn::GVArray_For_DerivedSpan<SplinePtr, bool, get_cyclic_value>>(
- curve.splines.as_span());
+ curve.splines());
}
static GVMutableArrayPtr make_cyclic_write_attribute(CurveEval &curve)
{
return std::make_unique<
fn::GVMutableArray_For_DerivedSpan<SplinePtr, bool, get_cyclic_value, set_cyclic_value>>(
- curve.splines.as_mutable_span());
+ curve.splines());
}
/** \} */
@@ -296,12 +296,13 @@ static GVMutableArrayPtr make_cyclic_write_attribute(CurveEval &curve)
static Array<int> control_point_offsets(const CurveEval &curve)
{
- Array<int> offsets(curve.splines.size() + 1);
+ Span<SplinePtr> splines = curve.splines();
+ Array<int> offsets(splines.size() + 1);
int size = 0;
- for (const int spline_index : curve.splines.index_range()) {
+ for (const int spline_index : splines.index_range()) {
offsets[spline_index] = size;
- size += curve.splines[spline_index]->size();
+ size += splines[spline_index]->size();
}
offsets.last() = size;
@@ -584,14 +585,15 @@ template<typename T> class BuiltinPointAttributeProvider : public BuiltinAttribu
return {};
}
- if (curve->splines.size() == 1) {
- return std::make_unique<fn::GVArray_For_GSpan>(get_span_(*curve->splines.first()));
+ Span<SplinePtr> splines = curve->splines();
+ if (splines.size() == 1) {
+ return std::make_unique<fn::GVArray_For_GSpan>(get_span_(*splines.first()));
}
Array<int> offsets = control_point_offsets(*curve);
- Array<Span<T>> spans(curve->splines.size());
- for (const int i : curve->splines.index_range()) {
- spans[i] = get_span_(*curve->splines[i]);
+ Array<Span<T>> spans(splines.size());
+ for (const int i : splines.index_range()) {
+ spans[i] = get_span_(*splines[i]);
}
return std::make_unique<fn::GVArray_For_EmbeddedVArray<T, VArray_For_SplinePoints<T>>>(
@@ -605,17 +607,18 @@ template<typename T> class BuiltinPointAttributeProvider : public BuiltinAttribu
return {};
}
- if (curve->splines.size() == 1) {
+ MutableSpan<SplinePtr> splines = curve->splines();
+ if (splines.size() == 1) {
return std::make_unique<fn::GVMutableArray_For_GMutableSpan>(
- get_mutable_span_(*curve->splines.first()));
+ get_mutable_span_(*splines.first()));
}
Array<int> offsets = control_point_offsets(*curve);
- Array<MutableSpan<T>> spans(curve->splines.size());
- for (const int i : curve->splines.index_range()) {
- spans[i] = get_mutable_span_(*curve->splines[i]);
+ Array<MutableSpan<T>> spans(splines.size());
+ for (const int i : splines.index_range()) {
+ spans[i] = get_mutable_span_(*splines[i]);
if (update_on_write_) {
- update_on_write_(*curve->splines[i]);
+ update_on_write_(*splines[i]);
}
}
@@ -668,7 +671,7 @@ class PositionAttributeProvider final : public BuiltinPointAttributeProvider<flo
/* Changing the positions requires recalculation of cached evaluated data in many cases.
* This could set more specific flags in the future to avoid unnecessary recomputation. */
bool curve_has_bezier_spline = false;
- for (SplinePtr &spline : curve->splines) {
+ for (SplinePtr &spline : curve->splines()) {
if (spline->type() == Spline::Type::Bezier) {
curve_has_bezier_spline = true;
break;
@@ -681,14 +684,14 @@ class PositionAttributeProvider final : public BuiltinPointAttributeProvider<flo
return BuiltinPointAttributeProvider<float3>::try_get_for_write(component);
}
- for (SplinePtr &spline : curve->splines) {
+ for (SplinePtr &spline : curve->splines()) {
spline->mark_cache_invalid();
}
Array<int> offsets = control_point_offsets(*curve);
return std::make_unique<
fn::GVMutableArray_For_EmbeddedVMutableArray<float3, VMutableArray_For_SplinePosition>>(
- offsets.last(), curve->splines, std::move(offsets));
+ offsets.last(), curve->splines(), std::move(offsets));
}
};
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index a792e268d5c..b6ee0337dbf 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -528,11 +528,11 @@ static void join_curve_splines(Span<GeometryInstanceGroup> set_groups, CurveComp
}
const CurveEval &source_curve = *set.get_curve_for_read();
- for (const SplinePtr &source_spline : source_curve.splines) {
+ for (const SplinePtr &source_spline : source_curve.splines()) {
for (const float4x4 &transform : set_group.transforms) {
SplinePtr new_spline = source_spline->copy();
new_spline->transform(transform);
- new_curve->splines.append(std::move(new_spline));
+ new_curve->add_spline(std::move(new_spline));
}
}
}