Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-06-14 17:25:24 +0300
committerHans Goudey <h.goudey@me.com>2022-06-14 17:41:43 +0300
commit58a67e6fb6df527ed45c0a554efd387e770bdc42 (patch)
treeea4fdb342e7d98a236dd929d2e8fbbbbdcb72e8a /source/blender/blenkernel
parent3012eca3503779697208f24d9f0a09494cd51455 (diff)
Attributes: Adjustments to duplicate attribute API function
Use a name argument, for the same reasons as 6eea5f70e3b79e3c668. Also reuse the layer and unique name creation in `BKE_id_attribute_new` instead of reimplementing it. Also include a few miscellaneous cleanups like using const variables and `std::string`.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_attribute.h2
-rw-r--r--source/blender/blenkernel/intern/attribute.cc53
2 files changed, 19 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 5755ddb3018..18993546e83 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -64,7 +64,7 @@ bool BKE_id_attribute_remove(struct ID *id, const char *name, struct ReportList
* Creates a duplicate attribute layer.
*/
struct CustomDataLayer *BKE_id_attribute_duplicate(struct ID *id,
- struct CustomDataLayer *layer,
+ const char *name,
struct ReportList *reports);
struct CustomDataLayer *BKE_id_attribute_find(const struct ID *id,
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index b2ea8b833b3..7bc51881f1f 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -208,53 +208,36 @@ CustomDataLayer *BKE_id_attribute_new(
return (index == -1) ? nullptr : &(customdata->layers[index]);
}
-CustomDataLayer *BKE_id_attribute_duplicate(ID *id, CustomDataLayer *layer, ReportList *reports)
+CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList *reports)
{
- DomainInfo info[ATTR_DOMAIN_NUM];
- get_domains(id, info);
-
- eCustomDataType type = (eCustomDataType)layer->type;
- eAttrDomain domain = BKE_id_attribute_domain(id, layer);
-
- CustomData *customdata = info[domain].customdata;
- if (customdata == nullptr) {
- BKE_report(reports, RPT_ERROR, "Attribute domain not supported by this geometry type");
+ const CustomDataLayer *src_layer = BKE_id_attribute_search(
+ id, name, CD_MASK_PROP_ALL, ATTR_DOMAIN_MASK_ALL);
+ if (src_layer == nullptr) {
+ BKE_report(reports, RPT_ERROR, "Attribute is not part of this geometry");
return nullptr;
}
- char name[MAX_CUSTOMDATA_LAYER_NAME];
- char uniquename[MAX_CUSTOMDATA_LAYER_NAME];
+ const eCustomDataType type = (eCustomDataType)src_layer->type;
+ const eAttrDomain domain = BKE_id_attribute_domain(id, src_layer);
/* Make a copy of name in case CustomData API reallocates the layers. */
- BLI_strncpy(name, layer->name, MAX_CUSTOMDATA_LAYER_NAME);
- BKE_id_attribute_calc_unique_name(id, layer->name, uniquename);
+ const std::string name_copy = name;
- switch (GS(id->name)) {
- case ID_ME: {
- Mesh *me = (Mesh *)id;
- BMEditMesh *em = me->edit_mesh;
- if (em != nullptr) {
- BM_data_layer_add_named(em->bm, customdata, type, uniquename);
- }
- else {
- CustomData_add_layer_named(
- customdata, type, CD_DEFAULT, nullptr, info[domain].length, uniquename);
- }
- break;
- }
- default: {
- CustomData_add_layer_named(
- customdata, type, CD_DEFAULT, nullptr, info[domain].length, uniquename);
- break;
- }
+ DomainInfo info[ATTR_DOMAIN_NUM];
+ get_domains(id, info);
+ CustomData *customdata = info[domain].customdata;
+
+ CustomDataLayer *new_layer = BKE_id_attribute_new(id, name_copy.c_str(), type, domain, reports);
+ if (new_layer == nullptr) {
+ return nullptr;
}
- int from_index = CustomData_get_named_layer_index(customdata, type, name);
- int to_index = CustomData_get_named_layer_index(customdata, type, uniquename);
+ const int from_index = CustomData_get_named_layer_index(customdata, type, name_copy.c_str());
+ const int to_index = CustomData_get_named_layer_index(customdata, type, new_layer->name);
CustomData_copy_data_layer(
customdata, customdata, from_index, to_index, 0, 0, info[domain].length);
- return (to_index == -1) ? nullptr : &(customdata->layers[to_index]);
+ return new_layer;
}
bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)