Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_access.cc
| Show First 20 Lines • Show All 615 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * This provider is used to provide access to builtin attributes. It supports making internal types | * This provider is used to provide access to builtin attributes. It supports making internal types | ||||
| * available as different types. For example, the vertex position attribute is stored as part of | * available as different types. For example, the vertex position attribute is stored as part of | ||||
| * the #MVert struct, but is exposed as float3 attribute. | * the #MVert struct, but is exposed as float3 attribute. | ||||
| */ | */ | ||||
| class BuiltinCustomDataLayerProvider final : public BuiltinAttributeProvider { | class BuiltinCustomDataLayerProvider final : public BuiltinAttributeProvider { | ||||
| using AsReadAttribute = ReadAttributePtr (*)(const void *data, const int domain_size); | using AsReadAttribute = ReadAttributePtr (*)(const void *data, const int domain_size); | ||||
| using AsWriteAttribute = WriteAttributePtr (*)(void *data, const int domain_size); | using AsWriteAttribute = WriteAttributePtr (*)(void *data, const int domain_size); | ||||
| using UpdateOnWrite = void (*)(GeometryComponent &component); | |||||
| const CustomDataType stored_type_; | const CustomDataType stored_type_; | ||||
| const CustomDataAccessInfo custom_data_access_; | const CustomDataAccessInfo custom_data_access_; | ||||
| const AsReadAttribute as_read_attribute_; | const AsReadAttribute as_read_attribute_; | ||||
| const AsWriteAttribute as_write_attribute_; | const AsWriteAttribute as_write_attribute_; | ||||
| const UpdateOnWrite update_on_write_; | |||||
HooglyBoogly: I wonder if the name should be slightly more general, this seems a bit specific to how this… | |||||
| public: | public: | ||||
| BuiltinCustomDataLayerProvider(std::string attribute_name, | BuiltinCustomDataLayerProvider(std::string attribute_name, | ||||
| const AttributeDomain domain, | const AttributeDomain domain, | ||||
| const CustomDataType attribute_type, | const CustomDataType attribute_type, | ||||
| const CustomDataType stored_type, | const CustomDataType stored_type, | ||||
| const CreatableEnum creatable, | const CreatableEnum creatable, | ||||
| const WritableEnum writable, | const WritableEnum writable, | ||||
| const DeletableEnum deletable, | const DeletableEnum deletable, | ||||
| const CustomDataAccessInfo custom_data_access, | const CustomDataAccessInfo custom_data_access, | ||||
| const AsReadAttribute as_read_attribute, | const AsReadAttribute as_read_attribute, | ||||
| const AsWriteAttribute as_write_attribute) | const AsWriteAttribute as_write_attribute, | ||||
| const UpdateOnWrite update_on_write) | |||||
| : BuiltinAttributeProvider( | : BuiltinAttributeProvider( | ||||
| std::move(attribute_name), domain, attribute_type, creatable, writable, deletable), | std::move(attribute_name), domain, attribute_type, creatable, writable, deletable), | ||||
| stored_type_(stored_type), | stored_type_(stored_type), | ||||
| custom_data_access_(custom_data_access), | custom_data_access_(custom_data_access), | ||||
| as_read_attribute_(as_read_attribute), | as_read_attribute_(as_read_attribute), | ||||
| as_write_attribute_(as_write_attribute) | as_write_attribute_(as_write_attribute), | ||||
| update_on_write_(update_on_write) | |||||
| { | { | ||||
| } | } | ||||
| ReadAttributePtr try_get_for_read(const GeometryComponent &component) const final | ReadAttributePtr try_get_for_read(const GeometryComponent &component) const final | ||||
| { | { | ||||
| const CustomData *custom_data = custom_data_access_.get_const_custom_data(component); | const CustomData *custom_data = custom_data_access_.get_const_custom_data(component); | ||||
| if (custom_data == nullptr) { | if (custom_data == nullptr) { | ||||
| return {}; | return {}; | ||||
| Show All 20 Lines | WriteAttributePtr try_get_for_write(GeometryComponent &component) const final | ||||
| if (data == nullptr) { | if (data == nullptr) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| void *new_data = CustomData_duplicate_referenced_layer(custom_data, stored_type_, domain_size); | void *new_data = CustomData_duplicate_referenced_layer(custom_data, stored_type_, domain_size); | ||||
| if (data != new_data) { | if (data != new_data) { | ||||
| custom_data_access_.update_custom_data_pointers(component); | custom_data_access_.update_custom_data_pointers(component); | ||||
| data = new_data; | data = new_data; | ||||
| } | } | ||||
| if (update_on_write_ != nullptr) { | |||||
| update_on_write_(component); | |||||
| } | |||||
| return as_write_attribute_(data, domain_size); | return as_write_attribute_(data, domain_size); | ||||
| } | } | ||||
| bool try_delete(GeometryComponent &component) const final | bool try_delete(GeometryComponent &component) const final | ||||
| { | { | ||||
| if (deletable_ != Deletable) { | if (deletable_ != Deletable) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | |||||
| static WriteAttributePtr make_vertex_position_write_attribute(void *data, const int domain_size) | static WriteAttributePtr make_vertex_position_write_attribute(void *data, const int domain_size) | ||||
| { | { | ||||
| return std::make_unique< | return std::make_unique< | ||||
| DerivedArrayWriteAttribute<MVert, float3, get_vertex_position, set_vertex_position>>( | DerivedArrayWriteAttribute<MVert, float3, get_vertex_position, set_vertex_position>>( | ||||
| ATTR_DOMAIN_POINT, MutableSpan<MVert>((MVert *)data, domain_size)); | ATTR_DOMAIN_POINT, MutableSpan<MVert>((MVert *)data, domain_size)); | ||||
| } | } | ||||
| static void tag_normals_dirty_when_writing_position(GeometryComponent &component) | |||||
| { | |||||
| Mesh *mesh = get_mesh_from_component_for_write(component); | |||||
| if (mesh != nullptr) { | |||||
| mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL; | |||||
| } | |||||
| } | |||||
| template<typename T, AttributeDomain Domain> | template<typename T, AttributeDomain Domain> | ||||
| static ReadAttributePtr make_array_read_attribute(const void *data, const int domain_size) | static ReadAttributePtr make_array_read_attribute(const void *data, const int domain_size) | ||||
| { | { | ||||
| return std::make_unique<ArrayReadAttribute<T>>(Domain, Span<T>((const T *)data, domain_size)); | return std::make_unique<ArrayReadAttribute<T>>(Domain, Span<T>((const T *)data, domain_size)); | ||||
| } | } | ||||
| template<typename T, AttributeDomain Domain> | template<typename T, AttributeDomain Domain> | ||||
| static WriteAttributePtr make_array_write_attribute(void *data, const int domain_size) | static WriteAttributePtr make_array_write_attribute(void *data, const int domain_size) | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static BuiltinCustomDataLayerProvider position("position", | ||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| CD_MVERT, | CD_MVERT, | ||||
| BuiltinAttributeProvider::NonCreatable, | BuiltinAttributeProvider::NonCreatable, | ||||
| BuiltinAttributeProvider::Writable, | BuiltinAttributeProvider::Writable, | ||||
| BuiltinAttributeProvider::NonDeletable, | BuiltinAttributeProvider::NonDeletable, | ||||
| point_access, | point_access, | ||||
| make_vertex_position_read_attribute, | make_vertex_position_read_attribute, | ||||
| make_vertex_position_write_attribute); | make_vertex_position_write_attribute, | ||||
| tag_normals_dirty_when_writing_position); | |||||
| static MeshUVsAttributeProvider uvs; | static MeshUVsAttributeProvider uvs; | ||||
| static VertexGroupsAttributeProvider vertex_groups; | static VertexGroupsAttributeProvider vertex_groups; | ||||
| static CustomDataAttributeProvider corner_custom_data(ATTR_DOMAIN_CORNER, corner_access); | static CustomDataAttributeProvider corner_custom_data(ATTR_DOMAIN_CORNER, corner_access); | ||||
| static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | ||||
| static CustomDataAttributeProvider edge_custom_data(ATTR_DOMAIN_EDGE, edge_access); | static CustomDataAttributeProvider edge_custom_data(ATTR_DOMAIN_EDGE, edge_access); | ||||
| static CustomDataAttributeProvider polygon_custom_data(ATTR_DOMAIN_POLYGON, polygon_access); | static CustomDataAttributeProvider polygon_custom_data(ATTR_DOMAIN_POLYGON, polygon_access); | ||||
| return ComponentAttributeProviders({&position}, | return ComponentAttributeProviders({&position}, | ||||
| Show All 37 Lines | static BuiltinCustomDataLayerProvider position( | ||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| BuiltinAttributeProvider::NonCreatable, | BuiltinAttributeProvider::NonCreatable, | ||||
| BuiltinAttributeProvider::Writable, | BuiltinAttributeProvider::Writable, | ||||
| BuiltinAttributeProvider::NonDeletable, | BuiltinAttributeProvider::NonDeletable, | ||||
| point_access, | point_access, | ||||
| make_array_read_attribute<float3, ATTR_DOMAIN_POINT>, | make_array_read_attribute<float3, ATTR_DOMAIN_POINT>, | ||||
| make_array_write_attribute<float3, ATTR_DOMAIN_POINT>); | make_array_write_attribute<float3, ATTR_DOMAIN_POINT>, | ||||
| nullptr); | |||||
| static BuiltinCustomDataLayerProvider radius( | static BuiltinCustomDataLayerProvider radius( | ||||
| "radius", | "radius", | ||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| CD_PROP_FLOAT, | CD_PROP_FLOAT, | ||||
| CD_PROP_FLOAT, | CD_PROP_FLOAT, | ||||
| BuiltinAttributeProvider::Creatable, | BuiltinAttributeProvider::Creatable, | ||||
| BuiltinAttributeProvider::Writable, | BuiltinAttributeProvider::Writable, | ||||
| BuiltinAttributeProvider::Deletable, | BuiltinAttributeProvider::Deletable, | ||||
| point_access, | point_access, | ||||
| make_array_read_attribute<float, ATTR_DOMAIN_POINT>, | make_array_read_attribute<float, ATTR_DOMAIN_POINT>, | ||||
| make_array_write_attribute<float, ATTR_DOMAIN_POINT>); | make_array_write_attribute<float, ATTR_DOMAIN_POINT>, | ||||
| nullptr); | |||||
| static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | ||||
| return ComponentAttributeProviders({&position, &radius}, {&point_custom_data}); | return ComponentAttributeProviders({&position, &radius}, {&point_custom_data}); | ||||
| } | } | ||||
| } // namespace blender::bke | } // namespace blender::bke | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Geometry Component | /** \name Geometry Component | ||||
| ▲ Show 20 Lines • Show All 539 Lines • Show Last 20 Lines | |||||
I wonder if the name should be slightly more general, this seems a bit specific to how this works for meshes. Maybe update_on_write?
The specific function name provided for this field can give the required context anyway.