diff options
author | D. O <Likkez> | 2020-05-29 19:52:29 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-05-29 19:55:28 +0300 |
commit | 907cab45ff02ad1bba3cba98a3d6af69eff2bec0 (patch) | |
tree | 3c2275ebafdfdb882d4b127e1af593b044c7a707 | |
parent | c93a88413d1499d43265af9580e993bf8963726d (diff) |
Modifiers: add invert vgroup weights options to operands of Mix modifier.
Please note that vertices which are in a vgroup are not affected by this
option (which means that affected vertices from 'selection' modes remain
the same). Only the weights of selected vertices get inverted.
Reviewed By: mont29
Differential Revision: https://developer.blender.org/D7811
-rw-r--r-- | release/scripts/startup/bl_ui/properties_data_modifier.py | 8 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 10 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_weightvgmix.c | 24 |
4 files changed, 40 insertions, 4 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 71c6817abe9..d58dec211be 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -1449,7 +1449,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): col = split.column() col.label(text="Vertex Group A:") - col.prop_search(md, "vertex_group_a", ob, "vertex_groups", text="") + row = col.row(align=True) + row.prop_search(md, "vertex_group_a", ob, "vertex_groups", text="") + row.prop(md, "invert_vertex_group_a", text="", icon='ARROW_LEFTRIGHT') col.label(text="Default Weight A:") col.prop(md, "default_weight_a", text="") @@ -1458,7 +1460,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): col = split.column() col.label(text="Vertex Group B:") - col.prop_search(md, "vertex_group_b", ob, "vertex_groups", text="") + row = col.row(align=True) + row.prop_search(md, "vertex_group_b", ob, "vertex_groups", text="") + row.prop(md, "invert_vertex_group_b", text="", icon='ARROW_LEFTRIGHT') col.label(text="Default Weight B:") col.prop(md, "default_weight_b", text="") diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index e74f42f5c10..13972ae032d 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1505,6 +1505,8 @@ enum { enum { MOD_WVG_MIX_INVERT_VGROUP_MASK = (1 << 0), MOD_WVG_MIX_WEIGHTS_NORMALIZE = (1 << 1), + MOD_WVG_MIX_INVERT_VGROUP_A = (1 << 2), + MOD_WVG_MIX_INVERT_VGROUP_B = (1 << 3), }; typedef struct WeightVGProximityModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 031d37bcbdf..f5a437b7892 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -5012,6 +5012,16 @@ static void rna_def_modifier_weightvgmix(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_WeightVGMixModifier_defgrp_name_b_set"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "invert_vertex_group_a", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WVG_MIX_INVERT_VGROUP_A); + RNA_def_property_ui_text(prop, "Invert Weights A", "Invert the influence of vertex group A"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "invert_vertex_group_b", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WVG_MIX_INVERT_VGROUP_B); + RNA_def_property_ui_text(prop, "Invert Weights B", "Invert the influence of vertex group B"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "default_weight_a", PROP_FLOAT, PROP_FACTOR); RNA_def_property_range(prop, 0.0, 1.0f); RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1); diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 57156aec5ec..a71b1d9d0e8 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -225,6 +225,16 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * int i; const bool invert_vgroup_mask = (wmd->flag & MOD_WVG_MIX_INVERT_VGROUP_MASK) != 0; const bool do_normalize = (wmd->flag & MOD_WVG_MIX_WEIGHTS_NORMALIZE) != 0; + + /* + * Note that we only invert the weight values within provided vgroups, the selection based on + * which vertice is affected because it belongs or not to a group remains unchanged. + * In other words, vertices not belonging to a group won't be affected, even though their + * inverted 'virtual' weight would be 1.0f. + */ + const bool invert_vgroup_a = (wmd->flag & MOD_WVG_MIX_INVERT_VGROUP_A) != 0; + const bool invert_vgroup_b = (wmd->flag & MOD_WVG_MIX_INVERT_VGROUP_B) != 0; + /* Flags. */ #if 0 const bool do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview) != 0; @@ -379,8 +389,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Mix weights. */ for (i = 0; i < numIdx; i++) { float weight2; - org_w[i] = dw1[i] ? dw1[i]->weight : wmd->default_weight_a; - weight2 = dw2[i] ? dw2[i]->weight : wmd->default_weight_b; + if (invert_vgroup_a) { + org_w[i] = 1.0f - (dw1[i] ? dw1[i]->weight : wmd->default_weight_a); + } + else { + org_w[i] = dw1[i] ? dw1[i]->weight : wmd->default_weight_a; + } + if (invert_vgroup_b) { + weight2 = 1.0f - (dw2[i] ? dw2[i]->weight : wmd->default_weight_b); + } + else { + weight2 = dw2[i] ? dw2[i]->weight : wmd->default_weight_b; + } new_w[i] = mix_weight(org_w[i], weight2, wmd->mix_mode); } |