[Bf-blender-cvs] [f42d3caecdd] temp-sculpt-colors: temp-sculpt-colors: fix data transfer modifier

Joseph Eagar noreply at git.blender.org
Wed Mar 23 22:10:38 CET 2022


Commit: f42d3caecdde37bdc873a66fbdc5685bf7050fb1
Author: Joseph Eagar
Date:   Wed Mar 23 14:10:18 2022 -0700
Branches: temp-sculpt-colors
https://developer.blender.org/rBf42d3caecdde37bdc873a66fbdc5685bf7050fb1

temp-sculpt-colors: fix data transfer modifier

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

M	source/blender/blenkernel/BKE_data_transfer.h
M	source/blender/blenkernel/intern/data_transfer.c
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_datatransfer.c

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

diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h
index efffa0f362b..1b6c1dc4205 100644
--- a/source/blender/blenkernel/BKE_data_transfer.h
+++ b/source/blender/blenkernel/BKE_data_transfer.h
@@ -8,6 +8,7 @@
 #pragma once
 
 #include "BKE_customdata.h"
+#include "BLI_compiler_compat.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -32,20 +33,23 @@ enum {
   DT_TYPE_BWEIGHT_EDGE = 1 << 11,
   DT_TYPE_FREESTYLE_EDGE = 1 << 12,
 
-  DT_TYPE_VCOL = 1 << 16,
+  DT_TYPE_MPROPCOL_VERT = 1 << 16,
   DT_TYPE_LNOR = 1 << 17,
 
   DT_TYPE_UV = 1 << 24,
   DT_TYPE_SHARP_FACE = 1 << 25,
   DT_TYPE_FREESTYLE_FACE = 1 << 26,
-  DT_TYPE_PROPCOL = 1 << 27,
-#define DT_TYPE_MAX 28
+  DT_TYPE_MLOOPCOL_VERT = 1 << 27,
+  DT_TYPE_MPROPCOL_LOOP = 1 << 28,
+  DT_TYPE_MLOOPCOL_LOOP = 1 << 29,
+  DT_TYPE_VCOL_ALL = (1 << 16) | (1 << 27) | (1 << 28) | (1 << 29),
+#define DT_TYPE_MAX 30
 
   DT_TYPE_VERT_ALL = DT_TYPE_MDEFORMVERT | DT_TYPE_SHAPEKEY | DT_TYPE_SKIN | DT_TYPE_BWEIGHT_VERT |
-                     DT_TYPE_PROPCOL,
+                     DT_TYPE_MPROPCOL_VERT | DT_TYPE_MLOOPCOL_VERT,
   DT_TYPE_EDGE_ALL = DT_TYPE_SHARP_EDGE | DT_TYPE_SEAM | DT_TYPE_CREASE | DT_TYPE_BWEIGHT_EDGE |
                      DT_TYPE_FREESTYLE_EDGE,
-  DT_TYPE_LOOP_ALL = DT_TYPE_VCOL | DT_TYPE_LNOR | DT_TYPE_UV,
+  DT_TYPE_LOOP_ALL = DT_TYPE_LNOR | DT_TYPE_UV | DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP,
   DT_TYPE_POLY_ALL = DT_TYPE_UV | DT_TYPE_SHARP_FACE | DT_TYPE_FREESTYLE_FACE,
 };
 
@@ -69,7 +73,8 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(int dtdata_type);
        DT_TYPE_SHAPEKEY, \
        DT_TYPE_SKIN, \
        DT_TYPE_BWEIGHT_VERT, \
-       DT_TYPE_PROPCOL)
+       DT_TYPE_MLOOPCOL_VERT, \
+       DT_TYPE_MPROPCOL_VERT)
 #define DT_DATATYPE_IS_EDGE(_dt) \
   ELEM(_dt, \
        DT_TYPE_CREASE, \
@@ -77,19 +82,27 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(int dtdata_type);
        DT_TYPE_SEAM, \
        DT_TYPE_BWEIGHT_EDGE, \
        DT_TYPE_FREESTYLE_EDGE)
-#define DT_DATATYPE_IS_LOOP(_dt) ELEM(_dt, DT_TYPE_UV, DT_TYPE_VCOL, DT_TYPE_LNOR)
+#define DT_DATATYPE_IS_LOOP(_dt) \
+  ELEM(_dt, DT_TYPE_UV, DT_TYPE_LNOR, DT_TYPE_MLOOPCOL_LOOP, DT_TYPE_MPROPCOL_LOOP)
 #define DT_DATATYPE_IS_POLY(_dt) ELEM(_dt, DT_TYPE_UV, DT_TYPE_SHARP_FACE, DT_TYPE_FREESTYLE_FACE)
 
 #define DT_DATATYPE_IS_MULTILAYERS(_dt) \
-  ELEM(_dt, DT_TYPE_MDEFORMVERT, DT_TYPE_SHAPEKEY, DT_TYPE_VCOL, DT_TYPE_UV)
+  ELEM(_dt, \
+       DT_TYPE_MDEFORMVERT, \
+       DT_TYPE_SHAPEKEY, \
+       DT_TYPE_MPROPCOL_VERT, \
+       DT_TYPE_MLOOPCOL_VERT, \
+       DT_TYPE_MPROPCOL_LOOP, \
+       DT_TYPE_MLOOPCOL_LOOP, \
+       DT_TYPE_UV)
 
 enum {
   DT_MULTILAYER_INDEX_INVALID = -1,
   DT_MULTILAYER_INDEX_MDEFORMVERT = 0,
   DT_MULTILAYER_INDEX_SHAPEKEY = 1,
-  DT_MULTILAYER_INDEX_VCOL = 2,
+  DT_MULTILAYER_INDEX_VCOL_LOOP = 2,
   DT_MULTILAYER_INDEX_UV = 3,
-  DT_MULTILAYER_INDEX_PROPCOL = 4,
+  DT_MULTILAYER_INDEX_VCOL_VERT = 4,
   DT_MULTILAYER_INDEX_MAX = 5,
 };
 
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index b72cb6d4af7..ef002edb861 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -19,6 +19,7 @@
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_attribute.h"
 #include "BKE_customdata.h"
 #include "BKE_data_transfer.h"
 #include "BKE_deform.h"
@@ -48,6 +49,7 @@ void BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types,
     }
 
     cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
+
     if (!(cddata_type & CD_FAKE)) {
       if (DT_DATATYPE_IS_VERT(dtdata_type)) {
         r_data_masks->vmask |= 1LL << cddata_type;
@@ -129,8 +131,10 @@ bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types,
       case DT_TYPE_UV:
         ret = true;
         break;
-      case DT_TYPE_PROPCOL:
-      case DT_TYPE_VCOL:
+      case DT_TYPE_MPROPCOL_VERT:
+      case DT_TYPE_MLOOPCOL_VERT:
+      case DT_TYPE_MPROPCOL_LOOP:
+      case DT_TYPE_MLOOPCOL_LOOP:
         *r_advanced_mixing = true;
         *r_threshold = true;
         ret = true;
@@ -210,11 +214,13 @@ int BKE_object_data_transfer_dttype_to_cdtype(const int dtdata_type)
       return CD_FAKE_SHARP;
     case DT_TYPE_FREESTYLE_FACE:
       return CD_FREESTYLE_FACE;
-    case DT_TYPE_VCOL:
-      return CD_MLOOPCOL;
     case DT_TYPE_LNOR:
       return CD_FAKE_LNOR;
-    case DT_TYPE_PROPCOL:
+    case DT_TYPE_MLOOPCOL_VERT:
+    case DT_TYPE_MLOOPCOL_LOOP:
+      return CD_MLOOPCOL;
+    case DT_TYPE_MPROPCOL_VERT:
+    case DT_TYPE_MPROPCOL_LOOP:
       return CD_PROP_COLOR;
     default:
       BLI_assert(0);
@@ -231,10 +237,12 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
       return DT_MULTILAYER_INDEX_SHAPEKEY;
     case DT_TYPE_UV:
       return DT_MULTILAYER_INDEX_UV;
-    case DT_TYPE_VCOL:
-      return DT_MULTILAYER_INDEX_VCOL;
-    case DT_TYPE_PROPCOL:
-      return DT_MULTILAYER_INDEX_PROPCOL;
+    case DT_TYPE_MPROPCOL_VERT:
+    case DT_TYPE_MLOOPCOL_VERT:
+      return DT_MULTILAYER_INDEX_VCOL_VERT;
+    case DT_TYPE_MPROPCOL_LOOP:
+    case DT_TYPE_MLOOPCOL_LOOP:
+      return DT_MULTILAYER_INDEX_VCOL_LOOP;
     default:
       return DT_MULTILAYER_INDEX_INVALID;
   }
@@ -1232,8 +1240,8 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph,
     }
 
     cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
-
     fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(dtdata_type);
+
     if (fromto_idx != DT_MULTILAYER_INDEX_INVALID) {
       fromlayers = fromlayers_select[fromto_idx];
       tolayers = tolayers_select[fromto_idx];
diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c
index 3abf0d68eb3..7b847447607 100644
--- a/source/blender/editors/object/object_data_transfer.c
+++ b/source/blender/editors/object/object_data_transfer.c
@@ -72,7 +72,7 @@ static const EnumPropertyItem DT_layer_items[] = {
      "Transfer Freestyle edge mark"},
     {0, "", 0, "Face Corner Data", ""},
     {DT_TYPE_LNOR, "CUSTOM_NORMAL", 0, "Custom Normals", "Transfer custom normals"},
-    {DT_TYPE_VCOL, "VCOL", 0, "Vertex Colors", "Vertex (face corners) colors"},
+    {DT_TYPE_MPROPCOL_LOOP | DT_TYPE_MLOOPCOL_LOOP, "VCOL", 0, "Colors", "Color Attributes"},
     {DT_TYPE_UV, "UV", 0, "UVs", "Transfer UV layers"},
     {0, "", 0, "Face Data", ""},
     {DT_TYPE_SHARP_FACE, "SMOOTH", 0, "Smooth", "Transfer flat/smooth mark"},
@@ -84,6 +84,33 @@ static const EnumPropertyItem DT_layer_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+static void dt_add_vcol_layers(CustomData *cdata,
+                               CustomDataMask mask,
+                               EnumPropertyItem **r_item,
+                               int *r_totitem)
+{
+  int types[2] = {CD_PROP_COLOR, CD_MLOOPCOL};
+
+  for (int i = 0; i < 2; i++) {
+    CustomDataType type = types[i];
+
+    if (!(mask & CD_TYPE_AS_MASK(type))) {
+      continue;
+    }
+
+    int num_data = CustomData_number_of_layers(cdata, type);
+
+    RNA_enum_item_add_separator(r_item, r_totitem);
+
+    for (int j = 0; j < num_data; j++) {
+      EnumPropertyItem tmp_item;
+
+      tmp_item.value = j;
+      tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(cdata, type, j);
+      RNA_enum_item_add(r_item, r_totitem, &tmp_item);
+    }
+  }
+}
 /* NOTE: #rna_enum_dt_layers_select_src_items enum is from rna_modifier.c. */
 static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C,
                                                           PointerRNA *ptr,
@@ -159,23 +186,33 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C,
       RNA_enum_item_add(&item, &totitem, &tmp_item);
     }
   }
-  else if (data_type == DT_TYPE_VCOL) {
+  else if (data_type & DT_TYPE_VCOL_ALL) {
     Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
     Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
     Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src);
 
     CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH;
-    cddata_masks.lmask |= CD_MASK_MLOOPCOL;
-    Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks);
-    int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL);
+    if (data_type & (DT_TYPE_MPROPCOL_VERT)) {
+      cddata_masks.vmask |= CD_MASK_PROP_COLOR;
+    }
+    if (data_type & (DT_TYPE_MLOOPCOL_VERT)) {
+      cddata_masks.vmask |= CD_MASK_MLOOPCOL;
+    }
 
-    RNA_enum_item_add_separator(&item, &totitem);
+    if (data_type & (DT_TYPE_MPROPCOL_LOOP)) {
+      cddata_masks.lmask |= CD_MASK_PROP_COLOR;
+    }
+    if (data_type & (DT_TYPE_MLOOPCOL_LOOP)) {
+      cddata_masks.lmask |= CD_MASK_MLOOPCOL;
+    }
 
-    for (int i = 0; i < num_data; i++) {
-      tmp_item.value = i;
-      tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(
-          &me_eval->ldata, CD_MLOOPCOL, i);
-      RNA_enum_item_add(&item, &totitem, &tmp_item);
+    Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks);
+
+    if (data_type & (DT_TYPE_MLOOPCOL_VERT | DT_TYPE_MPROPCOL_VERT)) {
+      dt_add_vcol_layers(&me_eval->vdata, cddata_masks.vmask, &item, &totitem);
+    }
+    if (data_type & (DT_TYPE_MLOOPCOL_LOOP | DT_TYPE_MPROPCOL_LOOP)) {
+      dt_add_vcol_layers(&me_eval->ldata, cddata_masks.lmask, &item, &totitem);
     }
   }
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 807a615f7f9..470497aabce 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2103,9 +2103,9 @@ typedef struct DataTransferModifierData {
   char _pad1[4];
 
   /** DT_MULTILAYER_INDEX_MAX; See DT_FROMLAYERS_ enum in ED_object.h. */
-  int layers_select_src[4];
+  int layers_select_src[5];
   /** DT_MULTILAYER_INDEX_MAX; See DT_TOLAYERS_ enum in ED_object.h. */
-  int layers_select_dst[4];
+  int layers_select_dst[5];
 
   /** See C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list