Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_access.cc
| Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | std::ostream &operator<<(std::ostream &stream, const AttributeIDRef &attribute_id) | ||||
| return stream; | return stream; | ||||
| } | } | ||||
| const char *no_procedural_access_message = | const char *no_procedural_access_message = | ||||
| "This attribute can not be accessed in a procedural context"; | "This attribute can not be accessed in a procedural context"; | ||||
| bool allow_procedural_attribute_access(StringRef attribute_name) | bool allow_procedural_attribute_access(StringRef attribute_name) | ||||
| { | { | ||||
| return !attribute_name.startswith(".sculpt") && !attribute_name.startswith(".select") && | if (attribute_name.startswith(".select")) { | ||||
| !attribute_name.startswith(".hide"); | return false; | ||||
| } | |||||
brecht: No need to use `std::string`, instead use `"." UV_VERTSEL_NAME "."` | |||||
Done Inline Actionsyou're right of course. In an earlier iteration I had the UV_VERTSEL_NAMES as char const *s instead of string literal macros. I forgot to change this. Baardaap: you're right of course. In an earlier iteration I had the UV_VERTSEL_NAMES as char const *s… | |||||
| if (attribute_name.startswith(".sculpt")) { | |||||
| return false; | |||||
| } | |||||
| if (attribute_name.startswith(".hide")) { | |||||
| return false; | |||||
| } | |||||
| if (attribute_name.startswith("." UV_VERTSEL_NAME ".")) { | |||||
| return false; | |||||
| } | |||||
| if (attribute_name.startswith("." UV_EDGESEL_NAME ".")) { | |||||
| return false; | |||||
| } | |||||
| if (attribute_name.startswith("." UV_PINNED_NAME ".")) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | } | ||||
| static int attribute_data_type_complexity(const eCustomDataType data_type) | static int attribute_data_type_complexity(const eCustomDataType data_type) | ||||
| { | { | ||||
| switch (data_type) { | switch (data_type) { | ||||
| case CD_PROP_BOOL: | case CD_PROP_BOOL: | ||||
| return 0; | return 0; | ||||
| case CD_PROP_INT8: | case CD_PROP_INT8: | ||||
| ▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | |||||
| static void *add_generic_custom_data_layer(CustomData &custom_data, | static void *add_generic_custom_data_layer(CustomData &custom_data, | ||||
| const eCustomDataType data_type, | const eCustomDataType data_type, | ||||
| const eCDAllocType alloctype, | const eCDAllocType alloctype, | ||||
| void *layer_data, | void *layer_data, | ||||
| const int domain_num, | const int domain_num, | ||||
| const AttributeIDRef &attribute_id) | const AttributeIDRef &attribute_id) | ||||
| { | { | ||||
| if (!attribute_id.is_anonymous()) { | if (!attribute_id.is_anonymous()) { | ||||
| char attribute_name_c[MAX_NAME]; | char attribute_name_c[MAX_CUSTOMDATA_LAYER_NAME]; | ||||
| attribute_id.name().copy(attribute_name_c); | attribute_id.name().copy(attribute_name_c); | ||||
| return CustomData_add_layer_named( | return CustomData_add_layer_named( | ||||
| &custom_data, data_type, alloctype, layer_data, domain_num, attribute_name_c); | &custom_data, data_type, alloctype, layer_data, domain_num, attribute_name_c); | ||||
| } | } | ||||
| const AnonymousAttributeID &anonymous_id = attribute_id.anonymous_id(); | const AnonymousAttributeID &anonymous_id = attribute_id.anonymous_id(); | ||||
| return CustomData_add_layer_anonymous( | return CustomData_add_layer_anonymous( | ||||
| &custom_data, data_type, alloctype, layer_data, domain_num, &anonymous_id); | &custom_data, data_type, alloctype, layer_data, domain_num, &anonymous_id); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 301 Lines • ▼ Show 20 Lines | if (this->type_is_supported(data_type)) { | ||||
| if (!callback(attribute_id, meta_data)) { | if (!callback(attribute_id, meta_data)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| GAttributeReader NamedLegacyCustomDataProvider::try_get_for_read( | |||||
| const void *owner, const AttributeIDRef &attribute_id) const | |||||
| { | |||||
| const CustomData *custom_data = custom_data_access_.get_const_custom_data(owner); | |||||
| if (custom_data == nullptr) { | |||||
| return {}; | |||||
| } | |||||
| for (const CustomDataLayer &layer : Span(custom_data->layers, custom_data->totlayer)) { | |||||
| if (layer.type == stored_type_) { | |||||
| if (custom_data_layer_matches_attribute_id(layer, attribute_id)) { | |||||
| const int domain_num = custom_data_access_.get_element_num(owner); | |||||
| return {as_read_attribute_(layer.data, domain_num), domain_}; | |||||
| } | |||||
| } | |||||
| } | |||||
| return {}; | |||||
| } | |||||
| GAttributeWriter NamedLegacyCustomDataProvider::try_get_for_write( | |||||
| void *owner, const AttributeIDRef &attribute_id) const | |||||
| { | |||||
| CustomData *custom_data = custom_data_access_.get_custom_data(owner); | |||||
| if (custom_data == nullptr) { | |||||
| return {}; | |||||
| } | |||||
| for (CustomDataLayer &layer : MutableSpan(custom_data->layers, custom_data->totlayer)) { | |||||
| if (layer.type == stored_type_) { | |||||
| if (custom_data_layer_matches_attribute_id(layer, attribute_id)) { | |||||
| const int element_num = custom_data_access_.get_element_num(owner); | |||||
| void *data = CustomData_duplicate_referenced_layer_named( | |||||
| custom_data, stored_type_, layer.name, element_num); | |||||
| return {as_write_attribute_(data, element_num), domain_}; | |||||
| } | |||||
| } | |||||
| } | |||||
| return {}; | |||||
| } | |||||
| bool NamedLegacyCustomDataProvider::try_delete(void *owner, | |||||
| const AttributeIDRef &attribute_id) const | |||||
| { | |||||
| CustomData *custom_data = custom_data_access_.get_custom_data(owner); | |||||
| if (custom_data == nullptr) { | |||||
| return false; | |||||
| } | |||||
| for (const int i : IndexRange(custom_data->totlayer)) { | |||||
| const CustomDataLayer &layer = custom_data->layers[i]; | |||||
| if (layer.type == stored_type_) { | |||||
| if (custom_data_layer_matches_attribute_id(layer, attribute_id)) { | |||||
| const int element_num = custom_data_access_.get_element_num(owner); | |||||
| CustomData_free_layer(custom_data, stored_type_, element_num, i); | |||||
| return true; | |||||
| } | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| bool NamedLegacyCustomDataProvider::foreach_attribute( | |||||
| const void *owner, const AttributeForeachCallback callback) const | |||||
| { | |||||
| const CustomData *custom_data = custom_data_access_.get_const_custom_data(owner); | |||||
| if (custom_data == nullptr) { | |||||
| return true; | |||||
| } | |||||
| for (const CustomDataLayer &layer : Span(custom_data->layers, custom_data->totlayer)) { | |||||
| if (layer.type == stored_type_) { | |||||
| AttributeMetaData meta_data{domain_, attribute_type_}; | |||||
| if (!callback(layer.name, meta_data)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| void NamedLegacyCustomDataProvider::foreach_domain( | |||||
| const FunctionRef<void(eAttrDomain)> callback) const | |||||
| { | |||||
| callback(domain_); | |||||
| } | |||||
| CustomDataAttributes::CustomDataAttributes() | CustomDataAttributes::CustomDataAttributes() | ||||
| { | { | ||||
| CustomData_reset(&data); | CustomData_reset(&data); | ||||
| size_ = 0; | size_ = 0; | ||||
| } | } | ||||
| CustomDataAttributes::~CustomDataAttributes() | CustomDataAttributes::~CustomDataAttributes() | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 401 Lines • Show Last 20 Lines | |||||
No need to use std::string, instead use "." UV_VERTSEL_NAME "."