Blender V5.3
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 contains (StringRef name) const
std::optional< AttributeMetaData > lookup_meta_data (StringRef name) const
bool domain_supported (const AttrDomain domain) const
int domain_size (const AttrDomain domain) const
bool is_builtin (const StringRef name) const
std::optional< AttributeDomainAndType > get_builtin_domain_and_type (const StringRef name) const
GPointer get_builtin_default (const StringRef name) const
GAttributeReader lookup (const StringRef name) const
GAttributeReader lookup (const StringRef name, const AttrDomain domain) const
GAttributeReader lookup (const StringRef name, const AttrType data_type) const
template<typename T>
AttributeReader< T > lookup (const StringRef name, const std::optional< AttrDomain > domain=std::nullopt) const
template<typename T>
AttributeReader< T > lookup_or_default (const StringRef name, const AttrDomain domain, const T &default_value) const
AttributeValidator lookup_validator (const StringRef name) const
GVArray adapt_domain (const GVArray &varray, const AttrDomain from_domain, const AttrDomain to_domain) const
template<typename T>
VArray< T > adapt_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

GAttributeReader lookup (StringRef name, std::optional< AttrDomain > domain, std::optional< AttrType > data_type) const
GAttributeReader lookup_or_default (StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
Set< StringRefNull > all_names () const
bool has_anonymous () const
static std::optional< AttributeAccessor > from_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 493 of file BKE_attribute.hh.

Constructor & Destructor Documentation

◆ AttributeAccessor()

Definition at line 512 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 665 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 676 of file BKE_attribute.hh.

◆ all_names()

Get a set of all attributes.

Definition at line 432 of file attribute_access.cc.

◆ contains()

Returns
True, when the attribute is available.

Definition at line 525 of file BKE_attribute.hh.

◆ domain_size()

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

Definition at line 549 of file BKE_attribute.hh.

◆ domain_supported()

Returns
True, when attributes can exist on that domain.

Definition at line 541 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 687 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 353 of file attribute_access.cc.

◆ get_builtin_default()

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

Definition at line 575 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 566 of file BKE_attribute.hh.

◆ has_anonymous()

True if there are any anonymous attributes.

Definition at line 440 of file attribute_access.cc.

◆ is_builtin()

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

Definition at line 558 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 585 of file BKE_attribute.hh.

◆ lookup() [2/5]

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

Definition at line 602 of file BKE_attribute.hh.

◆ lookup() [3/5]

GAttributeReader blender::bke::AttributeAccessor::lookup ( const StringRef name,
const AttrType 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 611 of file BKE_attribute.hh.

◆ lookup() [4/5]

template<typename T>
AttributeReader< T > blender::bke::AttributeAccessor::lookup ( const StringRef name,
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 621 of file BKE_attribute.hh.

◆ lookup() [5/5]

GAttributeReader blender::bke::AttributeAccessor::lookup ( StringRef name,
std::optional< AttrDomain > domain,
std::optional< AttrType > 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 401 of file attribute_access.cc.

◆ lookup_meta_data()

Returns
Information about the attribute if it exists.

Definition at line 533 of file BKE_attribute.hh.

◆ lookup_or_default() [1/2]

template<typename T>
AttributeReader< T > blender::bke::AttributeAccessor::lookup_or_default ( const StringRef name,
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 644 of file BKE_attribute.hh.

◆ lookup_or_default() [2/2]

GAttributeReader blender::bke::AttributeAccessor::lookup_or_default ( StringRef name,
AttrDomain domain,
AttrType 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 415 of file attribute_access.cc.

◆ lookup_validator()

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

Definition at line 657 of file BKE_attribute.hh.

Member Data Documentation

◆ fn_

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

Definition at line 509 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 505 of file BKE_attribute.hh.


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