[Bf-blender-cvs] [93d84e87b26] master: Fix T103400: Transfer Mesh Data Layout broken for color attributes

Philipp Oeser noreply at git.blender.org
Thu Jan 19 09:28:05 CET 2023


Commit: 93d84e87b26c85f814f4a2537e73387628491b68
Author: Philipp Oeser
Date:   Thu Jan 5 16:05:51 2023 +0100
Branches: master
https://developer.blender.org/rB93d84e87b26c85f814f4a2537e73387628491b68

Fix T103400: Transfer Mesh Data Layout broken for color attributes

This was the case when using the operator outside of the modifiers panel.

Caused by {rBeae36be372a6}.

In above commit, `DT_layer_items` shared both `DT_TYPE_MPROPCOL_LOOP` |
`DT_TYPE_MLOOPCOL_LOOP` in a single EnumPropertyItem value "Colors".
This is a bit unusual, but probably allowed.
As a consequence, checks for specific datatypes would fail when selecting
such EnumPropertyItem:
- `DT_DATATYPE_IS_MULTILAYERS` (uses `ELEM` to check distinct entries --
would return false)
- `BKE_object_data_transfer_dttype_to_srcdst_index` (would return
`DT_MULTILAYER_INDEX_INVALID`)

These places have now been corrected to take these "special" values into
account.

Another issue was that multiple EnumPropertyItems with the same value
could be created in dt_add_vcol_layers() if attributes of the same
domain, but different color types are in play (could lead to crashes)
and that has also been corrected.

Also: above commit did not give the choice of transfering color
attributes from the vertex domain (only face corner attributes could be
chosen), this has now been added. DT_layer_vert_items (used from the
modifier) already had this included so this was only an issue when using
the operator outside of the modifiers panel.

Since we now feature two domains, the single "VCOL" in the enum has been
split into "COLOR_VERTEX" and "COLOR_CORNER". This will break existing
scripts calling bpy.ops.object.datalayout_transfer and will be marked as
a breaking change in the release notes.

NOTE: there is another bug here when attributes of the same domain, but
different color types are in play and you want to transfer just a single
specific layer (but that is for a separate commit)

Maniphest Tasks: T103400

Differential Revision: https://developer.blender.org/D16935

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

M	source/blender/blenkernel/BKE_data_transfer.h
M	source/blender/blenkernel/intern/data_transfer.cc
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/makesrna/intern/rna_modifier.c

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

diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h
index 1b6c1dc4205..518b5146b18 100644
--- a/source/blender/blenkernel/BKE_data_transfer.h
+++ b/source/blender/blenkernel/BKE_data_transfer.h
@@ -92,8 +92,10 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(int dtdata_type);
        DT_TYPE_SHAPEKEY, \
        DT_TYPE_MPROPCOL_VERT, \
        DT_TYPE_MLOOPCOL_VERT, \
+       DT_TYPE_MPROPCOL_VERT | DT_TYPE_MLOOPCOL_VERT, \
        DT_TYPE_MPROPCOL_LOOP, \
        DT_TYPE_MLOOPCOL_LOOP, \
+       DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP, \
        DT_TYPE_UV)
 
 enum {
diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc
index 39d6cde31e7..740af7fa4db 100644
--- a/source/blender/blenkernel/intern/data_transfer.cc
+++ b/source/blender/blenkernel/intern/data_transfer.cc
@@ -237,9 +237,11 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
       return DT_MULTILAYER_INDEX_UV;
     case DT_TYPE_MPROPCOL_VERT:
     case DT_TYPE_MLOOPCOL_VERT:
+    case DT_TYPE_MPROPCOL_VERT | DT_TYPE_MLOOPCOL_VERT:
       return DT_MULTILAYER_INDEX_VCOL_VERT;
     case DT_TYPE_MPROPCOL_LOOP:
     case DT_TYPE_MLOOPCOL_LOOP:
+    case DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP:
       return DT_MULTILAYER_INDEX_VCOL_LOOP;
     default:
       return DT_MULTILAYER_INDEX_INVALID;
diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c
index 5f1af79c446..b5bea5b49f6 100644
--- a/source/blender/editors/object/object_data_transfer.c
+++ b/source/blender/editors/object/object_data_transfer.c
@@ -60,6 +60,11 @@ static const EnumPropertyItem DT_layer_items[] = {
     {DT_TYPE_SKIN, "SKIN", 0, "Skin Weight", "Transfer skin weights"},
 #endif
     {DT_TYPE_BWEIGHT_VERT, "BEVEL_WEIGHT_VERT", 0, "Bevel Weight", "Transfer bevel weights"},
+    {DT_TYPE_MPROPCOL_VERT | DT_TYPE_MLOOPCOL_VERT,
+     "COLOR_VERTEX",
+     0,
+     "Colors",
+     "Color Attributes"},
 
     RNA_ENUM_ITEM_HEADING(N_("Edge Data"), NULL),
     {DT_TYPE_SHARP_EDGE, "SHARP_EDGE", 0, "Sharp", "Transfer sharp mark"},
@@ -74,7 +79,11 @@ static const EnumPropertyItem DT_layer_items[] = {
 
     RNA_ENUM_ITEM_HEADING(N_("Face Corner Data"), NULL),
     {DT_TYPE_LNOR, "CUSTOM_NORMAL", 0, "Custom Normals", "Transfer custom normals"},
-    {DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP, "VCOL", 0, "Colors", "Color Attributes"},
+    {DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP,
+     "COLOR_CORNER",
+     0,
+     "Colors",
+     "Color Attributes"},
     {DT_TYPE_UV, "UV", 0, "UVs", "Transfer UV layers"},
 
     RNA_ENUM_ITEM_HEADING(N_("Face Data"), NULL),
@@ -93,7 +102,7 @@ static void dt_add_vcol_layers(CustomData *cdata,
                                int *r_totitem)
 {
   int types[2] = {CD_PROP_COLOR, CD_PROP_BYTE_COLOR};
-
+  int idx = 0;
   for (int i = 0; i < 2; i++) {
     eCustomDataType type = types[i];
 
@@ -106,9 +115,8 @@ static void dt_add_vcol_layers(CustomData *cdata,
     RNA_enum_item_add_separator(r_item, r_totitem);
 
     for (int j = 0; j < num_data; j++) {
-      EnumPropertyItem tmp_item;
-
-      tmp_item.value = j;
+      EnumPropertyItem tmp_item = {0};
+      tmp_item.value = idx++;
       tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(cdata, type, j);
       RNA_enum_item_add(r_item, r_totitem, &tmp_item);
     }
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 090ef1e5e28..0639ad29db4 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -6391,7 +6391,7 @@ static void rna_def_modifier_datatransfer(BlenderRNA *brna)
 #  endif
     {DT_TYPE_BWEIGHT_VERT, "BEVEL_WEIGHT_VERT", 0, "Bevel Weight", "Transfer bevel weights"},
     {DT_TYPE_MPROPCOL_VERT | DT_TYPE_MLOOPCOL_VERT,
-     "VCOL",
+     "COLOR_VERTEX",
      0,
      "Colors",
      "Transfer color attributes"},
@@ -6410,7 +6410,7 @@ static void rna_def_modifier_datatransfer(BlenderRNA *brna)
   static const EnumPropertyItem DT_layer_loop_items[] = {
       {DT_TYPE_LNOR, "CUSTOM_NORMAL", 0, "Custom Normals", "Transfer custom normals"},
       {DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP,
-       "VCOL",
+       "COLOR_CORNER",
        0,
        "Colors",
        "Transfer color attributes"},



More information about the Bf-blender-cvs mailing list