From 6594e802ab94ff1124d9157deb0ca760981e3f34 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 28 Feb 2022 17:20:37 -0500 Subject: [PATCH] Curves: Add method to access cyclic attribute Avoids the need to use the attribute API to access this commonly used builtin attribute. --- source/blender/blenkernel/BKE_curves.hh | 3 +++ .../blenkernel/intern/curves_geometry.cc | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh index 209f892c651..6fa7de49eb0 100644 --- a/source/blender/blenkernel/BKE_curves.hh +++ b/source/blender/blenkernel/BKE_curves.hh @@ -119,6 +119,9 @@ class CurvesGeometry : public ::CurvesGeometry { Span offsets() const; MutableSpan offsets(); + VArray cyclic() const; + MutableSpan cyclic(); + /* -------------------------------------------------------------------- * Operations. */ diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 68797942b56..3eea579230a 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -18,6 +18,7 @@ namespace blender::bke { static const std::string ATTR_POSITION = "position"; static const std::string ATTR_RADIUS = "radius"; static const std::string ATTR_CURVE_TYPE = "curve_type"; +static const std::string ATTR_CYCLIC = "cyclic"; /* -------------------------------------------------------------------- */ /** \name Constructors/Destructor @@ -168,6 +169,23 @@ Span CurvesGeometry::offsets() const return {this->curve_offsets, this->curve_size + 1}; } +VArray CurvesGeometry::cyclic() const +{ + const bool *data = (const bool *)CustomData_get_layer_named( + &this->curve_data, CD_PROP_INT8, ATTR_CURVE_TYPE.c_str()); + if (data != nullptr) { + return VArray::ForSpan(Span(data, this->curve_size)); + } + return VArray::ForSingle(false, this->curve_size); +} + +MutableSpan CurvesGeometry::cyclic() +{ + bool *data = (bool *)CustomData_add_layer_named( + &this->curve_data, CD_PROP_BOOL, CD_CALLOC, nullptr, this->curve_size, ATTR_CYCLIC.c_str()); + return {data, this->curve_size}; +} + void CurvesGeometry::resize(const int point_size, const int curve_size) { if (point_size != this->point_size) {