[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37027] branches/soc-2011-radish/source/ blender/editors/sculpt_paint/paint_vertex.c:

Jason Hays jason_hays22 at mymail.eku.edu
Mon May 30 18:33:24 CEST 2011


Revision: 37027
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37027
Author:   jason_hays22
Date:     2011-05-30 16:33:23 +0000 (Mon, 30 May 2011)
Log Message:
-----------


Modified Paths:
--------------
    branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c

Modified: branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-30 15:40:01 UTC (rev 37026)
+++ branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-30 16:33:23 UTC (rev 37027)
@@ -1028,15 +1028,74 @@
 		}
 	}
 }
+/* Jason was here 
+this function will handle normalize with locked groups 
+it assumes that the current ratios (of locked groups)
+are the intended ratios.
 
+also, it does not attempt to force them to add up to 1, that would destroy intergroup weight ratios,
+it simply makes the highest weight sum add up to one
+
+the Mesh is needed to change the ratios across the group
+*/
+static void do_wp_auto_normalize_locked_groups(Mesh *me, MDeformVert *dvert, char* map)
+{
+	float highestSum = 0.0f;
+	float currentSum;
+	int cnt;
+	int i, k;
+	int totvert = me->totvert;
+	MDeformVert dv;
+
+	if(!map) {
+		return;
+	}
+
+	for(i = 0; i < totvert; i++) {
+		dv = dvert[i];
+		cnt = dv.totweight;
+		currentSum = 0.0f;
+		for(k = 0; k < cnt; k++) {
+			currentSum += (dv.dw+k)->weight;
+		}
+		if(highestSum < currentSum) {
+			highestSum = currentSum;
+		}
+	}
+	if(highestSum == 1.0f) {
+		return;
+	}
+	for(i = 0; i < totvert; i++) {
+		dv = dvert[i];
+		cnt = dv.totweight;
+
+		for(k = 0; k < cnt; k++) {
+			(dv.dw+k)->weight /= highestSum;
+		}
+	}
+}
+/* Jason was here */
+static char get_locked_flag(Object *ob, int vgroup)
+{
+	int i = 0;
+	bDeformGroup *defgroup = ob->defbase.first;
+	for(i = 0; i < vgroup && defgroup; i++) {
+		defgroup = defgroup->next;
+	}
+	return defgroup->flag;
+}
+
 /*Jason was here
 not sure where these prototypes belong at them moment
 static char* gen_lck_flags(Object* ob);
 static void fix_weight_ratios(Mesh *me, MDeformWeight *pnt_dw, float oldw);
 
-gen_lck_flags gets the status of "flag" for each bDeformGroup in ob->defbase and returns an array containing them 
+gen_lck_flags gets the status of "flag" for each bDeformGroup
+in ob->defbase and returns an array containing them
+
+But I didn't need all of them in one place yet, so I'm using get_locked_flag()
 */
-static char* gen_lck_flags(Object* ob)
+/*static char* gen_lck_flags(Object* ob)
 {
 	char is_locked = 0;
 	int i, k;
@@ -1054,7 +1113,7 @@
 		return flags;
 	}
 	return NULL;
-}
+}*/
 /*Jason was here
 this alters the weights in order to maintain the ratios to match with the change in weights of pnt_dw
 */
@@ -1064,17 +1123,21 @@
 	float scaledown = 1.0f;
 	float neww = pnt_dw->weight;
 	int defgroup = pnt_dw->def_nr;
+	MDeformVert *dvert;
+	MDeformVert dv;
+	MDeformWeight *dw;
 	totvert = me->totvert;
 	pnt_dw->weight = oldw;
 
 	if(oldw == 0 || neww == 0){
 		return;
 	}
-
+	dvert = me->dvert;
 	for(i = 0; i < totvert; i++) {
-		cnt = (me->dvert+i)->totweight;
+		dv = dvert[i];
+		cnt = dv.totweight;
 		for(k = 0; k < cnt; k++) {
-			MDeformWeight *dw = ((me->dvert+i)->dw+k);
+			dw = dv.dw+k;
 			if(dw->def_nr == defgroup){
 				dw->weight = neww * (dw->weight / oldw);
 				if(dw->weight > scaledown){
@@ -1086,9 +1149,10 @@
 	}
 	if(scaledown > 1.0f) {
 		for(i = 0; i < totvert; i++) {
-			cnt = (me->dvert+i)->totweight;
+			dv = dvert[i];
+			cnt = dv.totweight;
 			for(k = 0; k < cnt; k++) {
-				MDeformWeight *dw = ((me->dvert+i)->dw+k);
+				dw = dv.dw+k;
 				if(dw->def_nr == defgroup){
 					dw->weight /= scaledown;
 					break;
@@ -1106,7 +1170,7 @@
 	int vgroup= ob->actdef-1;
 	
 	/* Jason was here */
-	char *flags;
+	char locked;
 	float oldw;
 
 	if(wp->flag & VP_ONLYVGROUP) {
@@ -1120,21 +1184,18 @@
 	if(dw==NULL || uw==NULL)
 		return;
 	/* Jason was here */
-	flags = gen_lck_flags(ob);
+	locked = get_locked_flag(ob, vgroup);
 	oldw = dw->weight;
 
 	wpaint_blend(wp, dw, uw, alpha, paintweight, flip);
 
 	/* Jason was here */
-	/* you are not allowed to go to or from zero if the group is locked */
-	if(flags && flags[dw->def_nr]) {
-		if(oldw == 0 || dw->weight == 0){
-			dw->weight = oldw;
-		}
+	if(locked) {
+		fix_weight_ratios(me, dw, oldw);
+		do_wp_auto_normalize_locked_groups(me, me->dvert, validmap);
+	}else {
+		do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);
 	}
-
-	do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);
-
 	if(me->editflag & ME_EDIT_MIRROR_X) {	/* x mirror painting */
 		int j= mesh_get_x_mirror_vert(ob, index);
 		if(j>=0) {
@@ -1143,19 +1204,19 @@
 				uw= defvert_verify_index(me->dvert+j, vgroup_mirror);
 			else
 				uw= defvert_verify_index(me->dvert+j, vgroup);
-				
+			/* Jason */
+			oldw = uw->weight;
+
 			uw->weight= dw->weight;
-
-			do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap);
+			/* Jason */
+			if(locked) {
+				fix_weight_ratios(me, uw, oldw);
+				do_wp_auto_normalize_locked_groups(me, me->dvert, validmap);
+			} else {
+				do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap);
+			}
 		}
 	}
-	/* Jason was here */
-	if(flags){
-		if(flags[dw->def_nr]) {
-			fix_weight_ratios(me, dw, oldw);
-		}
-		MEM_freeN(flags);
-	}
 }
 
 




More information about the Bf-blender-cvs mailing list