diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 21:42:55 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 21:42:55 +0300 |
commit | eae36be372a6b16ee3e76eff0485a47da4f3c230 (patch) | |
tree | d1ca2dc30951e31f1b91eed6a4edfdfb0824bf1f /source/blender/editors/object/object_data_transfer.c | |
parent | a3e122b9aec59fc303c2375a78183cfb8642c14f (diff) |
Refactor: Unify vertex and sculpt colors into new
color attribute system.
This commit removes sculpt colors from experimental
status and unifies it with vertex colors. It
introduces the concept of "color attributes", which
are any attributes that represents colors. Color
attributes can be represented with byte or floating-point
numbers and can be stored in either vertices or
face corners.
Color attributes share a common namespace
(so you can no longer have a floating-point
sculpt color attribute and a byte vertex color
attribute with the same name).
Note: this commit does not include vertex paint mode,
which is a separate patch, see:
https://developer.blender.org/D14179
Differential Revision: https://developer.blender.org/D12587
Ref D12587
Diffstat (limited to 'source/blender/editors/object/object_data_transfer.c')
-rw-r--r-- | source/blender/editors/object/object_data_transfer.c | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 6805c9144d6..3447ded5f68 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); } } |