Fixed the redistribute_weight_change() function so that it spreads the change evenly...
authorJason Hays <jason_hays22@mymail.eku.edu>
Wed, 1 Jun 2011 19:21:36 +0000 (19:21 +0000)
committerJason Hays <jason_hays22@mymail.eku.edu>
Wed, 1 Jun 2011 19:21:36 +0000 (19:21 +0000)
source/blender/editors/sculpt_paint/paint_vertex.c

index 8f03b6051bf68aab309e5c4329cf4ea90826c11f..4910cdc42fe43950363329959c57f33b4706435d 100644 (file)
@@ -1211,6 +1211,8 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw
        float change;
        char was_a_change;
        int groups_left_that_can_change = 0;
+       // make sure there is no case for division by 0, and make the redistribution the same per loop.
+       int groups_currently_left;
        char* change_status = MEM_mallocN(defcnt*sizeof(char), "defflags");
        MDeformWeight *dw;
        //printf("start\n");
@@ -1227,6 +1229,7 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw
        }
        //printf("\n");
        if(groups_left_that_can_change > 0) {
+               groups_currently_left = groups_left_that_can_change;
                do {
                        was_a_change = FALSE;
                        for(i = 0; i < dvert->totweight; i++) {
@@ -1245,18 +1248,19 @@ static void redistribute_weight_change(MDeformVert *dvert, MDeformWeight *pnt_dw
 
                                        change_left += dw->weight-1.0f;
                                        dw->weight = 1.0f;
-                                       groups_left_that_can_change--;
+                                       groups_currently_left--;
                                        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--;
+                                       groups_currently_left--;
                                        change_status[dw->def_nr] = FALSE;
                                }
                                was_a_change = TRUE;
                        }
+                       groups_left_that_can_change = groups_currently_left;
                } while(groups_left_that_can_change > 0 && change_left != 0.0f && was_a_change);
        }
        // add any remaining change back to the original weight