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
This commit is contained in:
Philipp Oeser 2023-01-05 16:05:51 +01:00
parent 3f627c38a2
commit 93d84e87b2
Notes: blender-bot 2024-03-22 15:57:27 +01:00
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #103400, Regression: Not possible to transfer Color Attributs Layer with "Transfer Mesh Data Layout"
4 changed files with 19 additions and 7 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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);
}

View File

@ -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"},