Fix T103452: Active & default color attributes reset on modifier apply

I missed adding the "convert type/domain to mask" macros.
Also refactor slightly to split the matching attribute test to a
separate function to ease debugging and reduce duplication.
This commit is contained in:
Hans Goudey 2022-12-26 10:49:21 -05:00
parent 6b9825e6f7
commit 7911954b40
Notes: blender-bot 2023-02-13 23:39:48 +01:00
Referenced by issue #103452, Regression: Color attribute lost active status after applying modifiers
1 changed files with 24 additions and 14 deletions

View File

@ -858,25 +858,35 @@ static bool modifier_apply_shape(Main *bmain,
return true;
}
static bool meta_data_matches(const std::optional<blender::bke::AttributeMetaData> meta_data,
const eAttrDomainMask domains,
const eCustomDataMask types)
{
if (!meta_data) {
return false;
}
if (!(ATTR_DOMAIN_AS_MASK(meta_data->domain) & domains)) {
return false;
}
if (!(CD_TYPE_AS_MASK(meta_data->data_type) & types)) {
return false;
}
return true;
}
static void remove_invalid_attribute_strings(Mesh &mesh)
{
using namespace blender;
bke::AttributeAccessor attributes = mesh.attributes();
if (mesh.active_color_attribute) {
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(
mesh.active_color_attribute);
if (!meta_data || !(meta_data->domain & ATTR_DOMAIN_MASK_COLOR) ||
!(meta_data->data_type & CD_MASK_COLOR_ALL)) {
MEM_SAFE_FREE(mesh.active_color_attribute);
}
if (!meta_data_matches(attributes.lookup_meta_data(mesh.active_color_attribute),
ATTR_DOMAIN_MASK_COLOR,
CD_MASK_COLOR_ALL)) {
MEM_SAFE_FREE(mesh.active_color_attribute);
}
if (mesh.default_color_attribute) {
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(
mesh.default_color_attribute);
if (!meta_data || !(meta_data->domain & ATTR_DOMAIN_MASK_COLOR) ||
!(meta_data->data_type & CD_MASK_COLOR_ALL)) {
MEM_SAFE_FREE(mesh.default_color_attribute);
}
if (!meta_data_matches(attributes.lookup_meta_data(mesh.default_color_attribute),
ATTR_DOMAIN_MASK_COLOR,
CD_MASK_COLOR_ALL)) {
MEM_SAFE_FREE(mesh.default_color_attribute);
}
}