Vertex Weight Proximity: minor updates and fixes.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Sep 2011 07:36:59 +0000 (07:36 +0000)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 8 Sep 2011 07:36:59 +0000 (07:36 +0000)
*Updated UI code (replaced “row columns” by splits ;) ).
*Clamped global influence to [0.0, 1.0] range!
*Added/edited some tooltips for Proximity.
*Proximity distance mapping can now be reversed by entering Lowest Dist > Highest Dist.
*Moved mapping before masking in Proximity, much more sensible this way!

release/scripts/startup/bl_ui/properties_data_modifier.py
source/blender/makesrna/intern/rna_modifier.c
source/blender/modifiers/intern/MOD_weightvgproximity.c

index 348ca554e63a860214281fbd3d04caf16c3d0a0d..c80823b0803899ca11b10b2effa4fab591ec0ac4 100644 (file)
@@ -740,20 +740,21 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     @staticmethod
     def vertex_weight_mask(layout, ob, md):
         layout.label(text="Influence/Mask Options:")
-        split = layout.split()
-        col1 = split.column()
-        col2 = split.column()
+        row = layout.row()
 
-        col1.label(text="Global Influence:")
-        col2.prop(md, "mask_constant", text="")
+        split = layout.split(percentage=0.4)
+        split.label(text="Global Influence:")
+        split.prop(md, "mask_constant", text="")
 
         if not md.mask_texture:
-            col1.label(text="Vertex Group Mask:")
-            col2.prop_search(md, "mask_vertex_group", ob, "vertex_groups", text="")
+            split = layout.split(percentage=0.4)
+            split.label(text="Vertex Group Mask:")
+            split.prop_search(md, "mask_vertex_group", ob, "vertex_groups", text="")
 
         if not md.mask_vertex_group:
-            col1.label(text="Texture Mask:")
-            col2.template_ID(md, "mask_texture", new="texture.new")
+            split = layout.split(percentage=0.4)
+            split.label(text="Texture Mask:")
+            split.template_ID(md, "mask_texture", new="texture.new")
             if md.mask_texture:
                 split = layout.split()
                 col = split.column()
index 2e8e8520dbf012b1206e1dc1ee0a1ed5de6f3b2b..d5c7002e07f8396b3d6d9039403370898b431329 100644 (file)
@@ -2510,7 +2510,7 @@ static void rna_def_modifier_weightvg_mask(BlenderRNA *brna, StructRNA *srna)
 
        prop= RNA_def_property(srna, "mask_constant", PROP_FLOAT, PROP_NONE);
        RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
-       RNA_def_property_ui_range(prop, -1.0, 1.0, 10, 0);
+       RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 0);
        RNA_def_property_ui_text(prop, "Influence", "Global influence of current modifications on vgroup.");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
@@ -2707,9 +2707,9 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna)
                {0, NULL, 0, NULL, NULL}};
 
        static EnumPropertyItem proximity_geometry_items[] = {
-               {MOD_WVG_PROXIMITY_GEOM_VERTS, "VERTEX", ICON_VERTEXSEL, "Vertex", ""},
-               {MOD_WVG_PROXIMITY_GEOM_EDGES, "EDGE", ICON_EDGESEL, "Edge", ""},
-               {MOD_WVG_PROXIMITY_GEOM_FACES, "FACE", ICON_FACESEL, "Face", ""},
+               {MOD_WVG_PROXIMITY_GEOM_VERTS, "VERTEX", ICON_VERTEXSEL, "Vertex", "Compute distance to nearest vertex."},
+               {MOD_WVG_PROXIMITY_GEOM_EDGES, "EDGE", ICON_EDGESEL, "Edge", "Compute distance to nearest edge."},
+               {MOD_WVG_PROXIMITY_GEOM_FACES, "FACE", ICON_FACESEL, "Face", "Compute distance to nearest face."},
                {0, NULL, 0, NULL, NULL}};
 
        static EnumPropertyItem weightvg_proximity_falloff_type_items[] = {
@@ -2748,7 +2748,9 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna)
        RNA_def_property_enum_sdna(prop, NULL, "proximity_flags");
        RNA_def_property_enum_items(prop, proximity_geometry_items);
        RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
-       RNA_def_property_ui_text(prop, "Proximity Geometry", "Use shortest distance to target object's geometry as weight");
+       RNA_def_property_ui_text(prop, "Proximity Geometry",
+                                "Use the shortest computed distance to target object's geometry "
+                                "as weight.");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
@@ -2760,13 +2762,13 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna)
        prop= RNA_def_property(srna, "min_dist", PROP_FLOAT, PROP_NONE);
        RNA_def_property_range(prop, 0.0, FLT_MAX);
        RNA_def_property_ui_range(prop, 0.0, 1000.0, 10, 0);
-       RNA_def_property_ui_text(prop, "Lowest Dist", "Distance mapping to weight 0.0.");
+       RNA_def_property_ui_text(prop, "Lowest Dist", "Distance mapping to weight 0.0 (or weight 1.0 if above Highest Dist).");
        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, 0.0, FLT_MAX);
        RNA_def_property_ui_range(prop, 0.0, 1000.0, 10, 0);
-       RNA_def_property_ui_text(prop, "Highest Dist", "Distance mapping to weight 1.0.");
+       RNA_def_property_ui_text(prop, "Highest Dist", "Distance mapping to weight 1.0 (or weight 0.0 if below Lowest Dist).");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop= RNA_def_property(srna, "falloff_type", PROP_ENUM, PROP_NONE);
index 561a021ce0cc5fdf8be086a442952c11bb5c0491..0dbf8a91d214ec307d47f360cd3beb81805236b1 100644 (file)
@@ -199,10 +199,24 @@ void do_map(float *weights, const int nidx, const float min_d, const float max_d
 {
        const float range_inv= 1.0f / (max_d - min_d); /* invert since multiplication is faster */
        unsigned int i= nidx;
-       while (i-- > 0) {
-               if     (weights[i] >= max_d) weights[i]= 1.0f; /* most likely case first */
-               else if(weights[i] <= min_d) weights[i]= 0.0f;
-               else                         weights[i]= (weights[i] - min_d) * range_inv;
+       if(max_d == min_d) {
+               while (i-- > 0) {
+                       weights[i] = (weights[i] >= max_d) ? 1.0f : 0.0f; /* "Step" behavior... */
+               }
+       }
+       else if(max_d > min_d) {
+               while (i-- > 0) {
+                       if     (weights[i] >= max_d) weights[i]= 1.0f; /* most likely case first */
+                       else if(weights[i] <= min_d) weights[i]= 0.0f;
+                       else                         weights[i]= (weights[i] - min_d) * range_inv;
+               }
+       }
+       else {
+               while (i-- > 0) {
+                       if     (weights[i] <= max_d) weights[i]= 1.0f; /* most likely case first */
+                       else if(weights[i] >= min_d) weights[i]= 0.0f;
+                       else                         weights[i]= (weights[i] - min_d) * range_inv;
+               }
        }
 
        if(!ELEM(mode, MOD_WVG_MAPPING_NONE, MOD_WVG_MAPPING_CURVE)) {
@@ -495,14 +509,14 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
                }
        }
 
+       /* Map distances to weights. */
+       do_map(new_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->falloff_type);
+
        /* Do masking. */
        weightvg_do_mask(numIdx, indices, org_w, new_w, ob, ret, wmd->mask_constant,
                         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, wmd->falloff_type);
-
        /* 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);