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
This commit is contained in:
2009-10-20 13:59:26 +00:00
parent cb8f7fd385
commit 4197253b26
4 changed files with 112 additions and 24 deletions

View File

@@ -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"
@@ -635,6 +635,22 @@ class VIEW3D_PT_sculpt_options(PaintPanel):
# ********** default tools for weightpaint ****************
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"
@@ -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)

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
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);
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;
j= dvert->totweight;
while(j--) {
dw= dvert->dw + j;
tot_weight += dw->weight;
}
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;
}
RNA_def_boolean(ot->srna, "all_groups", FALSE, "All Groups", "Normalize all vertex groups.");
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, "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)