* Added a quick little weight group 'Levels' operator, can interactively tweak overal...
authorMatt Ebb <matt@mke3.net>
Fri, 20 Nov 2009 05:09:57 +0000 (05:09 +0000)
committerMatt Ebb <matt@mke3.net>
Fri, 20 Nov 2009 05:09:57 +0000 (05:09 +0000)
release/scripts/ui/space_view3d_toolbar.py
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_vgroup.c

index 99da99b..aaa5220 100644 (file)
@@ -736,6 +736,7 @@ class VIEW3D_PT_tools_weightpaint(View3DPanel):
         col.itemO("object.vertex_group_normalize", text="Normalize")
         col.itemO("object.vertex_group_invert", text="Invert")
         col.itemO("object.vertex_group_clean", text="Clean")
+        col.itemO("object.vertex_group_levels", text="Levels")
 
 
 class VIEW3D_PT_tools_weightpaint_options(View3DPanel):
index 6272d3c..41d4af6 100644 (file)
@@ -173,6 +173,7 @@ void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot);
+void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_blend(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot);
index f74ab00..813d88f 100644 (file)
@@ -169,6 +169,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_vertex_group_normalize);
        WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all);
        WM_operatortype_append(OBJECT_OT_vertex_group_invert);
+       WM_operatortype_append(OBJECT_OT_vertex_group_levels);
        WM_operatortype_append(OBJECT_OT_vertex_group_blend);
        WM_operatortype_append(OBJECT_OT_vertex_group_clean);
        WM_operatortype_append(OBJECT_OT_vertex_group_menu);
index 7152a4d..14fb91f 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <string.h>
+#include <math.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -615,6 +616,32 @@ static void vgroup_normalize(Object *ob)
        }
 }
 
+static void vgroup_levels(Object *ob, float offset, float gain)
+{
+       bDeformGroup *dg;
+       MDeformWeight *dw;
+       MDeformVert *dvert, *dvert_array=NULL;
+       int i, def_nr, dvert_tot=0;
+       
+       ED_vgroup_give_array(ob->data, &dvert_array, &dvert_tot);
+       
+       dg = BLI_findlink(&ob->defbase, (ob->actdef-1));
+       
+       if(dg) {
+               def_nr= ob->actdef-1;
+               
+               for(i = 0; i < dvert_tot; i++) {
+                       dvert = dvert_array+i;
+                       dw = ED_vgroup_weight_get(dvert, def_nr);
+                       if(dw) {
+                               dw->weight = gain * (dw->weight + offset);
+                               
+                               CLAMP(dw->weight, 0.0f, 1.0f);
+                       }
+               }
+       }
+}
+
 /* TODO - select between groups */
 static void vgroup_normalize_all(Object *ob, int lock_active)
 {
@@ -1467,6 +1494,38 @@ void OBJECT_OT_vertex_group_copy(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+static int vertex_group_levels_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       
+       float offset= RNA_float_get(op->ptr,"offset");
+       float gain= RNA_float_get(op->ptr,"gain");
+       
+       vgroup_levels(ob, offset, gain);
+       
+       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_vertex_group_levels(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Vertex Group Levels";
+       ot->idname= "OBJECT_OT_vertex_group_levels";
+       
+       /* api callbacks */
+       ot->poll= vertex_group_poll;
+       ot->exec= vertex_group_levels_exec;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_float(ot->srna, "offset", 0.f, -1.0, 1.0, "Offset", "Value to add to weights.", -1.0f, 1.f);
+       RNA_def_float(ot->srna, "gain", 1.f, 0.f, FLT_MAX, "Gain", "Value to multiply weights by.", 0.0f, 10.f);
+}
 
 static int vertex_group_normalize_exec(bContext *C, wmOperator *op)
 {