Regression: Creating the first vertex color on a mesh does not always make it active/default #103761

Closed
opened 2023-01-09 15:37:16 +01:00 by Scurest · 16 comments
Contributor

System Information
Operating system: Linux

Blender Version
Broken: blender-3.5.0-alpha+master.1beaec46b8e3-linux.x86_64-release
Worked: blender-3.3.2-stable+v33.bd3a7b41e2b3-linux.x86_64-release

Originally caused by 6514bb05ea
Needs a similar fix as 101d04f41f

Short description of error
(Continuation of #103564)
Creating a color attribute on a mesh that didn't have color attributes should make the new attribute active and default (by which I mean that little camera next to the name, not sure what it's called). This works in 3.3.2 and it's also how UV maps work.

Exact steps for others to reproduce the error
I've found at least two more cases where this does happen.

  1. Using the old Python vertex_colors API. Create a new cube, run C.object.data.vertex_colors.new(name="Color") in the console, observe the new attribute is neither active nor default. Note that if you delete the attribute using the UI, and then run the same line again, the second time it does work correctly!

  2. Using importers. Import a .dae or .obj file with vertex colors and the color attribute will be active but not default.

  3. Using a Data Transfer modifier and using Generate Data Layers(or using the Transfer Mesh Data Layout operator) has the same issue: observe the new attribute is neither active nor default.

**System Information** Operating system: Linux **Blender Version** Broken: blender-3.5.0-alpha+master.1beaec46b8e3-linux.x86_64-release Worked: blender-3.3.2-stable+v33.bd3a7b41e2b3-linux.x86_64-release Originally caused by 6514bb05ea Needs a similar fix as 101d04f41f **Short description of error** (Continuation of #103564) Creating a color attribute on a mesh that didn't have color attributes should make the new attribute active and default (by which I mean that little camera next to the name, not sure what it's called). This works in 3.3.2 and it's also how UV maps work. **Exact steps for others to reproduce the error** I've found at least two more cases where this does happen. 1. Using the old Python `vertex_colors` API. Create a new cube, run `C.object.data.vertex_colors.new(name="Color")` in the console, observe the new attribute is neither active nor default. Note that if you delete the attribute using the UI, and then run the same line again, the second time it does work correctly! 2. Using importers. Import a .dae or .obj file with vertex colors and the color attribute will be active but not default. 3. Using a `Data Transfer` modifier and using `Generate Data Layers`(or using the `Transfer Mesh Data Layout` operator) has the same issue: observe the new attribute is neither active nor default.
Author
Contributor

Added subscriber: @scurest

Added subscriber: @scurest
Author
Contributor

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Philipp Oeser self-assigned this 2023-01-09 17:29:53 +01:00
Author
Contributor

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Author
Contributor

Bisecting says the first bad commit is 6514bb05 (D15169).
cc @HooglyBoogly

Bisecting says the first bad commit is 6514bb05 ([D15169](https://archive.blender.org/developer/D15169)). cc @HooglyBoogly
Philipp Oeser changed title from Creating the first color attribute on a mesh does not always make it active/default to Creating the first vertex color on a mesh does not always make it active/default 2023-01-10 08:38:34 +01:00
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Philipp Oeser changed title from Creating the first vertex color on a mesh does not always make it active/default to Regression: Creating the first vertex color on a mesh does not always make it active/default 2023-01-10 09:21:38 +01:00
Member

Added subscriber: @Wahooney

Added subscriber: @Wahooney
Member

I will add to this the following (will update the report description as well):

In #103799#1472566, @lichtwerk wrote:

It seems that when you hit Generate Data Layers it does work correctly behind the scenes, it just doesn't select the newly created color layer even if it's the only one. Which is more of a rough edge than an actual bug but still something that should be looked at I think.

That is an issue caused by 6514bb05ea, similar to #103761 / #103564, would probably be good to have this as a separate report, I can check on this as well

I have the fix for case 1 and 2 the newly spotted issue needs a bit more work...

CC @Wahooney

I will add to this the following (will update the report description as well): > In #103799#1472566, @lichtwerk wrote: >> It seems that when you hit Generate Data Layers it does work correctly behind the scenes, it just doesn't select the newly created color layer even if it's the only one. Which is more of a rough edge than an actual bug but still something that should be looked at I think. > > That is an issue caused by 6514bb05ea, similar to #103761 / #103564, would probably be good to have this as a separate report, I can check on this as well I have the fix for case `1` and `2` the newly spotted issue needs a bit more work... CC @Wahooney
Member

This isn't exactly the same but definitely related: when entering Vertex Paint mode on a mesh with no color attributes and you start painting, it auto-creates a new attribute and calls it Attribute, where creating a new attribute in the Object Data Panel defaults to naming it Color. It's something I ran into when making the example for #103799 (Data Transfer doesn't work in some situations (geometry nodes modifier preceeding the Data Transfer modifier)). Consistency there would be preferable.

This isn't exactly the same but definitely related: when entering Vertex Paint mode on a mesh with no color attributes and you start painting, it auto-creates a new attribute and calls it Attribute, where creating a new attribute in the Object Data Panel defaults to naming it Color. It's something I ran into when making the example for #103799 (Data Transfer doesn't work in some situations (geometry nodes modifier preceeding the Data Transfer modifier)). Consistency there would be preferable.
Member

Added subscriber: @JulienKaspar

Added subscriber: @JulienKaspar
Member

In #103761#1472639, @Wahooney wrote:
This isn't exactly the same but definitely related: when entering Vertex Paint mode on a mesh with no color attributes and you start painting, it auto-creates a new attribute and calls it Attribute, where creating a new attribute in the Object Data Panel defaults to naming it Color. It's something I ran into when making the example for #103799 (Data Transfer doesn't work in some situations (geometry nodes modifier preceeding the Data Transfer modifier)). Consistency there would be preferable.

This changed in 6514bb05ea which now bypasses LayerTypeInfo default name (which is still "Col") and uses what BKE_id_attribute_calc_unique_name gives when no name is provided (which is "Attribute" by default)
Sculpt mode painting does its own thing BKE_sculpt_color_layer_create_if_needed (calls it "Color", hardcoded)
Adding the attribute via GEOMETRY_OT_color_attribute_add (in the UI list that is) also hardcodes this to "Color"
(then there is also adding a canvas in sculptmode, which will call it e.g. "Material Base Color" -- this makes sense though)
Same is true for UVMaps btw.

@HooglyBoogly , @JulienKaspar : I think we should settle on one consistent name, no? Afaict, we can still rely on LayerTypeInfo defaultname. (changing this to "Color" might be good then)
Another possibility would be to put this into AttributeMetaData?
NOTE: this should be its own report though I guess.

Here is a patch that would get the default layer names from LayerTypeInfo
P3437: default layer names from LayerTypeInfo (#103761)

From: Philipp Oeser <philipp@blender.org>, Thu Jan 12 12:19:58 2023 +0100 (45 seconds ago)
Committer: Philipp Oeser <philipp@blender.org>, Thu Jan 12 12:19:58 2023 +0100 (45 seconds ago)
Follows: v3.3.0

Attributes: rely on LayerTypeInfo for a default name


diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 7c01a9205fc..2e9f188b09e 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -129,7 +129,10 @@ struct CustomDataLayer *BKE_id_attributes_default_color_get(const struct ID *id)
 void BKE_id_attributes_default_color_set(struct ID *id, const char *name);
 struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name);
 
-bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char *outname);
+bool BKE_id_attribute_calc_unique_name(struct ID *id,
+                                       eCustomDataType data_type,
+                                       const char *name,
+                                       char *outname);
 
 const char *BKE_uv_map_vert_select_name_get(const char *uv_map_name, char *buffer);
 const char *BKE_uv_map_edge_select_name_get(const char *uv_map_name, char *buffer);
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index b97ac9cc9b9..2facfaa77a0 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -539,6 +539,10 @@ int CustomData_sizeof(int type);
  * Get the name of a layer type.
  */
 const char *CustomData_layertype_name(int type);
+/**
+ * Get the default name of a layer type.
+ */
+const char *CustomData_layertype_defaultname(int type);
 /**
  * Can only ever be one of these.
  */
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index 4b090e710f5..3fbacc31299 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -190,7 +190,8 @@ bool BKE_id_attribute_rename(ID *id,
   }
 
   char result_name[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(id, new_name, result_name);
+  BKE_id_attribute_calc_unique_name(
+      id, static_cast<eCustomDataType>(layer->type), new_name, result_name);
 
   if (layer->type == CD_PROP_FLOAT2 && GS(id->name) == ID_ME) {
     /* Rename UV sub-attributes. */
@@ -251,15 +252,17 @@ static bool unique_name_cb(void *arg, const char *name)
   return false;
 }
 
-bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
+bool BKE_id_attribute_calc_unique_name(ID *id,
+                                       eCustomDataType data_type,
+                                       const char *name,
+                                       char *outname)
 {
   AttrUniqueData data{id};
   const int maxlength = CustomData_name_max_length_calc(name);
 
-  /* Set default name if none specified.
-   * NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */
+  /* Set default name if none specified. */
   if (!name || name- [x] == '\0') {
-    BLI_strncpy(outname, IFACE_("Attribute"), maxlength);
+    BLI_strncpy(outname, CustomData_layertype_defaultname(data_type), maxlength);
   }
   else {
     BLI_strncpy_utf8(outname, name, maxlength);
@@ -282,7 +285,7 @@ CustomDataLayer *BKE_id_attribute_new(
   }
 
   char uniquename[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(id, name, uniquename);
+  BKE_id_attribute_calc_unique_name(id, static_cast<eCustomDataType>(type), name, uniquename);
 
   if (GS(id->name) == ID_ME) {
     Mesh *mesh = reinterpret_cast<Mesh *>(id);
@@ -325,8 +328,6 @@ static void bke_id_attribute_copy_if_exists(ID *id, const char *srcname, const c
 CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList *reports)
 {
   using namespace blender::bke;
-  char uniquename[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(id, name, uniquename);
 
   if (GS(id->name) == ID_ME) {
     Mesh *mesh = reinterpret_cast<Mesh *>(id);
@@ -349,6 +350,10 @@ CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList
   }
 
   const eCustomDataType type = cpp_type_to_custom_data_type(src.varray.type());
+
+  char uniquename[MAX_CUSTOMDATA_LAYER_NAME];
+  BKE_id_attribute_calc_unique_name(id, type, name, uniquename);
+
   attributes->add(uniquename, src.domain, type, AttributeInitVArray(src.varray));
 
   if (GS(id->name) == ID_ME && type == CD_PROP_FLOAT2) {
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 1d970d35148..b8e2ef1a4d2 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -1622,7 +1622,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
     /* 6: CD_MCOL */
     /* 4 MCol structs per face */
     {sizeof(MCol- [x]),  "MCol",         4,
-     N_("Col"),        nullptr,        nullptr,
+     N_("Color"),      nullptr,        nullptr,
      layerInterp_mcol, layerSwap_mcol, layerDefault_mcol,
      nullptr,          nullptr,        nullptr,
      nullptr,          nullptr,        nullptr,
@@ -1703,7 +1703,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
     {sizeof(MLoopCol),
      "MLoopCol",
      1,
-     N_("Col"),
+     N_("Color"),
      nullptr,
      nullptr,
      layerInterp_mloopcol,
@@ -4247,6 +4247,16 @@ const char *CustomData_layertype_name(int type)
   return layerType_getName(type);
 }
 
+const char *CustomData_layertype_defaultname(int type)
+{
+  const LayerTypeInfo *typeInfo = layerType_getInfo(type);
+  if (typeInfo->defaultname) {
+    return DATA_(typeInfo->defaultname);
+  }
+
+  return DATA_("Attribute");
+}
+
 bool CustomData_layertype_is_singleton(int type)
 {
   const LayerTypeInfo *typeInfo = layerType_getInfo(type);
diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index 75d9f0d5b89..b63bedcb178 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -1924,7 +1924,7 @@ void BKE_sculpt_color_layer_create_if_needed(Object *object)
   }
 
   char unique_name[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(&orig_me->id, "Color", unique_name);
+  BKE_id_attribute_calc_unique_name(&orig_me->id, CD_PROP_COLOR, "", unique_name);
   if (!orig_me->attributes_for_write().add(
           unique_name, ATTR_DOMAIN_POINT, CD_PROP_COLOR, AttributeInitDefaultValue())) {
     return;
diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc
index 516d67220cb..13f4edc3dea 100644
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@ -360,8 +360,12 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot)
   /* properties */
   PropertyRNA *prop;
 
-  prop = RNA_def_string(
-      ot->srna, "name", "Color", MAX_NAME, "Name", "Name of new color attribute");
+  prop = RNA_def_string(ot->srna,
+                        "name",
+                        CustomData_layertype_defaultname(CD_PROP_COLOR),
+                        MAX_NAME,
+                        "Name",
+                        "Name of new color attribute");
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
   prop = RNA_def_enum(ot->srna,
@@ -380,8 +384,16 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot)
 
   static float default_color- [x] = {0.0f, 0.0f, 0.0f, 1.0f};
 
-  prop = RNA_def_float_color(
-      ot->srna, "color", 4, nullptr, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
+  prop = RNA_def_float_color(ot->srna,
+                             "color",
+                             4,
+                             nullptr,
+                             0.0f,
+                             FLT_MAX,
+                             CustomData_layertype_defaultname(CD_PROP_COLOR),
+                             "Default fill color",
+                             0.0f,
+                             1.0f);
   RNA_def_property_subtype(prop, PROP_COLOR);
   RNA_def_property_float_array_default(prop, default_color);
 }
@@ -423,7 +435,12 @@ void GEOMETRY_OT_color_attribute_render_set(wmOperatorType *ot)
   /* properties */
   PropertyRNA *prop;
 
-  prop = RNA_def_string(ot->srna, "name", "Color", MAX_NAME, "Name", "Name of color attribute");
+  prop = RNA_def_string(ot->srna,
+                        "name",
+                        CustomData_layertype_defaultname(CD_PROP_COLOR),
+                        MAX_NAME,
+                        "Name",
+                        "Name of color attribute");
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 8b3ecf6f59f..5df454e5835 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -261,12 +261,8 @@ int ED_mesh_uv_add(
   BMEditMesh *em;
   int layernum_dst;
 
-  if (!name) {
-    name = DATA_("UVMap");
-  }
-
   char unique_name[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(&me->id, name, unique_name);
+  BKE_id_attribute_calc_unique_name(&me->id, CD_MLOOPUV, name, unique_name);
   bool is_init = false;
 
   if (me->edit_mesh) {
@@ -510,7 +506,7 @@ bool ED_mesh_color_ensure(Mesh *me, const char *name)
   }
 
   char unique_name[MAX_CUSTOMDATA_LAYER_NAME];
-  BKE_id_attribute_calc_unique_name(&me->id, name, unique_name);
+  BKE_id_attribute_calc_unique_name(&me->id, CD_PROP_BYTE_COLOR, name, unique_name);
   if (!me->attributes_for_write().add(
           unique_name, ATTR_DOMAIN_CORNER, CD_PROP_BYTE_COLOR, bke::AttributeInitDefaultValue())) {
     return false;
@@ -537,11 +533,6 @@ static bool layers_poll(bContext *C)
 
 int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool do_init, ReportList *reports)
 {
-  /* If no name is supplied, provide a backwards compatible default. */
-  if (!name) {
-    name = "Color";
-  }
-
   if (const CustomDataLayer *layer = BKE_id_attribute_find(
           &me->id, me->active_color_attribute, CD_PROP_COLOR, ATTR_DOMAIN_POINT)) {
     int dummy;
> In #103761#1472639, @Wahooney wrote: > This isn't exactly the same but definitely related: when entering Vertex Paint mode on a mesh with no color attributes and you start painting, it auto-creates a new attribute and calls it Attribute, where creating a new attribute in the Object Data Panel defaults to naming it Color. It's something I ran into when making the example for #103799 (Data Transfer doesn't work in some situations (geometry nodes modifier preceeding the Data Transfer modifier)). Consistency there would be preferable. This changed in 6514bb05ea which now bypasses `LayerTypeInfo` default name (which is still "Col") and uses what `BKE_id_attribute_calc_unique_name` gives when no name is provided (which is "Attribute" by default) Sculpt mode painting does its own thing `BKE_sculpt_color_layer_create_if_needed` (calls it "Color", hardcoded) Adding the attribute via `GEOMETRY_OT_color_attribute_add` (in the UI list that is) also hardcodes this to "Color" (then there is also adding a canvas in sculptmode, which will call it e.g. "Material Base Color" -- this makes sense though) Same is true for UVMaps btw. @HooglyBoogly , @JulienKaspar : I think we should settle on one consistent name, no? Afaict, we can still rely on `LayerTypeInfo` defaultname. (changing this to "Color" might be good then) Another possibility would be to put this into `AttributeMetaData`? NOTE: this should be its own report though I guess. Here is a patch that would get the default layer names from `LayerTypeInfo` [P3437: default layer names from LayerTypeInfo (#103761)](https://archive.blender.org/developer/P3437.txt) ``` From: Philipp Oeser <philipp@blender.org>, Thu Jan 12 12:19:58 2023 +0100 (45 seconds ago) Committer: Philipp Oeser <philipp@blender.org>, Thu Jan 12 12:19:58 2023 +0100 (45 seconds ago) Follows: v3.3.0 Attributes: rely on LayerTypeInfo for a default name diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index 7c01a9205fc..2e9f188b09e 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -129,7 +129,10 @@ struct CustomDataLayer *BKE_id_attributes_default_color_get(const struct ID *id) void BKE_id_attributes_default_color_set(struct ID *id, const char *name); struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name); -bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char *outname); +bool BKE_id_attribute_calc_unique_name(struct ID *id, + eCustomDataType data_type, + const char *name, + char *outname); const char *BKE_uv_map_vert_select_name_get(const char *uv_map_name, char *buffer); const char *BKE_uv_map_edge_select_name_get(const char *uv_map_name, char *buffer); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index b97ac9cc9b9..2facfaa77a0 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -539,6 +539,10 @@ int CustomData_sizeof(int type); * Get the name of a layer type. */ const char *CustomData_layertype_name(int type); +/** + * Get the default name of a layer type. + */ +const char *CustomData_layertype_defaultname(int type); /** * Can only ever be one of these. */ diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 4b090e710f5..3fbacc31299 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -190,7 +190,8 @@ bool BKE_id_attribute_rename(ID *id, } char result_name[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(id, new_name, result_name); + BKE_id_attribute_calc_unique_name( + id, static_cast<eCustomDataType>(layer->type), new_name, result_name); if (layer->type == CD_PROP_FLOAT2 && GS(id->name) == ID_ME) { /* Rename UV sub-attributes. */ @@ -251,15 +252,17 @@ static bool unique_name_cb(void *arg, const char *name) return false; } -bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname) +bool BKE_id_attribute_calc_unique_name(ID *id, + eCustomDataType data_type, + const char *name, + char *outname) { AttrUniqueData data{id}; const int maxlength = CustomData_name_max_length_calc(name); - /* Set default name if none specified. - * NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */ + /* Set default name if none specified. */ if (!name || name- [x] == '\0') { - BLI_strncpy(outname, IFACE_("Attribute"), maxlength); + BLI_strncpy(outname, CustomData_layertype_defaultname(data_type), maxlength); } else { BLI_strncpy_utf8(outname, name, maxlength); @@ -282,7 +285,7 @@ CustomDataLayer *BKE_id_attribute_new( } char uniquename[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(id, name, uniquename); + BKE_id_attribute_calc_unique_name(id, static_cast<eCustomDataType>(type), name, uniquename); if (GS(id->name) == ID_ME) { Mesh *mesh = reinterpret_cast<Mesh *>(id); @@ -325,8 +328,6 @@ static void bke_id_attribute_copy_if_exists(ID *id, const char *srcname, const c CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList *reports) { using namespace blender::bke; - char uniquename[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(id, name, uniquename); if (GS(id->name) == ID_ME) { Mesh *mesh = reinterpret_cast<Mesh *>(id); @@ -349,6 +350,10 @@ CustomDataLayer *BKE_id_attribute_duplicate(ID *id, const char *name, ReportList } const eCustomDataType type = cpp_type_to_custom_data_type(src.varray.type()); + + char uniquename[MAX_CUSTOMDATA_LAYER_NAME]; + BKE_id_attribute_calc_unique_name(id, type, name, uniquename); + attributes->add(uniquename, src.domain, type, AttributeInitVArray(src.varray)); if (GS(id->name) == ID_ME && type == CD_PROP_FLOAT2) { diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 1d970d35148..b8e2ef1a4d2 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -1622,7 +1622,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { /* 6: CD_MCOL */ /* 4 MCol structs per face */ {sizeof(MCol- [x]), "MCol", 4, - N_("Col"), nullptr, nullptr, + N_("Color"), nullptr, nullptr, layerInterp_mcol, layerSwap_mcol, layerDefault_mcol, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, @@ -1703,7 +1703,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(MLoopCol), "MLoopCol", 1, - N_("Col"), + N_("Color"), nullptr, nullptr, layerInterp_mloopcol, @@ -4247,6 +4247,16 @@ const char *CustomData_layertype_name(int type) return layerType_getName(type); } +const char *CustomData_layertype_defaultname(int type) +{ + const LayerTypeInfo *typeInfo = layerType_getInfo(type); + if (typeInfo->defaultname) { + return DATA_(typeInfo->defaultname); + } + + return DATA_("Attribute"); +} + bool CustomData_layertype_is_singleton(int type) { const LayerTypeInfo *typeInfo = layerType_getInfo(type); diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 75d9f0d5b89..b63bedcb178 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -1924,7 +1924,7 @@ void BKE_sculpt_color_layer_create_if_needed(Object *object) } char unique_name[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(&orig_me->id, "Color", unique_name); + BKE_id_attribute_calc_unique_name(&orig_me->id, CD_PROP_COLOR, "", unique_name); if (!orig_me->attributes_for_write().add( unique_name, ATTR_DOMAIN_POINT, CD_PROP_COLOR, AttributeInitDefaultValue())) { return; diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 516d67220cb..13f4edc3dea 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -360,8 +360,12 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot) /* properties */ PropertyRNA *prop; - prop = RNA_def_string( - ot->srna, "name", "Color", MAX_NAME, "Name", "Name of new color attribute"); + prop = RNA_def_string(ot->srna, + "name", + CustomData_layertype_defaultname(CD_PROP_COLOR), + MAX_NAME, + "Name", + "Name of new color attribute"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_enum(ot->srna, @@ -380,8 +384,16 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot) static float default_color- [x] = {0.0f, 0.0f, 0.0f, 1.0f}; - prop = RNA_def_float_color( - ot->srna, "color", 4, nullptr, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f); + prop = RNA_def_float_color(ot->srna, + "color", + 4, + nullptr, + 0.0f, + FLT_MAX, + CustomData_layertype_defaultname(CD_PROP_COLOR), + "Default fill color", + 0.0f, + 1.0f); RNA_def_property_subtype(prop, PROP_COLOR); RNA_def_property_float_array_default(prop, default_color); } @@ -423,7 +435,12 @@ void GEOMETRY_OT_color_attribute_render_set(wmOperatorType *ot) /* properties */ PropertyRNA *prop; - prop = RNA_def_string(ot->srna, "name", "Color", MAX_NAME, "Name", "Name of color attribute"); + prop = RNA_def_string(ot->srna, + "name", + CustomData_layertype_defaultname(CD_PROP_COLOR), + MAX_NAME, + "Name", + "Name of color attribute"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); } diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc index 8b3ecf6f59f..5df454e5835 100644 --- a/source/blender/editors/mesh/mesh_data.cc +++ b/source/blender/editors/mesh/mesh_data.cc @@ -261,12 +261,8 @@ int ED_mesh_uv_add( BMEditMesh *em; int layernum_dst; - if (!name) { - name = DATA_("UVMap"); - } - char unique_name[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(&me->id, name, unique_name); + BKE_id_attribute_calc_unique_name(&me->id, CD_MLOOPUV, name, unique_name); bool is_init = false; if (me->edit_mesh) { @@ -510,7 +506,7 @@ bool ED_mesh_color_ensure(Mesh *me, const char *name) } char unique_name[MAX_CUSTOMDATA_LAYER_NAME]; - BKE_id_attribute_calc_unique_name(&me->id, name, unique_name); + BKE_id_attribute_calc_unique_name(&me->id, CD_PROP_BYTE_COLOR, name, unique_name); if (!me->attributes_for_write().add( unique_name, ATTR_DOMAIN_CORNER, CD_PROP_BYTE_COLOR, bke::AttributeInitDefaultValue())) { return false; @@ -537,11 +533,6 @@ static bool layers_poll(bContext *C) int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool do_init, ReportList *reports) { - /* If no name is supplied, provide a backwards compatible default. */ - if (!name) { - name = "Color"; - } - if (const CustomDataLayer *layer = BKE_id_attribute_find( &me->id, me->active_color_attribute, CD_PROP_COLOR, ATTR_DOMAIN_POINT)) { int dummy; ```
Author
Contributor

Wouldn't it be better to move it into the attribute creation logic instead? BKE_id_attribute_new, as mentioned in D16898, appears like it would have fixed both vertex_color.add and the OBJ importer (but not Collada I think).

Wouldn't it be better to move it into the attribute creation logic instead? `BKE_id_attribute_new`, as mentioned in [D16898](https://archive.blender.org/developer/D16898), appears like it would have fixed both `vertex_color.add` and the OBJ importer (but not Collada I think).
Member

we could move it there, but like you said, still does not garuantee everything is right... No strong opinion here, might also be better to drop the comment in D16799, might be forgotten otherwise

we could move it there, but like you said, still does not garuantee everything is right... No strong opinion here, might also be better to drop the comment in [D16799](https://archive.blender.org/developer/D16799), might be forgotten otherwise
Author
Contributor

Assume you meant D16977?

Assume you meant [D16977](https://archive.blender.org/developer/D16977)?
Member

Yeah, sorry, typing this on a phone with fat fingers :)

Yeah, sorry, typing this on a phone with fat fingers :)
Author
Contributor

Note that removing a color attribute with eg mesh.color_attributes.remove can also leave the mesh in a state with no active/default color attribute. This is also a regression from 3.3.2.

Note that removing a color attribute with eg `mesh.color_attributes.remove` can also leave the mesh in a state with no active/default color attribute. This is also a regression from 3.3.2.
Member

In #103761#1476197, @scurest wrote:
Note that removing a color attribute with eg mesh.color_attributes.remove can also leave the mesh in a state with no active/default color attribute. This is also a regression from 3.3.2.

thx noting, will add that as well

> In #103761#1476197, @scurest wrote: > Note that removing a color attribute with eg `mesh.color_attributes.remove` can also leave the mesh in a state with no active/default color attribute. This is also a regression from 3.3.2. thx noting, will add that as well
Philipp Oeser removed the
Interest
Sculpt, Paint & Texture
label 2023-02-10 09:10:54 +01:00
Brecht Van Lommel added this to the 3.5 milestone 2023-02-15 10:26:16 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-02-22 15:33:42 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#103761
No description provided.