Add invert mapping option to proximity weight edit modifier, and some cleanup.
This commit is contained in:
parent
26ef4fa85e
commit
bb26c1359e
|
@ -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()
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue