Fix T55470: Add option to not fix polygons' winding to Edit Normals modifier.

this is actually adding option to add buggy behavior, but.. NPR often
expects buggy behaviors, and its one of the main targets for normal editing.
So think it's reasonable to add that option (disabled by default of
course).

Note that am not really happy with UI, but:
* Not sure where to put it, it's kind of own self-contained area option.
* Don't to make it too much visible, using this should be the exception!
This commit is contained in:
Bastien Montagne 2018-06-14 11:41:12 +02:00
parent 4d58fac1b4
commit 0eb3246713
Notes: blender-bot 2023-02-14 05:44:18 +01:00
Referenced by issue #55470, Normal Edit modifier incorrectly causes faces to become 'back faces'
4 changed files with 17 additions and 3 deletions

View File

@ -1509,6 +1509,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
def NORMAL_EDIT(self, layout, ob, md):
has_vgroup = bool(md.vertex_group)
do_polynors_fix = not md.no_polynors_fix
needs_object_offset = (((md.mode == 'RADIAL') and not md.target) or
((md.mode == 'DIRECTIONAL') and md.use_direction_parallel))
@ -1538,7 +1539,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
sub = row.row(align=True)
sub.active = has_vgroup
sub.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
subcol.prop(md, "mix_limit")
row = subcol.row(align=True)
row.prop(md, "mix_limit")
row.prop(md, "no_polynors_fix", text="", icon='UNLOCKED' if do_polynors_fix else 'LOCKED')
def CORRECTIVE_SMOOTH(self, layout, ob, md):
is_bind = md.is_bind

View File

@ -1559,6 +1559,7 @@ enum {
enum {
MOD_NORMALEDIT_INVERT_VGROUP = (1 << 0),
MOD_NORMALEDIT_USE_DIRECTION_PARALLEL = (1 << 1),
MOD_NORMALEDIT_NO_POLYNORS_FIX = (1 << 2),
};
/* NormalEditModifierData.mix_mode */

View File

@ -4847,6 +4847,14 @@ static void rna_def_modifier_normaledit(BlenderRNA *brna)
RNA_def_property_subtype(prop, PROP_ANGLE);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "no_polynors_fix", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_NORMALEDIT_NO_POLYNORS_FIX);
RNA_def_property_boolean_default(prop, false);
RNA_def_property_ui_text(prop, "Lock Polygon Normals",
"Do not flip polygons when their normals are not consistent "
"with their newly computed custom vertex normals");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "defgrp_name");
RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group name for selecting/weighting the affected areas");

View File

@ -195,6 +195,7 @@ static void normalEditModifier_do_radial(
MVert *mvert, const int num_verts, MEdge *medge, const int num_edges,
MLoop *mloop, const int num_loops, MPoly *mpoly, const int num_polys)
{
const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
int i;
float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
@ -272,7 +273,7 @@ static void normalEditModifier_do_radial(
mix_limit, mix_mode, num_verts, mloop, loopnors, nos, num_loops);
}
if (polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
if (do_polynors_fix && polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
/* We need to recompute vertex normals! */
dm->calcNormals(dm);
@ -294,6 +295,7 @@ static void normalEditModifier_do_directional(
MVert *mvert, const int num_verts, MEdge *medge, const int num_edges,
MLoop *mloop, const int num_loops, MPoly *mpoly, const int num_polys)
{
const bool do_polynors_fix = (enmd->flag & MOD_NORMALEDIT_NO_POLYNORS_FIX) == 0;
const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;
float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
@ -351,7 +353,7 @@ static void normalEditModifier_do_directional(
mix_limit, mix_mode, num_verts, mloop, loopnors, nos, num_loops);
}
if (polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
if (do_polynors_fix && polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
}