diff options
7 files changed, 62 insertions, 38 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py index 670f937e52a..e72e826ce23 100644 --- a/release/scripts/startup/bl_ui/properties_data_modifier.py +++ b/release/scripts/startup/bl_ui/properties_data_modifier.py @@ -1410,7 +1410,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel): col.prop(md, "max_dist") layout.separator() - layout.prop(md, "falloff_type") + row = layout.row(align=True) + row.prop(md, "falloff_type") + row.prop(md, "invert_falloff", text="", icon='ARROW_LEFTRIGHT') # Common mask options layout.separator() diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index b0b003d4b29..5213dba6c79 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -1542,6 +1542,7 @@ enum { /* Use nearest faces of target obj, in MOD_WVG_PROXIMITY_GEOMETRY mode. */ MOD_WVG_PROXIMITY_GEOM_FACES = (1 << 2), MOD_WVG_PROXIMITY_INVERT_VGROUP_MASK = (1 << 3), + MOD_WVG_PROXIMITY_INVERT_FALLOFF = (1 << 4), }; /* Defines common to all WeightVG modifiers. */ diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index a42c3e6a171..c50e68b9465 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -4802,6 +4802,16 @@ static void rna_def_modifier_weightvgedit(BlenderRNA *brna) RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */ RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "invert_falloff", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "edit_flags", MOD_WVG_INVERT_FALLOFF); + RNA_def_property_ui_text(prop, "Invert Falloff", "Invert the resulting falloff weight"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop = RNA_def_property(srna, "map_curve", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "cmap_curve"); + RNA_def_property_ui_text(prop, "Mapping Curve", "Custom mapping curve"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "use_add", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "edit_flags", MOD_WVG_EDIT_ADD2VG); RNA_def_property_ui_text(prop, @@ -4827,11 +4837,6 @@ static void rna_def_modifier_weightvgedit(BlenderRNA *brna) "it is not in the vgroup"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "map_curve", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_sdna(prop, NULL, "cmap_curve"); - RNA_def_property_ui_text(prop, "Mapping Curve", "Custom mapping curve"); - RNA_def_property_update(prop, 0, "rna_Modifier_update"); - prop = RNA_def_property(srna, "add_threshold", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "add_threshold"); RNA_def_property_range(prop, 0.0, 1.0); @@ -4862,11 +4867,6 @@ static void rna_def_modifier_weightvgedit(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "edit_flags", MOD_WVG_EDIT_INVERT_VGROUP_MASK); RNA_def_property_ui_text(prop, "Invert", "Invert vertex group mask influence"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); - - prop = RNA_def_property(srna, "invert_falloff", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "edit_flags", MOD_WVG_INVERT_FALLOFF); - RNA_def_property_ui_text(prop, "Invert Falloff", "Invert the resulting falloff weight"); - RNA_def_property_update(prop, 0, "rna_Modifier_update"); } static void rna_def_modifier_weightvgmix(BlenderRNA *brna) @@ -5065,6 +5065,11 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna) RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */ RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop = RNA_def_property(srna, "invert_falloff", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "proximity_flags", MOD_WVG_PROXIMITY_INVERT_FALLOFF); + RNA_def_property_ui_text(prop, "Invert Falloff", "Invert the resulting falloff weight"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + /* Common masking properties. */ rna_def_modifier_weightvg_mask(brna, srna, diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index e93ab608498..23e4da32ed7 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -54,20 +54,22 @@ * mapping to the real vertex index (in case the weight tables do not cover the whole vertices...). * cmap might be NULL, in which case curve mapping mode will return unmodified data. */ -void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cmap, RNG *rng) +void weightvg_do_map( + int num, float *new_w, short falloff_type, const bool do_invert, CurveMapping *cmap, RNG *rng) { int i; /* Return immediately, if we have nothing to do! */ /* Also security checks... */ - if (((falloff_type == MOD_WVG_MAPPING_CURVE) && (cmap == NULL)) || !ELEM(falloff_type, - MOD_WVG_MAPPING_CURVE, - MOD_WVG_MAPPING_SHARP, - MOD_WVG_MAPPING_SMOOTH, - MOD_WVG_MAPPING_ROOT, - MOD_WVG_MAPPING_SPHERE, - MOD_WVG_MAPPING_RANDOM, - MOD_WVG_MAPPING_STEP)) { + if (!do_invert && (((falloff_type == MOD_WVG_MAPPING_CURVE) && (cmap == NULL)) || + !ELEM(falloff_type, + MOD_WVG_MAPPING_CURVE, + MOD_WVG_MAPPING_SHARP, + MOD_WVG_MAPPING_SMOOTH, + MOD_WVG_MAPPING_ROOT, + MOD_WVG_MAPPING_SPHERE, + MOD_WVG_MAPPING_RANDOM, + MOD_WVG_MAPPING_STEP))) { return; } @@ -103,9 +105,14 @@ void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cm case MOD_WVG_MAPPING_STEP: fac = (fac >= 0.5f) ? 1.0f : 0.0f; break; + case MOD_WVG_MAPPING_NONE: + BLI_assert(do_invert); + break; + default: + BLI_assert(0); } - new_w[i] = fac; + new_w[i] = do_invert ? 1.0f - fac : fac; } } diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h index fa3c61a6b6f..bcd1076eac6 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.h +++ b/source/blender/modifiers/intern/MOD_weightvg_util.h @@ -52,8 +52,12 @@ struct Tex; */ #define MOD_WVG_ZEROFLOOR 1.0e-32f -void weightvg_do_map( - int num, float *new_w, short mode, struct CurveMapping *cmap, struct RNG *rng); +void weightvg_do_map(int num, + float *new_w, + short mode, + const bool do_invert, + struct CurveMapping *cmap, + struct RNG *rng); void weightvg_do_mask(const ModifierEvalContext *ctx, const int num, diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index 2b2a4cf85ea..ba1745f7b5e 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -230,28 +230,21 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes } /* Do mapping. */ - if (wmd->falloff_type != MOD_WVG_MAPPING_NONE) { + const bool do_invert_mapping = (wmd->edit_flags & MOD_WVG_INVERT_FALLOFF) != 0; + if (do_invert_mapping || wmd->falloff_type != MOD_WVG_MAPPING_NONE) { RNG *rng = NULL; if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM) { rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ctx->object->id.name + 2)); } - weightvg_do_map(numVerts, new_w, wmd->falloff_type, wmd->cmap_curve, rng); + weightvg_do_map(numVerts, new_w, wmd->falloff_type, do_invert_mapping, wmd->cmap_curve, rng); if (rng) { BLI_rng_free(rng); } } - /* Invert resulting weights */ - if ((wmd->edit_flags & MOD_WVG_INVERT_FALLOFF) != 0) { - for (i = 0; i < numVerts; i++) { - new_w[i] = 1.0f - new_w[i]; - } - } - - /* Do masking. */ struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); weightvg_do_mask(ctx, diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index e2e8e732311..7c9242ed900 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -239,8 +239,13 @@ static float get_ob2ob_distance(const Object *ob, const Object *obr) /** * Maps distances to weights, with an optional "smoothing" mapping. */ -static void do_map( - Object *ob, float *weights, const int nidx, const float min_d, const float max_d, short mode) +static void do_map(Object *ob, + float *weights, + const int nidx, + const float min_d, + const float max_d, + short mode, + const bool do_invert_mapping) { const float range_inv = 1.0f / (max_d - min_d); /* invert since multiplication is faster */ uint i = nidx; @@ -276,14 +281,15 @@ static void do_map( } } - if (!ELEM(mode, MOD_WVG_MAPPING_NONE, MOD_WVG_MAPPING_CURVE)) { + BLI_assert(mode != MOD_WVG_MAPPING_CURVE); + if (do_invert_mapping || mode != MOD_WVG_MAPPING_NONE) { RNG *rng = NULL; if (mode == MOD_WVG_MAPPING_RANDOM) { rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ob->id.name + 2)); } - weightvg_do_map(nidx, weights, mode, NULL, rng); + weightvg_do_map(nidx, weights, mode, do_invert_mapping, NULL, rng); if (rng) { BLI_rng_free(rng); @@ -559,7 +565,13 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes } /* Map distances to weights. */ - do_map(ob, new_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->falloff_type); + do_map(ob, + new_w, + numIdx, + wmd->min_dist, + wmd->max_dist, + wmd->falloff_type, + (wmd->proximity_flags & MOD_WVG_PROXIMITY_INVERT_FALLOFF) != 0); /* Do masking. */ struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); |