[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42706] trunk/blender/source/blender: cleanup of weight paint color setting code, no functional changes

Campbell Barton ideasman42 at gmail.com
Sun Dec 18 13:54:51 CET 2011


Revision: 42706
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42706
Author:   campbellbarton
Date:     2011-12-18 12:54:50 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
cleanup of weight paint color setting code, no functional changes

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
    trunk/blender/source/blender/blenlib/intern/bpath.c

Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2011-12-18 12:51:50 UTC (rev 42705)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2011-12-18 12:54:50 UTC (rev 42706)
@@ -642,67 +642,71 @@
 	CALC_WP_AUTO_NORMALIZE= (1<<1)
 };
 
+void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input)
+{
+	float colf[4];
+
+	if(coba) do_colorband(coba, input, colf);
+	else     weight_to_rgb(colf, input);
+
+	r_col[3] = (unsigned char)(colf[0] * 255.0f);
+	r_col[2] = (unsigned char)(colf[1] * 255.0f);
+	r_col[1] = (unsigned char)(colf[2] * 255.0f);
+	r_col[0] = 255;
+}
+
+
 static void calc_weightpaint_vert_color(
-        Object *ob, const int defbase_tot, ColorBand *coba, int vert, unsigned char *col,
-        const char *dg_flags, int selected, int UNUSED(unselected), const int draw_flag)
+        unsigned char r_col[4],
+        MDeformVert *dv, ColorBand *coba,
+        const int defbase_tot, const int defbase_act,
+        const char *dg_flags,
+        const int selected, const int draw_flag)
 {
-	Mesh *me = ob->data;
 	float input = 0.0f;
 	
 	int make_black= FALSE;
 
-	if (me->dvert) {
-		MDeformVert *dvert= &me->dvert[vert];
+	if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
+		int was_a_nonzero= FALSE;
+		int i;
 
-		if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
-			int was_a_nonzero= FALSE;
-			int i;
-
-			MDeformWeight *dw= dvert->dw;
-			for (i = dvert->totweight; i > 0; i--, dw++) {
-				/* in multipaint, get the average if auto normalize is inactive
-				 * get the sum if it is active */
-				if (dw->def_nr < defbase_tot) {
-					if (dg_flags[dw->def_nr]) {
-						if (dw->weight) {
-							input += dw->weight;
-							was_a_nonzero= TRUE;
-						}
+		MDeformWeight *dw= dv->dw;
+		for (i = dv->totweight; i > 0; i--, dw++) {
+			/* in multipaint, get the average if auto normalize is inactive
+			 * get the sum if it is active */
+			if (dw->def_nr < defbase_tot) {
+				if (dg_flags[dw->def_nr]) {
+					if (dw->weight) {
+						input += dw->weight;
+						was_a_nonzero= TRUE;
 					}
 				}
 			}
+		}
 
-			/* make it black if the selected groups have no weight on a vertex */
-			if (was_a_nonzero == FALSE) {
-				make_black = TRUE;
-			}
-			else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) {
-				input /= selected; /* get the average */
-			}
+		/* make it black if the selected groups have no weight on a vertex */
+		if (was_a_nonzero == FALSE) {
+			make_black = TRUE;
 		}
-		else {
-			/* default, non tricky behavior */
-			input= defvert_find_weight(dvert, ob->actdef-1);
+		else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) {
+			input /= selected; /* get the average */
 		}
 	}
-	
-	if (make_black) {
-		col[3] = 0;
-		col[2] = 0;
-		col[1] = 0;
-		col[0] = 255;
+	else {
+		/* default, non tricky behavior */
+		input= defvert_find_weight(dv, defbase_act);
 	}
+
+	if (make_black) { /* TODO, theme color */
+		r_col[3] = 0;
+		r_col[2] = 0;
+		r_col[1] = 0;
+		r_col[0] = 255;
+	}
 	else {
-		float colf[4];
 		CLAMP(input, 0.0f, 1.0f);
-
-		if(coba) do_colorband(coba, input, colf);
-		else     weight_to_rgb(colf, input);
-
-		col[3] = (unsigned char)(colf[0] * 255.0f);
-		col[2] = (unsigned char)(colf[1] * 255.0f);
-		col[1] = (unsigned char)(colf[2] * 255.0f);
-		col[0] = 255;
+		weightpaint_color(r_col, coba, input);
 	}
 }
 
@@ -716,28 +720,41 @@
 static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
 {
 	Mesh *me = ob->data;
-	MFace *mf = me->mface;
 	ColorBand *coba= stored_cb;	/* warning, not a local var */
-	unsigned char *wtcol;
-	int i;
-	
-	int defbase_tot = BLI_countlist(&ob->defbase);
-	char *defbase_sel = MEM_mallocN(defbase_tot * sizeof(char), __func__);
-	int selected = get_selected_defgroups(ob, defbase_sel, defbase_tot);
-	int unselected = defbase_tot - selected;
 
-	wtcol = MEM_callocN (sizeof (unsigned char) * me->totface*4*4, "weightmap");
-	
-	memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4);
-	for (i=0; i<me->totface; i++, mf++) {
-		calc_weightpaint_vert_color(ob, defbase_tot, coba, mf->v1, &wtcol[(i*4 + 0)*4], defbase_sel, selected, unselected, draw_flag);
-		calc_weightpaint_vert_color(ob, defbase_tot, coba, mf->v2, &wtcol[(i*4 + 1)*4], defbase_sel, selected, unselected, draw_flag);
-		calc_weightpaint_vert_color(ob, defbase_tot, coba, mf->v3, &wtcol[(i*4 + 2)*4], defbase_sel, selected, unselected, draw_flag);
-		if (mf->v4)
-			calc_weightpaint_vert_color(ob, defbase_tot, coba, mf->v4, &wtcol[(i*4 + 3)*4], defbase_sel, selected, unselected, draw_flag);
+	unsigned char *wtcol = MEM_mallocN (sizeof (unsigned char) * me->totface*4*4, "weightmap");
+
+	if (me->dvert) {
+		MDeformVert *dvert= me->dvert;
+		MFace *mf = me->mface;
+
+		const int defbase_tot = BLI_countlist(&ob->defbase);
+		const int defbase_act = ob->actdef-1;
+		char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__);
+		const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot);
+		/* const int unselected = defbase_tot - selected; */ /* UNUSED */
+
+		int i;
+
+		memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4);
+		for (i=0; i<me->totface; i++, mf++) {
+			unsigned int fidx= mf->v4 ? 3:2;
+			do {
+				calc_weightpaint_vert_color(&wtcol[(i*4 + fidx)*4],
+				                            &dvert[*(&mf->v1 + fidx)], coba,
+				                            defbase_tot, defbase_act,
+				                            dg_flags, selected, draw_flag);
+			} while (fidx--);
+		}
+
+		MEM_freeN(dg_flags);
 	}
-	
-	MEM_freeN(defbase_sel);
+	else {
+		/* no weights, fill in zero */
+		int col_i;
+		weightpaint_color((unsigned char *)&col_i, coba, 0.0f);
+		fill_vn_i((int *)wtcol, me->totface*4, col_i);
+	}
 
 	CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData);
 }

Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c	2011-12-18 12:51:50 UTC (rev 42705)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c	2011-12-18 12:54:50 UTC (rev 42706)
@@ -199,7 +199,11 @@
  - filesize: filesize for the file
 */
 #define MAX_RECUR 16
-static int findFileRecursive(char *filename_new, const char *dirname, const char *filename, int *filesize, int *recur_depth)
+static int findFileRecursive(char *filename_new,
+                             const char *dirname,
+                             const char *filename,
+                             int *filesize,
+                             int *recur_depth)
 {
 	/* file searching stuff */
 	DIR *dir;
@@ -314,7 +318,11 @@
 	}
 }
 
-static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], char path_file[FILE_MAXFILE], BPathVisitor visit_cb, const char *absbase, void *userdata)
+static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR],
+                                      char path_file[FILE_MAXFILE],
+                                      BPathVisitor visit_cb,
+                                      const char *absbase,
+                                      void *userdata)
 {
 	char path_src[FILE_MAX];
 	char path_dst[FILE_MAX];
@@ -496,7 +504,8 @@
 				SEQ_BEGIN(scene->ed, seq) {
 					if (SEQ_HAS_PATH(seq)) {
 						if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) {
-							rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, visit_cb, absbase, bpath_user_data);
+							rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name,
+							                           visit_cb, absbase, bpath_user_data);
 						}
 						else if (seq->type == SEQ_IMAGE) {
 							/* might want an option not to loop over all strips */
@@ -510,7 +519,8 @@
 							}
 
 							for(i= 0; i < len; i++, se++) {
-								rewrite_path_fixed_dirfile(seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data);
+								rewrite_path_fixed_dirfile(seq->strip->dir, se->name,
+								                           visit_cb, absbase, bpath_user_data);
 							}
 						}
 						else {




More information about the Bf-blender-cvs mailing list