Blender V4.3
blender::bke::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
 
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 AttributeAccessorFunctionsfn_
 

Attribute API

bool contains (const StringRef attribute_id) const
 
std::optional< AttributeMetaDatalookup_meta_data (const 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 491 of file BKE_attribute.hh.

Constructor & Destructor Documentation

◆ AttributeAccessor()

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

Definition at line 510 of file BKE_attribute.hh.

Member Function Documentation

◆ adapt_domain() [1/2]

◆ 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 650 of file BKE_attribute.hh.

References adapt_domain(), and blender::GVArray::typed().

◆ all_ids()

◆ contains()

◆ domain_size()

◆ domain_supported()

bool blender::bke::AttributeAccessor::domain_supported ( const AttrDomain domain) const
inline
Returns
True, when attributes can exist on that domain.

Definition at line 533 of file BKE_attribute.hh.

References blender::bke::AttributeAccessorFunctions::domain_supported, fn_, and owner_.

◆ 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 661 of file BKE_attribute.hh.

References fn_, blender::bke::AttributeAccessorFunctions::foreach_attribute, and owner_.

Referenced by attr_create_generic(), attr_create_generic(), contains(), copy_attributes(), blender::bke::copy_attributes_group_to_group(), blender::nodes::node_geo_curve_to_points_cc::copy_curve_domain_attributes(), blender::ed::sculpt_paint::greasepencil::create_blank_curve(), blender::geometry::create_curve_from_vert_indices(), blender::nodes::node_geo_curves_to_grease_pencil_cc::curve_instances_to_grease_pencil_layers(), blender::bke::curve_to_mesh_sweep(), blender::ed::sculpt_paint::greasepencil::extend_curve(), blender::geometry::extract_mesh_edges(), blender::geometry::extract_mesh_faces(), blender::geometry::extract_mesh_vertices(), blender::bke::gather_attributes(), blender::bke::gather_attributes(), blender::bke::gather_attributes_group_to_group(), blender::bke::gather_attributes_to_groups(), blender::geometry::gather_attributes_to_propagate(), blender::geometry::gather_curve_attributes_to_interpolate(), blender::geometry::gather_point_attributes_to_interpolate(), blender::geometry::gather_point_attributes_to_interpolate(), blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_generation_items_group(), blender::nodes::node_geo_interpolate_curves_cc::interpolate_curve_attributes(), lookup_meta_data(), blender::bke::mesh_flip_faces(), blender::bke::mesh_remesh_reproject_attributes(), blender::nodes::node_geo_grease_pencil_to_curves_cc::node_geo_exec(), blender::geometry::prepare_attribute_fallbacks(), blender::bke::GeometrySet::propagate_attributes_from_layer_to_instances(), blender::geometry::reorder_and_flip_attributes_group_to_group(), blender::geometry::reorder_attributes_group_to_group(), blender::ed::curves::resize_curves(), blender::bke::retrieve_attributes_for_transfer(), and blender::ed::sculpt_paint::greasepencil::trim_end_points().

◆ from_id()

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

Construct an AttributeAccessor from an ID.

Definition at line 571 of file attribute_access.cc.

References GS, ID_CV, ID_GP, ID_ME, and ID_PT.

◆ is_builtin()

◆ lookup() [1/5]

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

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

Definition at line 559 of file BKE_attribute.hh.

References fn_, blender::bke::AttributeAccessorFunctions::lookup, and owner_.

Referenced by blender::draw::overlay::add_attributes_to_text_cache(), blender::draw::overlay::add_instance_attributes_to_text_cache(), blender::nodes::node_geo_instance_on_points_cc::add_instances_from_component(), blender::bke::Instances::almost_unique_ids(), attr_create_subd_uv_map(), attr_create_uv_map(), BKE_shrinkwrap_init_tree(), blender::bke::build_mesh_positions(), blender::nodes::node_geo_instances_to_points_cc::convert_instances_to_points(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_curves(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_edges(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_faces(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_point(), blender::geometry::create_id_index_map(), create_mesh(), blender::ed::greasepencil::curves_geometry_is_equal(), ED_mesh_pick_vert(), export_hair_curves(), export_hair_curves_motion(), blender::ed::curves::extrude_curves(), blender::draw::pbvh::fill_vbos_mesh(), blender::bke::gather_attributes(), blender::nodes::node_geo_interpolate_curves_cc::generate_interpolated_curves(), blender::nodes::node_geo_mesh_to_points_cc::geometry_set_mesh_to_points(), blender::nodes::node_geo_points_to_vertices_cc::geometry_set_points_to_vertices(), blender::bke::AttributeFieldInput::get_varray_for_context(), blender::nodes::LazyFunctionForReduceForeachGeometryElement::handle_generation_items_group(), lookup(), lookup(), lookup(), lookup(), lookup_or_default(), lookup_or_default(), mesh_merge_transform(), MOD_solidify_nonmanifold_modifyMesh(), blender::nodes::node_geo_deform_curves_on_surface_cc::node_geo_exec(), blender::geometry::point_merge_by_distance(), blender::io::usd::populate_curve_widths(), blender::nodes::node_geo_distribute_points_on_faces_cc::propagate_existing_attributes(), blender::geometry::retrieve_attribute_spans(), blender::geometry::retrieve_attribute_spans(), SCULPT_cursor_geometry_info_update(), SCULPT_stroke_get_location_ex(), blender::ed::curves::snap_curves_to_surface::snap_curves_to_surface_exec_object(), blender::bke::compare_meshes::sort_domain_using_attributes(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::geometry::tests::TEST(), blender::nodes::node_geo_dual_mesh_cc::transfer_attributes(), and blender::bke::compare_meshes::verify_attributes_compatible().

◆ 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 576 of file BKE_attribute.hh.

References lookup().

◆ 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 585 of file BKE_attribute.hh.

References lookup().

◆ 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 595 of file BKE_attribute.hh.

References blender::bke::cpp_type_to_custom_data_type(), blender::CPPType::get(), lookup(), and blender::bke::GAttributeReader::typed().

◆ 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 620 of file attribute_access.cc.

References blender::bke::adapt_domain_and_type_if_necessary(), and lookup().

◆ lookup_meta_data()

◆ 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 618 of file BKE_attribute.hh.

References domain_size(), blender::VArray< T >::ForSingle(), and lookup().

◆ 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 633 of file attribute_access.cc.

References attribute, blender::bke::custom_data_type_to_cpp_type(), domain_size(), blender::GVArray::ForSingle(), blender::GVArray::ForSingleRef(), and lookup().

Referenced by blender::ed::greasepencil::bake_grease_pencil_animation_exec(), blender::ed::greasepencil::create_curves_outline(), blender::create_dashes(), blender::create_envelope_strokes(), blender::nodes::node_geo_curves_to_grease_pencil_cc::curve_instances_to_grease_pencil_layers(), blender::io::alembic::ABCCurveWriter::do_write(), blender::ed::sculpt_paint::CombOperationExecutor::execute(), blender::ed::sculpt_paint::CurvesEffectOperationExecutor::execute(), blender::ed::sculpt_paint::PinchOperationExecutor::execute(), blender::ed::sculpt_paint::PuffOperationExecutor::execute(), blender::ed::sculpt_paint::SlideOperationExecutor::execute(), blender::ed::sculpt_paint::SmoothOperationExecutor::execute(), blender::ed::sculpt_paint::SnakeHookOperatorExecutor::execute(), blender::modifier::greasepencil::get_filtered_layer_mask(), blender::nodes::node_geo_tool_selection_cc::EditSelectionFieldInput::get_varray_for_context(), blender::nodes::node_geo_tool_selection_cc::SculptSelectionFieldInput::get_varray_for_context(), grease_pencil_do_layer_adjustments(), blender::nodes::node_geo_deform_curves_on_surface_cc::node_geo_exec(), OVERLAY_grease_pencil_material_names(), paintface_flush_flags(), paintvert_flush_flags(), blender::geometry::point_merge_by_distance(), and blender::ed::sculpt_paint::greasepencil::EraseOperationExecutor::soft_eraser().

◆ 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 631 of file BKE_attribute.hh.

References fn_, blender::bke::AttributeAccessorFunctions::lookup_validator, and owner_.

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 507 of file BKE_attribute.hh.

Referenced by adapt_domain(), blender::bke::MutableAttributeAccessor::add(), domain_size(), domain_supported(), foreach_attribute(), is_builtin(), lookup(), lookup_validator(), and blender::bke::MutableAttributeAccessor::remove().

◆ owner_

void* blender::bke::AttributeAccessor::owner_
protected

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 503 of file BKE_attribute.hh.

Referenced by adapt_domain(), blender::bke::MutableAttributeAccessor::add(), domain_size(), domain_supported(), foreach_attribute(), is_builtin(), lookup(), lookup_validator(), and blender::bke::MutableAttributeAccessor::remove().


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