diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-10-20 17:59:26 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-10-20 17:59:26 +0400 |
commit | 4197253b26dd86b1c06f400542fd073340f644a0 (patch) | |
tree | 654fbb19bfe39f94b1215ba7be7c28ded0f4edee | |
parent | cb8f7fd385251d22ab97a48466e33ce0e42d5e4d (diff) |
split weight normalize into 2 operators, normalize and normalize_all.
Added an option for normalize_all that keeps the active group at its existing weight while normaling all other groups around it.
Thsi makes it easy to paint up to 100% where all other groups will use progressivly less until the active group is 100% and all others are 0.
Added weight operators to the toolbar
-rw-r--r-- | release/scripts/ui/space_view3d_toolbar.py | 23 | ||||
-rw-r--r-- | source/blender/editors/object/object_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_ops.c | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 109 |
4 files changed, 111 insertions, 23 deletions
diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index f354a3314f2..a552bb7de14 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -103,7 +103,7 @@ class VIEW3D_PT_tools_meshedit(View3DPanel): col.itemO("screen.repeat_history", text="History...") col.itemO("screen.redo_last", text="Tweak...") -class VIEW3D_PT_tools_mesheditoptions(View3DPanel): +class VIEW3D_PT_tools_meshedit_options(View3DPanel): __context__ = "mesh_edit" __label__ = "Mesh Options" @@ -636,6 +636,22 @@ class VIEW3D_PT_sculpt_options(PaintPanel): class VIEW3D_PT_tools_weightpaint(View3DPanel): __context__ = "weightpaint" + __label__ = "Weight Tools" + + def draw(self, context): + layout = self.layout + + wpaint = context.tool_settings.weight_paint + + col = layout.column() + # col.itemL(text="Blend:") + col.itemO("object.vertex_group_normalize_all", text="Normalize All") + col.itemO("object.vertex_group_normalize", text="Normalize") + col.itemO("object.vertex_group_invert", text="Invert") + col.itemO("object.vertex_group_clean", text="Clean") + +class VIEW3D_PT_tools_weightpaint_options(View3DPanel): + __context__ = "weightpaint" __label__ = "Options" def draw(self, context): @@ -806,9 +822,10 @@ class VIEW3D_PT_tools_particlemode(View3DPanel): sub.active = pe.fade_time sub.itemR(pe, "fade_frames", slider=True) +bpy.types.register(VIEW3D_PT_tools_weightpaint) bpy.types.register(VIEW3D_PT_tools_objectmode) bpy.types.register(VIEW3D_PT_tools_meshedit) -bpy.types.register(VIEW3D_PT_tools_mesheditoptions) +bpy.types.register(VIEW3D_PT_tools_meshedit_options) bpy.types.register(VIEW3D_PT_tools_curveedit) bpy.types.register(VIEW3D_PT_tools_surfaceedit) bpy.types.register(VIEW3D_PT_tools_textedit) @@ -822,6 +839,6 @@ bpy.types.register(VIEW3D_PT_tools_brush_stroke) bpy.types.register(VIEW3D_PT_tools_brush_curve) bpy.types.register(VIEW3D_PT_sculpt_options) bpy.types.register(VIEW3D_PT_tools_vertexpaint) -bpy.types.register(VIEW3D_PT_tools_weightpaint) +bpy.types.register(VIEW3D_PT_tools_weightpaint_options) bpy.types.register(VIEW3D_PT_tools_projectpaint) bpy.types.register(VIEW3D_PT_tools_particlemode) diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 866180f01a0..36d897b76c8 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -167,6 +167,7 @@ void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot); 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_invert(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_menu(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 17487ea6aca..06b554f0406 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -164,6 +164,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked); WM_operatortype_append(OBJECT_OT_vertex_group_copy); 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_clean); WM_operatortype_append(OBJECT_OT_vertex_group_menu); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7c206ce300a..e5467e50972 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -616,9 +616,9 @@ static void vgroup_normalize(Object *ob) } /* TODO - select between groups */ -static void vgroup_normalize_all(Object *ob) +static void vgroup_normalize_all(Object *ob, int lock_active) { - MDeformWeight *dw; + MDeformWeight *dw, *dw_act; MDeformVert *dvert, *dvert_array=NULL; int i, dvert_tot=0; float tot_weight; @@ -626,25 +626,70 @@ static void vgroup_normalize_all(Object *ob) ED_vgroup_give_array(ob->data, &dvert_array, &dvert_tot); if(dvert_array) { - for(i = 0; i < dvert_tot; i++) { - int j; - tot_weight= 0.0f; - dvert = dvert_array+i; + if(lock_active) { + int def_nr= ob->actdef-1; - j= dvert->totweight; - while(j--) { - dw= dvert->dw + j; - tot_weight += dw->weight; + for(i = 0; i < dvert_tot; i++) { + float lock_iweight= 1.0f; + int j; + + tot_weight= 0.0f; + dw_act= NULL; + dvert = dvert_array+i; + + j= dvert->totweight; + while(j--) { + dw= dvert->dw + j; + + if(dw->def_nr==def_nr) { + dw_act= dw; + lock_iweight = (1.0f - dw_act->weight); + } + else { + tot_weight += dw->weight; + } + } + + if(tot_weight) { + j= dvert->totweight; + while(j--) { + dw= dvert->dw + j; + if(dw == dw_act) { + if (dvert->totweight==1) { + dw_act->weight= 1.0f; /* no other weights, set to 1.0 */ + } + } else { + if(dw->weight > 0.0f) + dw->weight = (dw->weight / tot_weight) * lock_iweight; + } + + /* incase of division errors with very low weights */ + CLAMP(dw->weight, 0.0f, 1.0f); + } + } } + } + else { + for(i = 0; i < dvert_tot; i++) { + int j; + tot_weight= 0.0f; + dvert = dvert_array+i; - if(tot_weight) { j= dvert->totweight; while(j--) { dw= dvert->dw + j; - dw->weight /= tot_weight; + tot_weight += dw->weight; + } - /* incase of division errors with very low weights */ - CLAMP(dw->weight, 0.0f, 1.0f); + if(tot_weight) { + j= dvert->totweight; + while(j--) { + dw= dvert->dw + j; + dw->weight /= tot_weight; + + /* incase of division errors with very low weights */ + CLAMP(dw->weight, 0.0f, 1.0f); + } } } } @@ -1342,12 +1387,8 @@ void OBJECT_OT_vertex_group_copy(wmOperatorType *ot) static int vertex_group_normalize_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - int all_groups= RNA_boolean_get(op->ptr,"all_groups"); - if(all_groups) - vgroup_normalize_all(ob); - else - vgroup_normalize(ob); + vgroup_normalize(ob); DAG_id_flush_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); @@ -1368,8 +1409,36 @@ void OBJECT_OT_vertex_group_normalize(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + int lock_active= RNA_boolean_get(op->ptr,"lock_active"); + + vgroup_normalize_all(ob, lock_active); + + 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_normalize_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Normalize All Vertex Groups"; + ot->idname= "OBJECT_OT_vertex_group_normalize_all"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_normalize_all_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Normalize all vertex groups."); + RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others."); } static int vertex_group_invert_exec(bContext *C, wmOperator *op) |