Fix #119520: Auto smooth modifier added unnecessarily with bevel

If the bevel "Harden Normals" option is on, custom normals will be
generated. In that case, the automatic sharp edge tagging based on the
angle shouldn't run. This PR extends the earlier fix to #116395 to
handle this case and also extends the check to not just check the last
modifier, which doesn't work in this test file which has a collision
modifier at the end. That makes sense anyway, since what we really care
about is whether the evaluated mesh has custom normals or not.

Pull Request: https://projects.blender.org/blender/blender/pulls/119638
This commit is contained in:
Hans Goudey
2024-03-18 21:43:22 +01:00
committed by Hans Goudey
parent 5bfe6ad8f8
commit 51cdf665ab

View File

@@ -2418,6 +2418,12 @@ void BKE_main_mesh_legacy_convert_auto_smooth(Main &bmain)
if (ELEM(md->type, eModifierType_WeightedNormal, eModifierType_NormalEdit)) {
has_custom_normals = true;
}
if (md->type == eModifierType_Bevel) {
BevelModifierData *bmd = reinterpret_cast<BevelModifierData *>(md);
if (bmd->flags & MOD_BEVEL_HARDEN_NORMALS) {
has_custom_normals = true;
}
}
if (md->type == eModifierType_WeightedNormal) {
WeightedNormalModifierData *nmd = reinterpret_cast<WeightedNormalModifierData *>(md);
if ((nmd->flag & MOD_WEIGHTEDNORMAL_KEEP_SHARP) != 0) {
@@ -2430,13 +2436,11 @@ void BKE_main_mesh_legacy_convert_auto_smooth(Main &bmain)
/* Some modifiers always generate custom normals which disabled sharp edge tagging, making
* adding a modifier at the end unnecessary. Conceptually this is similar to checking if the
* evaluated mesh had custom normals. */
ModifierData *last_md = static_cast<ModifierData *>(object->modifiers.last);
if (last_md) {
if (ELEM(last_md->type, eModifierType_WeightedNormal, eModifierType_NormalEdit)) {
continue;
}
if (has_custom_normals) {
continue;
}
ModifierData *last_md = static_cast<ModifierData *>(object->modifiers.last);
ModifierData *new_md = create_auto_smooth_modifier(*object, add_node_group, angle);
if (last_md && last_md->type == eModifierType_Subsurf && has_custom_normals &&
(reinterpret_cast<SubsurfModifierData *>(last_md)->flags &