Curves: Add method to access cyclic attribute

Avoids the need to use the attribute API to access this commonly
used builtin attribute.
This commit is contained in:
Hans Goudey 2022-02-28 17:20:37 -05:00
parent 4c407f20a6
commit 6594e802ab
Notes: blender-bot 2023-02-14 08:38:11 +01:00
Referenced by commit c238728105, Fix: Curves cyclic access function duplicates attribute
2 changed files with 21 additions and 0 deletions

View File

@ -119,6 +119,9 @@ class CurvesGeometry : public ::CurvesGeometry {
Span<int> offsets() const;
MutableSpan<int> offsets();
VArray<bool> cyclic() const;
MutableSpan<bool> cyclic();
/* --------------------------------------------------------------------
* Operations.
*/

View File

@ -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<int> CurvesGeometry::offsets() const
return {this->curve_offsets, this->curve_size + 1};
}
VArray<bool> 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<bool>::ForSpan(Span(data, this->curve_size));
}
return VArray<bool>::ForSingle(false, this->curve_size);
}
MutableSpan<bool> 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) {