[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24002] trunk/blender: split weight normalize into 2 operators, normalize and normalize_all.

Campbell Barton ideasman42 at gmail.com
Tue Oct 20 15:59:26 CEST 2009


Revision: 24002
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24002
Author:   campbellbarton
Date:     2009-10-20 15:59:26 +0200 (Tue, 20 Oct 2009)

Log Message:
-----------
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

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_view3d_toolbar.py
    trunk/blender/source/blender/editors/object/object_intern.h
    trunk/blender/source/blender/editors/object/object_ops.c
    trunk/blender/source/blender/editors/object/object_vgroup.c

Modified: trunk/blender/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2009-10-20 13:58:53 UTC (rev 24001)
+++ trunk/blender/release/scripts/ui/space_view3d_toolbar.py	2009-10-20 13:59:26 UTC (rev 24002)
@@ -103,7 +103,7 @@
 		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_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 @@
 		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_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)

Modified: trunk/blender/source/blender/editors/object/object_intern.h
===================================================================
--- trunk/blender/source/blender/editors/object/object_intern.h	2009-10-20 13:58:53 UTC (rev 24001)
+++ trunk/blender/source/blender/editors/object/object_intern.h	2009-10-20 13:59:26 UTC (rev 24002)
@@ -167,6 +167,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_invert(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_menu(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/object/object_ops.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_ops.c	2009-10-20 13:58:53 UTC (rev 24001)
+++ trunk/blender/source/blender/editors/object/object_ops.c	2009-10-20 13:59:26 UTC (rev 24002)
@@ -164,6 +164,7 @@
 	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);

Modified: trunk/blender/source/blender/editors/object/object_vgroup.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_vgroup.c	2009-10-20 13:58:53 UTC (rev 24001)
+++ trunk/blender/source/blender/editors/object/object_vgroup.c	2009-10-20 13:59:26 UTC (rev 24002)
@@ -616,9 +616,9 @@
 }
 
 /* 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 @@
 	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 @@
 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,10 +1409,38 @@
 
 	/* 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)
 {
 	Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;





More information about the Bf-blender-cvs mailing list