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
This commit is contained in:
parent
eae1be548d
commit
9fd834fbb3
Notes:
blender-bot
2023-02-14 12:01:57 +01:00
Referenced by issue #103143, Regression: Cycles doesn't use default color attributes with face corner domains. Referenced by issue #102967, 3.4: Potential candidates for corrective releases
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue