From e2c24bac6c56df6a54c37233d43f609f86d868d5 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 8 Aug 2011 21:12:51 +0000 Subject: vgroup_modifiers: Now clamping output values to [0.0, 1.0] range (and added min/max mapping values for Prowimity modif). --- .../blender/modifiers/intern/MOD_weightvg_util.c | 3 +++ .../modifiers/intern/MOD_weightvgproximity.c | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index 1fe1a96c2e5..43cc3081199 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -192,6 +192,9 @@ void weightvg_update_vg(MDeformVert *dvert, int defgrp_idx, int num, int *indice MDeformVert *dv = &dvert[indices ? indices[i] : i]; MDeformWeight *newdw; + /* Never allow weights out of [0.0, 1.0] range. */ + CLAMP(w, 0.0, 1.0); + /* Let’s first check to see if this vert is already in the weight group – if so * let’s update it, or remove it if needed. */ diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 537c5784d29..7272878b5b5 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -200,6 +200,27 @@ static float get_ob2ob_distance(const Object* ob, const Object* obr) return len_v3v3(ob->obmat[3], obr->obmat[3]); } +/** + * Maps distances to weights. + */ +void do_map(float *weights, const int nidx, const float min_d, const float max_d) +{ + int i; + float b = min_d / (min_d - max_d); + float a = -b / min_d; + for (i = 0; i < nidx; i++) + weights[i] = a * weights[i] + b; +} + +/*a min_d + b = 0.0*/ +/*a max_d + b = 1.0*/ +/*a min_d = -b*/ +/*a = -b / min_d*/ + +/*max_d(-b/min_d) + b = 1.0*/ +/*b((-max_d/min_d)+1.0) = 1.0*/ +/*b = 1.0 / ((min_d-max_d)/min_d)*/ +/*b = min_d/(min_d-max_d)*/ /************************************** * Modifiers functions. * **************************************/ @@ -476,6 +497,9 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der wmd->mask_defgrp_name, wmd->mask_texture, wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name); + /* Map distances to weights. */ + do_map(org_w, numIdx, wmd->min_dist, wmd->max_dist); + /* Update vgroup. Note we never add nor remove vertices from vgroup here. */ weightvg_update_vg(dvert, defgrp_idx, numIdx, indices, org_w, 0, 0.0f, 0, 0.0f); -- cgit v1.2.3