[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37705] branches/soc-2011-radish/source/ blender: Tweaked multi-paint and the way the colors are displayed so one of the artists could see it-

Jason Hays jason_hays22 at mymail.eku.edu
Tue Jun 21 21:20:42 CEST 2011


Revision: 37705
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37705
Author:   jason_hays22
Date:     2011-06-21 19:20:42 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
Tweaked multi-paint and the way the colors are displayed so one of the artists could see it-
when you paint the active group, and makes the others match based on the change factor; so the active group being 0 is not handled.

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

Modified: branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c	2011-06-21 18:24:00 UTC (rev 37704)
+++ branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c	2011-06-21 19:20:42 UTC (rev 37705)
@@ -1612,18 +1612,27 @@
 	Mesh *me = ob->data;
 	float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason
 	int i;
-	int cnt = 0;
 	char make_black = FALSE;
+	char was_a_nonzero = FALSE;
+	char actdef_nonzero = FALSE;
 
 	if (me->dvert) {
 		for (i=0; i<me->dvert[vert].totweight; i++) {
 			// Jason was here
 			if(multipaint && selected > 1) {
 				if(dg_flags[me->dvert[vert].dw[i].def_nr]) {
+					if(ob->actdef-1 == me->dvert[vert].dw[i].def_nr) {
+						if (me->dvert[vert].dw[i].weight == 0) {
+							//make_black = TRUE;
+							break;
+						}
+						actdef_nonzero = TRUE;
+					}
 					if(me->dvert[vert].dw[i].weight) {
 						input+=me->dvert[vert].dw[i].weight;
-						cnt++;
+						was_a_nonzero = TRUE;
 					}
+
 				}
 				// TODO unselected non-bone groups should not be involved in this sum
 				else if(auto_normalize) {
@@ -1633,13 +1642,18 @@
 				input+=me->dvert[vert].dw[i].weight;
 			}
 		}
+		
 		// Jason was here
-		if(multipaint && selected > 1) {
-			if(cnt == 0 || input == 1.0f && auto_normalize && !unsel_sum) {
+		if(!make_black && multipaint && selected > 1) {
+			/*if(input == 1.0f && auto_normalize && !unsel_sum) {
 				make_black = TRUE;
+			} else */
+			if(!(was_a_nonzero && actdef_nonzero)) {
+				make_black = TRUE;
 			} else if (!auto_normalize){
 				input /= selected;
 			}
+
 		}
 	}
 	

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-06-21 18:24:00 UTC (rev 37704)
+++ branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-06-21 19:20:42 UTC (rev 37705)
@@ -812,7 +812,8 @@
 		if (dw->weight > paintval)
 			dw->weight = paintval*alpha + dw->weight*(1.0f-alpha);
 	}
-	CLAMP(dw->weight, 0.0f, 1.0f);
+	// Jason delay clamping until the end so multi-paint can function when the active group is at the limits
+	//CLAMP(dw->weight, 0.0f, 1.0f);
 	
 	/* if no spray, clip result with orig weight & orig alpha */
 	if((wp->flag & VP_SPRAY)==0) {
@@ -839,7 +840,7 @@
 			else
 				testw = uw->weight;
 		}
-		CLAMP(testw, 0.0f, 1.0f);
+		//CLAMP(testw, 0.0f, 1.0f);
 		
 		if( testw<uw->weight ) {
 			if(dw->weight < testw) dw->weight= testw;
@@ -1126,12 +1127,14 @@
 static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) {
 	int i;
 	MDeformWeight *dw;
+	float val;
 	// make sure they are all at most 1 after the change
 	for(i = 0; i < defcnt; i++) {
 		if(selection[i]) {
 			dw = defvert_find_index(dvert, i);
 			if(dw && dw->weight) {
-				if(dw->weight * change > 1) {
+				val = dw->weight * change;
+				if(val > 1) {
 					change = 1.0f/dw->weight;
 				}
 			}
@@ -1237,6 +1240,10 @@
 		}
 	}
 	if(total_changed) {
+		// auto normalize will allow weights to temporarily go above 1 in redistribution
+		if(validmap && total_changed < 0 && total_valid) {
+			totchange_allowed = total_valid;
+		}
 		if(totchange_allowed) {
 			if(totchange < 0) {
 				totchange_allowed = total_valid - totchange_allowed;
@@ -1291,32 +1298,45 @@
 }
 /*Jason*/
 static float get_mp_change(MDeformVert *odv, char *selection, float oldw, float neww) {
-	int i;
-
 	if(oldw) {
 		return neww/oldw;
 	}
-
-	for(i = 0; i < odv->totweight; i++) {
-		if(selection[(odv->dw+i)->def_nr]) {
-			if((odv->dw+i)->weight) {
-				return ((odv->dw+i)->weight+neww) / (odv->dw+i)->weight;
-			}
+	return 0;
+}
+/*Jason*/
+/*static void reset_to_prev(VPaint *wv, MDeformVert *dv, int vgroup) {
+	int i;
+	MDeformWeight *d;
+	MDeformWeight *w;
+	for(i = 0; i < dv->totweight; i++) {
+		d = dv->dw+i;
+		if(d->def_nr == vgroup) {
+			continue;
 		}
+		w = defvert_find_index(wv, d->def_nr);
+		if(w) {
+			d->weight = w->weight;
+		} else {
+			d->weight = 0;
+		}
 	}
-	return 0;
+}*/
+/* Jason */
+static void clamp_weights(MDeformVert *dvert) {
+	int i;
+	for (i = 0; i < dvert->totweight; i++) {
+		CLAMP((dvert->dw+i)->weight, 0.0f, 1.0f);
+	}
 }
 /*Jason*/
 /* fresh start to make multi-paint and locking modular */
-static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) {
+static void apply_mp_lcks_normalize(Object *ob, Mesh *me, int index, MDeformWeight *dw, int defcnt, float oldw, float neww, char *selection, int selected, char *bone_groups, char *validmap, char *flags, int multipaint) {
 	MDeformVert *dvert = me->dvert+index;
 	MDeformVert *dv = MEM_mallocN(sizeof (*(me->dvert+index)), "oldMDeformVert");
-	float neww = dw->weight;
 	float change = 0.0f;
 	int i;
 	dw->weight = oldw;
-
-	//defvert_copy(dv, dvert);
+	
 	dv->dw= MEM_dupallocN(dvert->dw);
 	dv->flag = dvert->flag;
 	dv->totweight = dvert->totweight;
@@ -1329,6 +1349,8 @@
 			change = 0.0f;
 		}
 	}
+	clamp_weights(me->dvert+index);
+
 	enforce_locks(dv, dvert, defcnt, flags, bone_groups, validmap);
 
 	do_weight_paint_auto_normalize_all_groups(dvert, validmap);
@@ -1390,7 +1412,9 @@
 	char *selection;
 	int selected;
 	float oldw;
+	float neww;
 	int defcnt;
+	int i;
 	if(validmap) {
 		bone_groups = validmap;
 	}else {
@@ -1414,11 +1438,19 @@
 	if(!selected && ob->actdef) {
 		selected = 1;
 	}
+	
 	oldw = dw->weight;
 	wpaint_blend(wp, dw, uw, alpha, paintweight, flip);
+	neww = dw->weight;
+	if(selected > 1 && multipaint) {
+		if(!oldw || neww <= 0) {
+			neww = oldw;
+			dw->weight = oldw;
+		}
+	}
 	/* Jason was here */
-	apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint);
-	//check_locks_and_normalize(ob, me, index, vgroup, dw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint);
+	apply_mp_lcks_normalize(ob, me, index, dw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint);
+
 	// dvert may have been altered greatly
 	dw = defvert_find_index(me->dvert+index, vgroup);
 
@@ -1433,19 +1465,17 @@
 			/* Jason */
 			oldw = uw->weight;
 
-			uw->weight= dw->weight;
+			//uw->weight= dw->weight;
+			uw->weight = neww;
 			/* Jason */
-			apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, selection, selected, bone_groups, validmap, flags, multipaint);
-			//check_locks_and_normalize(ob, me, j, vgroup, uw, oldw, validmap, flags, defcnt, bone_groups, selection, selected, multipaint);
+			apply_mp_lcks_normalize(ob, me, j, uw, defcnt, oldw, neww, selection, selected, bone_groups, validmap, flags, multipaint);
 		}
 	}
 	/* Jason */
 	if(flags) {
 		MEM_freeN(flags);
 	}
-	if(selection) {
-		MEM_freeN(selection);
-	}
+	MEM_freeN(selection);
 	if(!validmap) {
 		MEM_freeN(bone_groups);
 	}




More information about the Bf-blender-cvs mailing list