[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37566] branches/soc-2011-radish/source/ blender: Made Multi-Paint and Locking more independent to better support future features .

Jason Hays jason_hays22 at mymail.eku.edu
Thu Jun 16 21:05:05 CEST 2011


Revision: 37566
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37566
Author:   jason_hays22
Date:     2011-06-16 19:05:05 +0000 (Thu, 16 Jun 2011)
Log Message:
-----------
Made Multi-Paint and Locking more independent to better support future features.
(an if statement surrounding Multi-Paint still checks the lock flags to see if it should bother changing anything)

Also, I changed lock's redistribution method so that if there was no enough space
on other unlocked groups, it tries to keep the new weights' ratios to each other

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-16 18:27:20 UTC (rev 37565)
+++ branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c	2011-06-16 19:05:05 UTC (rev 37566)
@@ -1612,8 +1612,6 @@
 	Mesh *me = ob->data;
 	float colf[4], input = 0.0f, unsel_sum = 0.0f;// Jason
 	int i;
-	//Jason, a dw might be absent from dvert, so count the dw's you find
-	// to see if it should be disabled in multipaint
 	int cnt = 0;
 	char make_black = FALSE;
 
@@ -1622,12 +1620,10 @@
 			// Jason was here
 			if(multipaint && selected > 1) {
 				if(dg_flags[me->dvert[vert].dw[i].def_nr]) {
-					if(!me->dvert[vert].dw[i].weight) {
-						make_black = TRUE;
-						break;
+					if(me->dvert[vert].dw[i].weight) {
+						input+=me->dvert[vert].dw[i].weight;
+						cnt++;
 					}
-					input+=me->dvert[vert].dw[i].weight;
-					cnt++;
 				}
 				// TODO unselected non-bone groups should not be involved in this sum
 				else if(auto_normalize) {
@@ -1638,11 +1634,11 @@
 			}
 		}
 		// Jason was here
-		if(multipaint && selected > 1 && !make_black) {
-			if(cnt!=selected || input == 1.0f && auto_normalize && !unsel_sum) {
+		if(multipaint && selected > 1) {
+			if(cnt == 0 || input == 1.0f && auto_normalize && !unsel_sum) {
 				make_black = TRUE;
-			} else {
-				input/=selected;
+			} 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-16 18:27:20 UTC (rev 37565)
+++ branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-06-16 19:05:05 UTC (rev 37566)
@@ -1029,7 +1029,7 @@
 	}
 }
 // Jason was here: the active group should be involved in auto normalize
-static void do_weight_paint_auto_normalize_change_act_group(MDeformVert *dvert, char *map)
+static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map)
 {
 //	MDeformWeight *dw = dvert->dw;
 	float sum=0.0f, fac=0.0f;
@@ -1107,23 +1107,8 @@
 	}
 	return FALSE;
 }
+
 /* Jason was here */
-static float get_change_allowed_from_unlocked_bone_groups(MDeformVert *dvert, int def_nr, int defcnt, char *selection, int pos, char *flags, char *bone_groups) {
-	int i;
-	float allowed_totchange = 0.0f;
-	for(i = 0; i < defcnt; i++) {
-		if(def_nr != i && bone_groups[i] && !selection[i] && !flags[i]) {
-			// positive change
-			if(pos == 1) {
-				allowed_totchange -= 1-defvert_verify_index(dvert, i)->weight;
-			} else {//negative change
-				allowed_totchange -= defvert_verify_index(dvert, i)->weight;
-			}
-		}
-	}
-	return allowed_totchange;
-}
-/* Jason was here */
 static int has_unselected_unlocked_bone_group(int defcnt, char *selection, int selected, char *flags, char *bone_groups) {
 	int i;
 	if(defcnt == selected) {
@@ -1136,216 +1121,222 @@
 	}
 	return FALSE;
 }
-/*
-The idea behind this function is to get the difference in weight,
-and to redistribute that weight to the unlocked groups
-(if it has to, then it will put some/all of the change
-back onto the original group)
-*/
-static void redistribute_weight_change(Object *ob, MDeformVert *dvert, int index, int def_nr, int multipaint, char *selection, int selected, float change_left, char* flags, int defcnt, char *map)
-{
+
+/*Jason*/
+static void multipaint_selection(MDeformVert *dvert, float change, char *selection, int defcnt) {
 	int i;
-	float old_change_left;
-	// make sure the redistribution the same per loop.
-	float change;
-	char was_a_change;
-	int groups_left_that_can_change = 0;
-	char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags");
 	MDeformWeight *dw;
+	// make sure they are all at most 1 after the change
 	for(i = 0; i < defcnt; i++) {
-		if(def_nr == i || (multipaint && selection[i]) || !map[i]) {
-			change_status[i] = FALSE;
-		} else {
-			change_status[i] = !flags[i];
+		if(selection[i]) {
+			dw = defvert_find_index(dvert, i);
+			if(dw && dw->weight) {
+				if(dw->weight * change > 1) {
+					change = 1.0f/dw->weight;
+				}
+			}
 		}
-		if(change_status[i]) {
-			groups_left_that_can_change++;
-			defvert_verify_index(dvert, i);
-		}
 	}
-	if(groups_left_that_can_change > 0) {
-		change = change_left/groups_left_that_can_change;
-		/* the division could cause it to be zero, so if it is, forget it*/
-		if(change == 0) {
-			change = change_left;
+	for(i = 0; i < defcnt; i++) {
+		if(selection[i]) {
+			dw = defvert_find_index(dvert, i);
+			if(dw && dw->weight) {
+				dw->weight = dw->weight * change;
+			}
 		}
-		do {
-			was_a_change = FALSE;
-			for(i = 0; i < dvert->totweight; i++) {
-				dw = defvert_verify_index(dvert, i);
-				if(!change_status[dw->def_nr]) {
-					continue;
-				}
-
-				old_change_left = change_left;
-				change_left -= change;
-				// sign change?
-				if(change_left!=0 && change_left/fabs(change_left) != old_change_left/fabs(old_change_left)) {
-					change_left = old_change_left;
-					break;
+	}
+}
+/*Jason*/
+static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, char *validmap, float totchange, float total_valid) {
+	float was_change;
+	float change;
+	float oldval;
+	MDeformWeight *ndw;
+	int i;
+	do {
+		was_change = FALSE;
+		change = totchange/total_valid;
+		for(i = 0; i < ndv->totweight && total_valid && totchange; i++) {
+			ndw = (ndv->dw+i);
+			if(change_status[ndw->def_nr] == changeme) {
+				oldval = ndw->weight;
+				if(!validmap && ndw->weight + change > 1) {
+					totchange -= 1-ndw->weight;
+					ndw->weight = 1;
+					change_status[ndw->def_nr] = changeto;
+					total_valid--;
+				} else if(ndw->weight + change < 0) {
+					totchange -= ndw->weight;
+					ndw->weight = 0;
+					change_status[ndw->def_nr] = changeto;
+					total_valid--;
 				} else {
-					dw->weight += change;
+					totchange -= change;
+					ndw->weight += change;
 				}
-				if(dw->weight >= 1.0f) {
-
-					change_left += dw->weight-1.0f;
-					dw->weight = 1.0f;
-					groups_left_that_can_change--;
-					change_status[dw->def_nr] = FALSE;
-
-				}else if(dw->weight <= 0.0f) {
-
-					change_left += dw->weight;
-					dw->weight = 0.0f;
-					groups_left_that_can_change--;
-					change_status[dw->def_nr] = FALSE;
+				if(oldval != ndw->weight) {
+					was_change = TRUE;
 				}
-				/* if it was too small, don't get stuck in an infinite loop! */
-				if(old_change_left != change_left) {
-					was_a_change = TRUE;
-				}
 			}
-		} while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change);
-	}
-	// now it should never have any left, unless there are precision problems
-	// add any remaining change back to the original weight
-	if(change_left > 0) {
-		if(multipaint) {
-			for(i = 0; i < defcnt; i++) {
-				if(selection[i]) {
-					defvert_find_index(dvert, i)->weight += change_left/selected;
-				}
-			}
-		} else {
-			defvert_find_index(dvert, def_nr)->weight += change_left;
 		}
-	}
-	MEM_freeN(change_status);
+	}while(was_change && total_valid && totchange);
+	return totchange;
 }
-/* Jason */
-/* get the change that is needed to get a valid multipaint (if it can)*/
-static float get_valid_multipaint_change(MDeformVert *dvert, float neww, float oldw, float allowed_totchange, char* validmap, char* bone_groups, char* selection, int defcnt) {
-	int i;
+/*Jason*/
+static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defcnt, char *flags, char *bone_groups, char *validmap) {
+	float totchange = 0.0f;
+	float totchange_allowed = 0.0f;
+	float left_over;
 	float change;
-	float tchange;
-	MDeformWeight *w;
-	float val;
-	// see if you need to do anything (if it is normalized)
-	float sumw = 0.0f;
-	if(allowed_totchange == 0 || oldw == 0 || !selection) {
-		return FALSE;
+	int total_valid = 0;
+	int total_changed = 0;
+	int i;
+	MDeformWeight *ndw;
+	MDeformWeight *odw;
+	MDeformWeight *ndw2;
+	MDeformWeight *odw2;
+	int designatedw = -1;
+	int designatedw_changed = FALSE;
+	float storedw;
+	char *change_status;
+	char new_weight_has_zero = FALSE;
+
+	if(!flags || !has_locked_group(ndv, flags)) {
+		return;
 	}
-	change = neww/oldw;
-	if(change == 1 || !change) {
-		return FALSE;
-	}
-	// see if all changes are valid before doing any
+
+	change_status = MEM_callocN(sizeof(char)*defcnt, "unlocked_unchanged");
+
 	for(i = 0; i < defcnt; i++) {
-		if(!selection[i] || !bone_groups[i]) {
+		ndw = defvert_find_index(ndv, i);
+		odw = defvert_find_index(odv, i);
+		if(!ndw || !odw) {
+			if (!flags[i] && bone_groups[i]){
+				defvert_verify_index(odv, i);
+				defvert_verify_index(ndv, i);
+				total_valid++;
+				change_status[i] = 1; // can be altered while redistributing
+			}
 			continue;
 		}
-		w = defvert_verify_index(dvert, i);
-		// already reached the cap
-		if(change > 1 && w->weight==1) {
-			return FALSE;
-		}
-		if(w->weight == 0) {
-			if(selection[i]) {
-				return FALSE;
+		if(flags[i]) {
+			ndw->weight = odw->weight;
+		} else if(ndw->weight != odw->weight) {
+			totchange += ndw->weight-odw->weight;
+			change_status[i] = 2; // was altered already
+			total_changed++;
+			if(ndw->weight == 0) {
+				new_weight_has_zero = TRUE;
+			} else if(!designatedw){
+				designatedw = i;
 			}
-			continue;
+		} else if (bone_groups[i]){
+			totchange_allowed += ndw->weight;
+			total_valid++;
+			change_status[i] = 1; // can be altered while redistributing
 		}
-		val = w->weight*change;
-		// no success here-I'm not going to force it to try to be just above 0 by changing 'change'
-		if(val <= 0) {
-			return FALSE;
-		}
-		if (validmap){
-			sumw += w->weight;
-		}else if(val > 1) {
-			// use the transitive property to make magic, all of the others
-			// will still end up within the boundaries if the worst case does
-			change = 1.0f/w->weight;
-		}
 	}
-	if(validmap && sumw == 1.0f) {
-		return FALSE;
-	}
-	if(allowed_totchange>0) {
-		for(i = 0; i < defcnt; i++) {
-			w = defvert_find_index(dvert, i);
-			if(w && selection[i] && bone_groups[i]) {
-				tchange += w->weight*change;
+	if(total_changed) {
+		if(totchange_allowed) {
+			if(totchange < 0) {
+				totchange_allowed = total_valid - totchange_allowed;
+			} else {
+				totchange_allowed *= -1;
 			}
+			left_over = 0;
+			if(fabs(totchange_allowed) < fabs(totchange)) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list