Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2011-08-09 01:12:51 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2011-08-09 01:12:51 +0400
commite2c24bac6c56df6a54c37233d43f609f86d868d5 (patch)
treed38015c0a40f4352d181e32b023c310b759d2c2d /source/blender/modifiers
parentce20487fa79bb5b7e112bcdaca5a25ba8fbcfec2 (diff)
vgroup_modifiers: Now clamping output values to [0.0, 1.0] range (and added min/max mapping values for Prowimity modif).
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.c3
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c24
2 files changed, 27 insertions, 0 deletions
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);