Commit: 2049960aa3d9de4d3c8d02d41d9949358b9f8574
Author: Baardaap
Date:   Mon Dec 12 17:00:00 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB2049960aa3d9de4d3c8d02d41d9949358b9f8574

Make BM_ensure_selection_and_pin_attributes() loop over all CD_PROP_FLOAT2 
layers

Passing in the name does not work when adding layers, because the names passed
to CustomData_add_layer_named() can change the name to make it unique.

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

M       source/blender/bmesh/intern/bmesh_interp.c
M       source/blender/bmesh/intern/bmesh_interp.h
M       source/blender/editors/mesh/mesh_data.cc
M       
source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M       source/blender/python/bmesh/bmesh_py_types_customdata.c

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

diff --git a/source/blender/bmesh/intern/bmesh_interp.c 
b/source/blender/bmesh/intern/bmesh_interp.c
index 7c13b2e7663..745257dd919 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -873,15 +873,19 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData 
*data, int type, const cha
   }
 }
 
-void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm, const char 
*uv_map_name)
+void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm)
 {
-  char name[MAX_CUSTOMDATA_LAYER_NAME];
-  BM_data_layer_ensure_named(
-      bm, &bm->ldata, CD_PROP_BOOL, 
BKE_get_uv_map_vert_selection_name(uv_map_name, name));
-  BM_data_layer_ensure_named(
-      bm, &bm->ldata, CD_PROP_BOOL, 
BKE_get_uv_map_edge_selection_name(uv_map_name, name));
-  BM_data_layer_ensure_named(
-      bm, &bm->ldata, CD_PROP_BOOL, BKE_get_uv_map_pin_name(uv_map_name, 
name));
+  const int nr_uv_layers = CustomData_number_of_layers(&bm->ldata, 
CD_PROP_FLOAT2);
+  for (int l = 0; l < nr_uv_layers; l++ ) {
+    /* note: you can't re-use the returnvalue of CustomData_get_layer_name() 
because adding layers can invalidate that. */
+    char name[MAX_CUSTOMDATA_LAYER_NAME];
+    BM_data_layer_ensure_named(
+        bm, &bm->ldata, CD_PROP_BOOL, 
BKE_get_uv_map_vert_selection_name(CustomData_get_layer_name(&bm->ldata, 
CD_PROP_FLOAT2, l), name));
+    BM_data_layer_ensure_named(
+        bm, &bm->ldata, CD_PROP_BOOL, 
BKE_get_uv_map_edge_selection_name(CustomData_get_layer_name(&bm->ldata, 
CD_PROP_FLOAT2, l), name));
+    BM_data_layer_ensure_named(
+        bm, &bm->ldata, CD_PROP_BOOL, 
BKE_get_uv_map_pin_name(CustomData_get_layer_name(&bm->ldata, CD_PROP_FLOAT2, 
l), name));
+  }
 }
 
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name)
diff --git a/source/blender/bmesh/intern/bmesh_interp.h 
b/source/blender/bmesh/intern/bmesh_interp.h
index 0b7b5197074..c7ce6d36453 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -65,7 +65,9 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int 
type, const char *
 void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const 
char *name);
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
 
-void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm, const char 
*uv_map_name);
+/* This ensures the dependent bool layers exist for all CD_PROP_FLOAT2 layers 
*/
+void BM_uv_map_ensure_selection_and_pin_attributes(BMesh *bm);
+
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char 
*uv_map_name);
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name);
diff --git a/source/blender/editors/mesh/mesh_data.cc 
b/source/blender/editors/mesh/mesh_data.cc
index 496678ede3d..0c2d2eaf3d2 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -246,7 +246,7 @@ int ED_mesh_uv_add(
     }
 
     BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_PROP_FLOAT2, name);
-    BM_uv_map_ensure_selection_and_pin_attributes(em->bm, name);
+    BM_uv_map_ensure_selection_and_pin_attributes(em->bm);
     /* copy data from active UV */
     if (layernum_dst && do_init) {
       const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, 
CD_PROP_FLOAT2);
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
index 2543b21e7fb..4d59d904405 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
@@ -40,8 +40,7 @@ static Mesh *create_ico_sphere_mesh(const int subdivisions, 
const float radius)
    * Normally this would be done when adding a UV layer via python
    * or when copying from Mesh, but when we 'manually' create the UV layer
    * we need to make sure the bool layers exist as well. */
-  BM_uv_map_ensure_selection_and_pin_attributes(
-      bm, CustomData_get_layer_name(&bm->ldata, CD_PROP_FLOAT2, 0));
+  BM_uv_map_ensure_selection_and_pin_attributes(bm);
 
   BMO_op_callf(bm,
                BMO_FLAG_DEFAULTS,
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 659ec0bb104..97b13013793 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -466,9 +466,7 @@ static PyObject 
*bpy_bmlayercollection_verify(BPy_BMLayerCollection *self)
     /* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
      * in Py objects we can't lazily add the associated bool layers. So add 
them all right
      * now. */
-    const char *active_uv_name = 
CustomData_get_active_layer_name(&self->bm->ldata,
-                                                                  
CD_PROP_FLOAT2);
-    BM_uv_map_ensure_selection_and_pin_attributes(self->bm, active_uv_name);
+    BM_uv_map_ensure_selection_and_pin_attributes(self->bm);
   }
 
   BLI_assert(index >= 0);
@@ -515,9 +513,7 @@ static PyObject 
*bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject
     /* Because adding CustomData layers to a bmesh will invalidate any 
existing pointers
      * in Py objects we can't lazily add the associated bool layers. So add 
them all right
      * now. */
-    const char *active_uv_name = 
CustomData_get_active_layer_name(&self->bm->ldata,
-                                                                  
CD_PROP_FLOAT2);
-    BM_uv_map_ensure_selection_and_pin_attributes(self->bm, active_uv_name);
+    BM_uv_map_ensure_selection_and_pin_attributes(self->bm);
   }
 
   index = CustomData_number_of_layers(data, self->type) - 1;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to