[Bf-blender-cvs] [9fd834fbb34] master: Fix T103143: Cycles can lose default color attribute

Hans Goudey noreply at git.blender.org
Wed Dec 14 18:26:52 CET 2022


Commit: 9fd834fbb3468133b807b50808f3ccfbf55cc7f1
Author: Hans Goudey
Date:   Wed Dec 14 11:11:37 2022 -0600
Branches: master
https://developer.blender.org/rB9fd834fbb3468133b807b50808f3ccfbf55cc7f1

Fix T103143: Cycles can lose default color attribute

The `render_color_index` skips attributes with different types
and domains in order to give the proper order for the UI list.
That is a different than an index in the group of all attributes.

The most solid solution I could think of is exposing the name of
the default color attribute. It's "solid" because we always address
attributes by name internally. Doing something different is bound
to create problems. It's also aligned with the design in T98366 and
D15169.

Another option would be to change the way the "attribute index"
is incremented in Cycles. That would be a valid solution, but would
be more complex and annoying.

For consistency, I also exposed the name of the active color attribute
the same way, though it isn't necessary to fix this particular bug.

The properties aren't editable, that can come in 3.5 as part of D15169.

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

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

M	intern/cycles/blender/mesh.cpp
M	source/blender/makesrna/intern/rna_attribute.c

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

diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp
index 1887440bc67..736b80bacd6 100644
--- a/intern/cycles/blender/mesh.cpp
+++ b/intern/cycles/blender/mesh.cpp
@@ -367,13 +367,11 @@ static void attr_create_generic(Scene *scene,
 {
   AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
   static const ustring u_velocity("velocity");
-
-  int attribute_index = 0;
-  int render_color_index = b_mesh.attributes.render_color_index();
+  const ustring default_color_name{b_mesh.attributes.default_color_name().c_str()};
 
   for (BL::Attribute &b_attribute : b_mesh.attributes) {
     const ustring name{b_attribute.name().c_str()};
-    const bool is_render_color = (attribute_index++ == render_color_index);
+    const bool is_render_color = name == default_color_name;
 
     if (need_motion && name == u_velocity) {
       attr_create_motion(mesh, b_attribute, motion_scale);
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c
index c5ddc9a0204..d65159af28a 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -651,6 +651,49 @@ static void rna_AttributeGroup_render_color_index_range(
   *softmin = *min;
   *softmax = *max;
 }
+
+static void rna_AttributeGroup_default_color_name_get(PointerRNA *ptr, char *value)
+{
+  const ID *id = ptr->owner_id;
+  const CustomDataLayer *layer = BKE_id_attributes_render_color_get(id);
+  if (!layer) {
+    value[0] = '\0';
+    return;
+  }
+  BLI_strncpy(value, layer->name, MAX_CUSTOMDATA_LAYER_NAME);
+}
+
+static int rna_AttributeGroup_default_color_name_length(PointerRNA *ptr)
+{
+  const ID *id = ptr->owner_id;
+  const CustomDataLayer *layer = BKE_id_attributes_render_color_get(id);
+  if (!layer) {
+    return 0;
+  }
+  return strlen(layer->name);
+}
+
+static void rna_AttributeGroup_active_color_name_get(PointerRNA *ptr, char *value)
+{
+  const ID *id = ptr->owner_id;
+  const CustomDataLayer *layer = BKE_id_attributes_active_color_get(id);
+  if (!layer) {
+    value[0] = '\0';
+    return;
+  }
+  BLI_strncpy(value, layer->name, MAX_CUSTOMDATA_LAYER_NAME);
+}
+
+static int rna_AttributeGroup_active_color_name_length(PointerRNA *ptr)
+{
+  const ID *id = ptr->owner_id;
+  const CustomDataLayer *layer = BKE_id_attributes_active_color_get(id);
+  if (!layer) {
+    return 0;
+  }
+  return strlen(layer->name);
+}
+
 #else
 
 static void rna_def_attribute_float(BlenderRNA *brna)
@@ -1110,6 +1153,29 @@ static void rna_def_attribute_group(BlenderRNA *brna)
                              "rna_AttributeGroup_render_color_index_set",
                              "rna_AttributeGroup_render_color_index_range");
   RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active_color");
+
+  prop = RNA_def_property(srna, "default_color_name", PROP_STRING, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME);
+  RNA_def_property_string_funcs(prop,
+                                "rna_AttributeGroup_default_color_name_get",
+                                "rna_AttributeGroup_default_color_name_length",
+                                NULL);
+  RNA_def_property_ui_text(
+      prop,
+      "Default Color Attribute",
+      "The name of the default color attribute used as a fallback for rendering");
+
+  prop = RNA_def_property(srna, "active_color_name", PROP_STRING, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_string_maxlength(prop, MAX_CUSTOMDATA_LAYER_NAME);
+  RNA_def_property_string_funcs(prop,
+                                "rna_AttributeGroup_active_color_name_get",
+                                "rna_AttributeGroup_active_color_name_length",
+                                NULL);
+  RNA_def_property_ui_text(prop,
+                           "Active Color Attribute",
+                           "The name of the active color attribute for display and editing");
 }
 
 void rna_def_attributes_common(StructRNA *srna)



More information about the Bf-blender-cvs mailing list