[Bf-blender-cvs] [392a95e0bcc] refactor-mesh-uv-map-generic: Handle UV map associated bool lyers on attribute removal

Martijn Versteegh noreply at git.blender.org
Tue Jan 3 13:10:25 CET 2023


Commit: 392a95e0bcc9576b3e8dadc2484a1ce1e1ce42ca
Author: Martijn Versteegh
Date:   Tue Jan 3 13:09:45 2023 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB392a95e0bcc9576b3e8dadc2484a1ce1e1ce42ca

Handle UV map associated bool lyers on attribute removal

===================================================================

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/intern/attribute.cc
M	source/blender/blenkernel/intern/customdata.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 01ceee78497..b725ec3b6ec 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -440,6 +440,7 @@ int CustomData_get_n_offset(const struct CustomData *data, int type, int n);
 int CustomData_get_layer_index(const struct CustomData *data, int type);
 int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n);
 int CustomData_get_named_layer_index(const struct CustomData *data, int type, const char *name);
+int CustomData_get_named_layer_index_notype(const struct CustomData *data, const char *name);
 int CustomData_get_active_layer_index(const struct CustomData *data, int type);
 int CustomData_get_render_layer_index(const struct CustomData *data, int type);
 int CustomData_get_clone_layer_index(const struct CustomData *data, int type);
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index 0431967ebc0..490f7d48833 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -341,11 +341,23 @@ bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);
 
+
+
   if (GS(id->name) == ID_ME) {
     Mesh *mesh = reinterpret_cast<Mesh *>(id);
     if (BMEditMesh *em = mesh->edit_mesh) {
       for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
         if (CustomData *data = info[domain].customdata) {
+          int layer_index = CustomData_get_named_layer_index_notype(data, name);
+          if (layer_index >= 0) {
+            if (data->layers[layer_index].type == CD_PROP_FLOAT2) {
+              /* free associated UV map bool layers */
+              char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
+              BM_data_layer_free_named(em->bm, data, BKE_uv_map_vert_selection_name_get(name, buffer_src));
+              BM_data_layer_free_named(em->bm, data, BKE_uv_map_edge_selection_name_get(name, buffer_src));
+              BM_data_layer_free_named(em->bm, data, BKE_uv_map_pin_name_get(name, buffer_src));
+            }
+          }
           if (BM_data_layer_free_named(em->bm, data, name)) {
             if (name == StringRef(mesh->active_color_attribute)) {
               MEM_SAFE_FREE(mesh->active_color_attribute);
@@ -362,10 +374,30 @@ bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)
   }
 
   std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(*id);
+
   if (!attributes) {
     return false;
   }
 
+  if (GS(id->name) == ID_ME) {
+
+    std::optional<blender::bke::AttributeMetaData> metadata = attributes->lookup_meta_data(name);
+    if (metadata->data_type == CD_PROP_FLOAT2)
+    {
+      /* remove UV sub-attributes. */
+      char buffer_src[MAX_CUSTOMDATA_LAYER_NAME];
+      BKE_id_attribute_remove(id,
+                              BKE_uv_map_vert_selection_name_get(name, buffer_src),
+                              reports);
+      BKE_id_attribute_remove(id,
+                              BKE_uv_map_edge_selection_name_get(name, buffer_src),
+                              reports);
+      BKE_id_attribute_remove(id,
+                              BKE_uv_map_pin_name_get(name, buffer_src),
+                              reports);
+    }
+  }
+
   return attributes->remove(name);
 }
 
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 0509592427a..04233d1aedc 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -2506,6 +2506,18 @@ int CustomData_get_named_layer_index(const CustomData *data, const int type, con
   return -1;
 }
 
+int CustomData_get_named_layer_index_notype(const CustomData *data, const char *name)
+{
+  for (int i = 0; i < data->totlayer; i++) {
+    if (STREQ(data->layers[i].name, name)) {
+        return i;
+    }
+  }
+
+  return -1;
+}
+
+
 int CustomData_get_active_layer_index(const CustomData *data, const int type)
 {
   const int layer_index = data->typemap[type];



More information about the Bf-blender-cvs mailing list