diff options
author | Hans Goudey <h.goudey@me.com> | 2022-11-10 23:38:49 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-11-11 00:29:21 +0300 |
commit | ca1642cd0c5cdf634fe2022c955d93983de95934 (patch) | |
tree | 4d12e830e6c4eb6a8e9d39bdd5a0a5e6ce23301c | |
parent | 34f4646786dad75b418250cc8e4bf92441434d00 (diff) |
Cleanup: Use string argument for attribute API function
Instead of CustomDataLayer, which exposes the internal implementation
more than necessary, and requires that the layer is always available,
which isn't always true.
-rw-r--r-- | source/blender/blenkernel/BKE_attribute.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/attribute.cc | 27 | ||||
-rw-r--r-- | source/blender/editors/geometry/geometry_attributes.cc | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_attribute.c | 2 |
4 files changed, 9 insertions, 24 deletions
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index 13eefd27bec..3f4981993eb 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -90,7 +90,7 @@ int BKE_id_attributes_length(const struct ID *id, eCustomDataMask mask); struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); -void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); +void BKE_id_attributes_active_set(struct ID *id, const char *name); int *BKE_id_attributes_active_index_p(struct ID *id); CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers); diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 1a54454bf9a..80647362826 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -495,29 +495,14 @@ CustomDataLayer *BKE_id_attributes_active_get(ID *id) return nullptr; } -void BKE_id_attributes_active_set(ID *id, CustomDataLayer *active_layer) +void BKE_id_attributes_active_set(ID *id, const char *name) { - DomainInfo info[ATTR_DOMAIN_NUM]; - get_domains(id, info); - - int index = 0; + const CustomDataLayer *layer = BKE_id_attribute_search( + id, name, CD_MASK_PROP_ALL, ATTR_DOMAIN_MASK_ALL); + BLI_assert(layer != nullptr); - for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) { - const CustomData *customdata = info[domain].customdata; - if (customdata == nullptr) { - continue; - } - for (int i = 0; i < customdata->totlayer; i++) { - const CustomDataLayer *layer = &customdata->layers[i]; - if (layer == active_layer) { - *BKE_id_attributes_active_index_p(id) = index; - return; - } - if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) { - index++; - } - } - } + const int index = BKE_id_attribute_to_index(id, layer, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL); + *BKE_id_attributes_active_index_p(id) = index; } int *BKE_id_attributes_active_index_p(ID *id) diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 2233c6d59ad..7f163da493b 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -98,7 +98,7 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_id_attributes_active_set(id, layer); + BKE_id_attributes_active_set(id, layer->name); DEG_id_tag_update(id, ID_RECALC_GEOMETRY); WM_main_add_notifier(NC_GEOM | ND_DATA, id); diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index e1b6fb429a7..20c6e24b735 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -534,7 +534,7 @@ static void rna_AttributeGroup_active_set(PointerRNA *ptr, { ID *id = ptr->owner_id; CustomDataLayer *layer = attribute_ptr.data; - BKE_id_attributes_active_set(id, layer); + BKE_id_attributes_active_set(id, layer->name); } static void rna_AttributeGroup_active_index_set(PointerRNA *ptr, int value) |