Blender V4.5
blender::nodes::AttributeAccessor Class Reference

#include <BKE_attribute.hh>

Inherited by blender::bke::MutableAttributeAccessor.

Public Member Functions

 AttributeAccessor (const void *owner, const AttributeAccessorFunctions &fn)
bool domain_supported (const AttrDomain domain) const
int domain_size (const AttrDomain domain) const
bool is_builtin (const StringRef attribute_id) const
std::optional< AttributeDomainAndTypeget_builtin_domain_and_type (const StringRef name) const
GPointer get_builtin_default (const StringRef attribute_id) const
GAttributeReader lookup (const StringRef attribute_id) const
GAttributeReader lookup (const StringRef attribute_id, const AttrDomain domain) const
GAttributeReader lookup (const StringRef attribute_id, const eCustomDataType data_type) const
template<typename T>
AttributeReader< Tlookup (const StringRef attribute_id, const std::optional< AttrDomain > domain=std::nullopt) const
template<typename T>
AttributeReader< Tlookup_or_default (const StringRef attribute_id, const AttrDomain domain, const T &default_value) const
AttributeValidator lookup_validator (const StringRef attribute_id) const
GVArray adapt_domain (const GVArray &varray, const AttrDomain from_domain, const AttrDomain to_domain) const
template<typename T>
VArray< Tadapt_domain (const VArray< T > &varray, const AttrDomain from_domain, const AttrDomain to_domain) const
void foreach_attribute (const FunctionRef< void(const AttributeIter &)> fn) const

Protected Attributes

void * owner_
const AttributeAccessorFunctions * fn_

Attribute API

bool contains (StringRef attribute_id) const
std::optional< AttributeMetaDatalookup_meta_data (StringRef attribute_id) const
GAttributeReader lookup (StringRef attribute_id, std::optional< AttrDomain > domain, std::optional< eCustomDataType > data_type) const
GAttributeReader lookup_or_default (StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const void *default_value=nullptr) const
Set< StringRefNullall_ids () const
static std::optional< AttributeAccessorfrom_id (const ID &id)

Detailed Description

Provides read-only access to the set of attributes on some geometry.

Note, this does not own the attributes. When the owner is freed, it is invalid to access its attributes.

Definition at line 525 of file BKE_attribute.hh.

Constructor & Destructor Documentation

◆ AttributeAccessor()

blender::bke::AttributeAccessor::AttributeAccessor ( const void * owner,
const AttributeAccessorFunctions & fn )
inline

Definition at line 544 of file BKE_attribute.hh.

Member Function Documentation

◆ adapt_domain() [1/2]

GVArray blender::bke::AttributeAccessor::adapt_domain ( const GVArray & varray,
const AttrDomain from_domain,
const AttrDomain to_domain ) const
inline

Interpolate data from one domain to another.

Definition at line 691 of file BKE_attribute.hh.

◆ adapt_domain() [2/2]

template<typename T>
VArray< T > blender::bke::AttributeAccessor::adapt_domain ( const VArray< T > & varray,
const AttrDomain from_domain,
const AttrDomain to_domain ) const
inline

Interpolate data from one domain to another.

Definition at line 702 of file BKE_attribute.hh.

◆ all_ids()

Get a set of all attributes.

Definition at line 777 of file attribute_access.cc.

◆ contains()

Returns
True, when the attribute is available.

Definition at line 752 of file attribute_access.cc.

◆ domain_size()

int blender::bke::AttributeAccessor::domain_size ( const AttrDomain domain) const
inline
Returns
Number of elements in the given domain.

Definition at line 575 of file BKE_attribute.hh.

◆ domain_supported()

Returns
True, when attributes can exist on that domain.

Definition at line 567 of file BKE_attribute.hh.

◆ foreach_attribute()

void blender::bke::AttributeAccessor::foreach_attribute ( const FunctionRef< void(const AttributeIter &)> fn) const
inline

Run the provided function for every attribute. Attributes should not be removed or added during iteration.

Definition at line 713 of file BKE_attribute.hh.

◆ from_id()

std::optional< AttributeAccessor > blender::bke::AttributeAccessor::from_id ( const ID & id)
static

Construct an AttributeAccessor from an ID.

Definition at line 673 of file attribute_access.cc.

◆ get_builtin_default()

Returns
The default value defined by the #BuiltinAttributeProvider. The provided attribute_id must refer to a builtin attribute.

Definition at line 601 of file BKE_attribute.hh.

◆ get_builtin_domain_and_type()

Returns
The required domain and type for the attribute, if it is builtin.

Definition at line 592 of file BKE_attribute.hh.

◆ is_builtin()

bool blender::bke::AttributeAccessor::is_builtin ( const StringRef attribute_id) const
inline
Returns
True, when the attribute has a special meaning for Blender and can't be used for arbitrary things.

Definition at line 584 of file BKE_attribute.hh.

◆ lookup() [1/5]

Get read-only access to the attribute. If the attribute does not exist, the return value is empty.

Definition at line 611 of file BKE_attribute.hh.

◆ lookup() [2/5]

GAttributeReader blender::bke::AttributeAccessor::lookup ( const StringRef attribute_id,
const AttrDomain domain ) const
inline

Get read-only access to the attribute whereby the attribute is interpolated to the given domain. The result may be empty.

Definition at line 628 of file BKE_attribute.hh.

◆ lookup() [3/5]

GAttributeReader blender::bke::AttributeAccessor::lookup ( const StringRef attribute_id,
const eCustomDataType data_type ) const
inline

Get read-only access to the attribute whereby the attribute is converted to the given type. The result may be empty.

Definition at line 637 of file BKE_attribute.hh.

◆ lookup() [4/5]

template<typename T>
AttributeReader< T > blender::bke::AttributeAccessor::lookup ( const StringRef attribute_id,
const std::optional< AttrDomain > domain = std::nullopt ) const
inline

Get read-only access to the attribute. If necessary, the attribute is interpolated to the given domain and then converted to the given type, in that order. The result may be empty.

Definition at line 647 of file BKE_attribute.hh.

◆ lookup() [5/5]

GAttributeReader blender::bke::AttributeAccessor::lookup ( StringRef attribute_id,
std::optional< AttrDomain > domain,
std::optional< eCustomDataType > data_type ) const

Get read-only access to the attribute. If necessary, the attribute is interpolated to the given domain, and converted to the given type, in that order. The result may be empty.

Definition at line 722 of file attribute_access.cc.

◆ lookup_meta_data()

Returns
Information about the attribute if it exists.

Definition at line 764 of file attribute_access.cc.

◆ lookup_or_default() [1/2]

template<typename T>
AttributeReader< T > blender::bke::AttributeAccessor::lookup_or_default ( const StringRef attribute_id,
const AttrDomain domain,
const T & default_value ) const
inline

Same as the generic version above, but should be used when the type is known at compile time.

Definition at line 670 of file BKE_attribute.hh.

◆ lookup_or_default() [2/2]

GAttributeReader blender::bke::AttributeAccessor::lookup_or_default ( StringRef attribute_id,
AttrDomain domain,
eCustomDataType data_type,
const void * default_value = nullptr ) const

Get read-only access to the attribute. If necessary, the attribute is interpolated to the given domain and then converted to the given data type, in that order. If the attribute does not exist, a virtual array with the given default value is returned. If the passed in default value is null, the default value of the type is used (generally 0).

Definition at line 735 of file attribute_access.cc.

◆ lookup_validator()

AttributeValidator blender::bke::AttributeAccessor::lookup_validator ( const StringRef attribute_id) const
inline

Same as the generic version above, but should be used when the type is known at compile time.

Definition at line 683 of file BKE_attribute.hh.

Member Data Documentation

◆ fn_

const AttributeAccessorFunctions* blender::bke::AttributeAccessor::fn_
protected

Functions that know how to access the attributes stored in the owner above.

Definition at line 541 of file BKE_attribute.hh.

◆ owner_

The data that actually owns the attributes, for example, a pointer to a Mesh or PointCloud Most commonly this is a pointer to a Mesh or PointCloud. Under some circumstances this can be null. In that case most methods can't be used. Allowed methods are domain_size, foreach_attribute and is_builtin. We could potentially make these methods accessible without AttributeAccessor and then owner_ could always be non-null.

Note
This class cannot modify the owner's attributes, but the pointer is still non-const, so this class can be a base class for the mutable version.

Definition at line 537 of file BKE_attribute.hh.


The documentation for this class was generated from the following files: