diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_weightvg_util.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_weightvg_util.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c index 23e4da32ed7..1a38787777f 100644 --- a/source/blender/modifiers/intern/MOD_weightvg_util.c +++ b/source/blender/modifiers/intern/MOD_weightvg_util.c @@ -10,7 +10,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, + * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The Original Code is Copyright (C) 2011 by Bastien Montagne. @@ -137,6 +137,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, const int tex_use_channel, const int tex_mapping, Object *tex_map_object, + const char *text_map_bone, const char *tex_uvlayer_name, const bool invert_vgroup_mask) { @@ -163,6 +164,7 @@ void weightvg_do_mask(const ModifierEvalContext *ctx, */ t_map.texture = texture; t_map.map_object = tex_map_object; + BLI_strncpy(t_map.map_bone, text_map_bone, sizeof(t_map.map_bone)); BLI_strncpy(t_map.uvlayer_name, tex_uvlayer_name, sizeof(t_map.uvlayer_name)); t_map.texmapping = tex_mapping; @@ -270,16 +272,45 @@ void weightvg_update_vg(MDeformVert *dvert, const bool do_add, const float add_thresh, const bool do_rem, - const float rem_thresh) + const float rem_thresh, + const bool do_normalize) { int i; + float min_w = weights[0]; + float norm_fac = 1.0f; + if (do_normalize) { + float max_w = weights[0]; + for (i = 1; i < num; i++) { + const float w = weights[i]; + + /* No need to clamp here, normalization will ensure we stay within [0.0, 1.0] range. */ + if (w < min_w) { + min_w = w; + } + else if (w > max_w) { + max_w = w; + } + } + + const float range = max_w - min_w; + if (fabsf(range) > FLT_EPSILON) { + norm_fac = 1.0f / range; + } + else { + min_w = 0.0f; + } + } + for (i = 0; i < num; i++) { float w = weights[i]; MDeformVert *dv = &dvert[indices ? indices[i] : i]; MDeformWeight *dw = dws ? dws[i] : ((defgrp_idx >= 0) ? BKE_defvert_find_index(dv, defgrp_idx) : NULL); + if (do_normalize) { + w = (w - min_w) * norm_fac; + } /* Never allow weights out of [0.0, 1.0] range. */ CLAMP(w, 0.0f, 1.0f); |