[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40199] branches/soc-2011-radish: initial cleanup for weight paint branch

Campbell Barton ideasman42 at gmail.com
Wed Sep 14 04:04:29 CEST 2011


Revision: 40199
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40199
Author:   campbellbarton
Date:     2011-09-14 02:04:26 +0000 (Wed, 14 Sep 2011)
Log Message:
-----------
initial cleanup for weight paint branch
- move get_selected_defgroups & count_selected_defgroups into blenkernel
- split calc_weightpaint_vert_color() logic so its more obvious whats default and multipaint behavior

Modified Paths:
--------------
    branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py
    branches/soc-2011-radish/source/blender/blenkernel/BKE_armature.h
    branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c
    branches/soc-2011-radish/source/blender/blenkernel/intern/armature.c
    branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-radish/source/blender/editors/space_view3d/view3d_select.c

Modified: branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py
===================================================================
--- branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py	2011-09-14 01:54:04 UTC (rev 40198)
+++ branches/soc-2011-radish/release/scripts/startup/bl_ui/properties_data_mesh.py	2011-09-14 02:04:26 UTC (rev 40199)
@@ -135,8 +135,7 @@
 
         ob = context.object
         group = ob.vertex_groups.active
-        
-        
+
         rows = 2
         if group:
             rows = 5

Modified: branches/soc-2011-radish/source/blender/blenkernel/BKE_armature.h
===================================================================
--- branches/soc-2011-radish/source/blender/blenkernel/BKE_armature.h	2011-09-14 01:54:04 UTC (rev 40198)
+++ branches/soc-2011-radish/source/blender/blenkernel/BKE_armature.h	2011-09-14 02:04:26 UTC (rev 40199)
@@ -100,6 +100,9 @@
 void vec_roll_to_mat3(float *vec, float roll, float mat[][3]);
 void mat3_to_vec_roll(float mat[][3], float *vec, float *roll);
 
+char* get_selected_defgroups(struct Object *ob, int defcnt);
+int count_selected_defgroups(const char *list, int len);
+
 /* Common Conversions Between Co-ordinate Spaces */
 void armature_mat_world_to_pose(struct Object *ob, float inmat[][4], float outmat[][4]);
 void armature_loc_world_to_pose(struct Object *ob, float *inloc, float *outloc);

Modified: branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c	2011-09-14 01:54:04 UTC (rev 40198)
+++ branches/soc-2011-radish/source/blender/blenkernel/intern/DerivedMesh.c	2011-09-14 02:04:26 UTC (rev 40199)
@@ -62,6 +62,7 @@
 #include "BKE_paint.h"
 #include "BKE_texture.h"
 #include "BKE_multires.h"
+#include "BKE_armature.h"
 
 #include "BLO_sys_types.h" // for intptr_t support
 
@@ -73,8 +74,6 @@
 #include "GPU_material.h"
 
 extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
-// Jason was here, this is for multi-paint
-#include "ED_armature.h"
 
 ///////////////////////////////////
 ///////////////////////////////////
@@ -1678,47 +1677,58 @@
 	}
 }
 
-static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int unselected, int multipaint, int auto_normalize)
+/* draw_flag's for calc_weightpaint_vert_color */
+enum {
+	CALC_WP_MULTIPAINT= (1<<0),
+	CALC_WP_AUTO_NORMALIZE= (1<<1),
+};
+
+static void calc_weightpaint_vert_color(Object *ob, ColorBand *coba, int vert, unsigned char *col, char *dg_flags, int selected, int UNUSED(unselected), const int draw_flag)
 {
 	Mesh *me = ob->data;
-	float colf[4], input = 0.0f;// Jason
+	float colf[4], input = 0.0f;
 	int i;
-	char make_black = FALSE;
-	char was_a_nonzero = FALSE;
 
+	// Jason was here
+	int make_black= FALSE;
+
 	if (me->dvert) {
-		for (i=0; i<me->dvert[vert].totweight; i++) {
+		if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
 			// Jason was here
-			// in multipaint, get the average if auto normalize is inactive
-			// get the sum if it is active
-			if(multipaint && selected > 1) {
+			int was_a_nonzero= FALSE;
+			for (i=0; i<me->dvert[vert].totweight; i++) {
+				/* in multipaint, get the average if auto normalize is inactive
+				 * get the sum if it is active */
 				if(dg_flags[me->dvert[vert].dw[i].def_nr]) {
 					if(me->dvert[vert].dw[i].weight) {
-						input+=me->dvert[vert].dw[i].weight;
-						was_a_nonzero = TRUE;
+						input+= me->dvert[vert].dw[i].weight;
+						was_a_nonzero= TRUE;
 					}
 				}
-			} else if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) {
-				input+=me->dvert[vert].dw[i].weight;
 			}
-		}
-		
-		// Jason was here
-		// make it black if the selected groups have no weight on a vertex
-		if(!make_black && multipaint && selected > 1) {
-			if(!was_a_nonzero) {
+
+			/* make it black if the selected groups have no weight on a vertex */
+			if(was_a_nonzero == FALSE) {
 				make_black = TRUE;
-			} else if (!auto_normalize){
-				// get the average
-				input /= selected;
 			}
-
+			else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) {
+				input /= selected; /* get the average */
+			}
 		}
+		else {
+			/* default, non tricky behavior */
+			for (i=0; i<me->dvert[vert].totweight; i++) {
+				if (me->dvert[vert].dw[i].def_nr==ob->actdef-1) {
+					input+=me->dvert[vert].dw[i].weight;
+				}
+			}
+		}
 	}
 	
-	if(make_black) {
+	if (make_black) {
 		input = -1;
-	}else {
+	}
+	else {
 		CLAMP(input, 0.0f, 1.0f);
 	}
 	
@@ -1740,65 +1750,30 @@
 {
 	stored_cb= coba;
 }
-/* TODO move duplicates to header */
-/* Jason was here duplicate function in paint_vertex.c*/
-static char* get_selected_defgroups(Object *ob, int defcnt) {
-	bPoseChannel *chan;
-	bPose *pose;
-	bDeformGroup *defgroup;
-	//Bone *bone;
-	char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags");
-	int i;
-	Object *armob = ED_object_pose_armature(ob);
 
-	if(armob) {
-		pose = armob->pose;
-		for (chan=pose->chanbase.first; chan; chan=chan->next) {
-			for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) {
-				if(!strcmp(defgroup->name, chan->bone->name)) {
-					dg_flags[i] = (chan->bone->flag & BONE_SELECTED);
-				}
-			}
-		}
-	}
-	
-	return dg_flags;
-}
-/* TODO move duplicates to header */
-/* Jason was here duplicate function */
-static int count_true(char *list, int len)
+static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
 {
-	int i;
-	int cnt = 0;
-	for(i = 0; i < len; i++) {
-		if (list[i]) {
-			cnt++;
-		}
-	}
-	return cnt;
-}
-static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int multipaint, int auto_normalize)
-{
 	Mesh *me = ob->data;
 	MFace *mf = me->mface;
 	ColorBand *coba= stored_cb;	/* warning, not a local var */
 	unsigned char *wtcol;
 	int i;
+
 	// Jason was here
 	int defcnt = BLI_countlist(&ob->defbase);
 	char *dg_flags = get_selected_defgroups(ob, defcnt);
-	int selected = count_true(dg_flags, defcnt);
+	int selected = count_selected_defgroups(dg_flags, defcnt);
 	int unselected = defcnt - 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, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, multipaint, auto_normalize); 
-		calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, multipaint, auto_normalize); 
-		calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, multipaint, auto_normalize); 
+		calc_weightpaint_vert_color(ob, coba, mf->v1, &wtcol[(i*4 + 0)*4], dg_flags, selected, unselected, draw_flag);
+		calc_weightpaint_vert_color(ob, coba, mf->v2, &wtcol[(i*4 + 1)*4], dg_flags, selected, unselected, draw_flag);
+		calc_weightpaint_vert_color(ob, coba, mf->v3, &wtcol[(i*4 + 2)*4], dg_flags, selected, unselected, draw_flag);
 		if (mf->v4)
-			calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, multipaint, auto_normalize); 
+			calc_weightpaint_vert_color(ob, coba, mf->v4, &wtcol[(i*4 + 3)*4], dg_flags, selected, unselected, draw_flag);
 	}
 	// Jason
 	MEM_freeN(dg_flags);
@@ -1830,6 +1805,10 @@
 	int has_multires = mmd != NULL, multires_applied = 0;
 	int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt;
 
+	// Jason
+	int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) |
+	                (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
+
 	if(mmd && !mmd->sculptlvl)
 		has_multires = 0;
 
@@ -2009,7 +1988,7 @@
 				}
 
 				if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
-					add_weight_mcol_dm(ob, dm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason
+					add_weight_mcol_dm(ob, dm, draw_flag); // Jason
 
 				/* Constructive modifiers need to have an origindex
 				 * otherwise they wont have anywhere to copy the data from.
@@ -2121,7 +2100,7 @@
 		CDDM_calc_normals(finaldm);
 
 		if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
-			add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason
+			add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason
 	} else if(dm) {
 		finaldm = dm;
 	} else {
@@ -2133,7 +2112,7 @@
 		}
 
 		if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
-			add_weight_mcol_dm(ob, finaldm, scene->toolsettings->multipaint, scene->toolsettings->auto_normalize);// Jason
+			add_weight_mcol_dm(ob, finaldm, draw_flag);// Jason
 	}
 
 	/* add an orco layer if needed */

Modified: branches/soc-2011-radish/source/blender/blenkernel/intern/armature.c
===================================================================
--- branches/soc-2011-radish/source/blender/blenkernel/intern/armature.c	2011-09-14 01:54:04 UTC (rev 40198)
+++ branches/soc-2011-radish/source/blender/blenkernel/intern/armature.c	2011-09-14 02:04:26 UTC (rev 40199)
@@ -2465,3 +2465,42 @@
 		}
 	}
 }
+
+/* Jason was here */
+char* get_selected_defgroups(Object *ob, int defcnt)
+{
+	bPoseChannel *chan;
+	bPose *pose;
+	bDeformGroup *defgroup;
+	//Bone *bone;
+	char *dg_flags = MEM_callocN(defcnt*sizeof(char), "dg_selected_flags");
+	int i;
+	Object *armob = object_pose_armature_get(ob);
+
+	if(armob) {
+		pose = armob->pose;
+		for (chan=pose->chanbase.first; chan; chan=chan->next) {
+			for (i = 0, defgroup = ob->defbase.first; i < defcnt && defgroup; defgroup = defgroup->next, i++) {
+				if(!strcmp(defgroup->name, chan->bone->name)) {
+					dg_flags[i] = (chan->bone->flag & BONE_SELECTED);
+				}
+			}
+		}
+	}
+
+	return dg_flags;
+}
+
+/* TODO move duplicates to header */
+/* Jason was here duplicate function */
+int count_selected_defgroups(const char *list, int len)
+{
+	int i;
+	int cnt = 0;
+	for(i = 0; i < len; i++) {
+		if (list[i]) {
+			cnt++;
+		}
+	}
+	return cnt;
+}

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-09-14 01:54:04 UTC (rev 40198)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list