[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39198] branches/vgroup_modifiers: vgroup_modifiers: Now clamping output values to [0.0, 1.0] range ( and added min/max mapping values for Prowimity modif).
Bastien Montagne
montagne29 at wanadoo.fr
Mon Aug 8 23:12:51 CEST 2011
Revision: 39198
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39198
Author: mont29
Date: 2011-08-08 21:12:51 +0000 (Mon, 08 Aug 2011)
Log Message:
-----------
vgroup_modifiers: Now clamping output values to [0.0, 1.0] range (and added min/max mapping values for Prowimity modif).
Modified Paths:
--------------
branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py
branches/vgroup_modifiers/source/blender/makesdna/DNA_modifier_types.h
branches/vgroup_modifiers/source/blender/makesrna/intern/rna_modifier.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
Modified: branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py
===================================================================
--- branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py 2011-08-08 20:25:00 UTC (rev 39197)
+++ branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py 2011-08-08 21:12:51 UTC (rev 39198)
@@ -859,6 +859,10 @@
row = layout.row()
row.prop(md, "proximity_geometry", expand=True)
+ row = layout.split()
+ row.prop(md, "min_dist")
+ row.prop(md, "max_dist")
+
# Common mask options…
layout.separator()
self.weight_vg_mask(layout, ob, md)
Modified: branches/vgroup_modifiers/source/blender/makesdna/DNA_modifier_types.h
===================================================================
--- branches/vgroup_modifiers/source/blender/makesdna/DNA_modifier_types.h 2011-08-08 20:25:00 UTC (rev 39197)
+++ branches/vgroup_modifiers/source/blender/makesdna/DNA_modifier_types.h 2011-08-08 21:12:51 UTC (rev 39198)
@@ -921,6 +921,8 @@
int mask_tex_mapping; /* How to map the texture! */
char mask_tex_uvlayer_name[32]; /* Name of the UV layer. */
+ float min_dist, max_dist; /* Distances mapping to 0.0/1.0 weights. */
+
/* Padding… */
int pad_i2;
} WeightVGProximityModifierData;
Modified: branches/vgroup_modifiers/source/blender/makesrna/intern/rna_modifier.c
===================================================================
--- branches/vgroup_modifiers/source/blender/makesrna/intern/rna_modifier.c 2011-08-08 20:25:00 UTC (rev 39197)
+++ branches/vgroup_modifiers/source/blender/makesrna/intern/rna_modifier.c 2011-08-08 21:12:51 UTC (rev 39198)
@@ -2781,6 +2781,18 @@
RNA_def_property_flag(prop, PROP_EDITABLE|PROP_ID_SELF_CHECK);
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+ prop= RNA_def_property(srna, "min_dist", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+ RNA_def_property_ui_range(prop, -100000.0, 100000.0, 10, 0);
+ RNA_def_property_ui_text(prop, "Lowest Dist", "Distance mapping to weight 0.0.");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop= RNA_def_property(srna, "max_dist", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
+ RNA_def_property_ui_range(prop, -100000.0, 100000.0, 10, 0);
+ RNA_def_property_ui_text(prop, "Highest Dist", "Distance mapping to weight 1.0.");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
/* Common masking properties. */
rna_def_modifier_weightvg_mask(brna, srna);
}
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c 2011-08-08 20:25:00 UTC (rev 39197)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c 2011-08-08 21:12:51 UTC (rev 39198)
@@ -192,6 +192,9 @@
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.
*/
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c 2011-08-08 20:25:00 UTC (rev 39197)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c 2011-08-08 21:12:51 UTC (rev 39198)
@@ -200,6 +200,27 @@
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 @@
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);
More information about the Bf-blender-cvs
mailing list