[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42864] branches/vgroup_modifiers/source/ blender: Previous commit was not working as expected, except in some specific cases.

Bastien Montagne montagne29 at wanadoo.fr
Sat Dec 24 15:22:19 CET 2011


Revision: 42864
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42864
Author:   mont29
Date:     2011-12-24 14:22:16 +0000 (Sat, 24 Dec 2011)
Log Message:
-----------
Previous commit was not working as expected, except in some specific cases. So I had to change things a bit, and add a new "flags" memeber to DerivedMesh struct. For now, it only holds a DM_MOD_DO_WMCOL flag indicating to DynaPaint and WeightVG modifiers whether they should do weight preview or not (specifically, only in Object mode, or WP mode when modifier preview is enabled)!

As far as I can tell, it now works fine (and I?\226?\128?\153m quite happy with the viewing possibilities in WP mode), but not sure it is OK to edit such core struct for this? Will have to poke main devs?\226?\128?\166 :)

Modified Paths:
--------------
    branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h
    branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
    branches/vgroup_modifiers/source/blender/blenkernel/intern/dynamicpaint.c
    branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c

Modified: branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h	2011-12-24 14:09:43 UTC (rev 42863)
+++ branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h	2011-12-24 14:22:16 UTC (rev 42864)
@@ -68,6 +68,9 @@
 #define SUB_ELEMS_EDGE 2
 #define SUB_ELEMS_FACE 4
 
+/* DM flags. */
+#define DM_MOD_DO_WMCOL (1 << 0)
+
 typedef struct DMGridData {
 	float co[3];
 	float no[3];
@@ -95,6 +98,7 @@
 	struct GPUDrawObject *drawObject;
 	DerivedMeshType type;
 	float auto_bump_scale;
+	int flags; /* Various flags, currently only DM_MOD_DO_WMCOL. */
 
 	/* Misc. Queries */
 
@@ -372,6 +376,11 @@
  */
 int DM_release(DerivedMesh *dm);
 
+/* Utility functions to set, clear, and get a DM flag. */
+void DM_set_flag(DerivedMesh *dm, const int flag);
+void DM_clear_flag(DerivedMesh *dm, const int flag);
+int  DM_get_flag(DerivedMesh *dm, const int flag);
+
 /* utility function to convert a DerivedMesh to a Mesh
  */
 void DM_to_mesh(DerivedMesh *dm, struct Mesh *me);

Modified: branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c	2011-12-24 14:09:43 UTC (rev 42863)
+++ branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c	2011-12-24 14:22:16 UTC (rev 42864)
@@ -185,6 +185,7 @@
 	
 	dm->needsFree = 1;
 	dm->auto_bump_scale = -1.0f;
+	dm->flags = 0;
 }
 
 void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
@@ -205,6 +206,7 @@
 	DM_init_funcs(dm);
 
 	dm->needsFree = 1;
+	dm->flags = source->flags;
 }
 
 int DM_release(DerivedMesh *dm)
@@ -227,6 +229,21 @@
 	}
 }
 
+void DM_set_flag(DerivedMesh *dm, const int flag)
+{
+	dm->flags |= flag;
+}
+
+void DM_clear_flag(DerivedMesh *dm, const int flag)
+{
+	dm->flags &= ~flag;
+}
+
+int DM_get_flag(DerivedMesh *dm, const int flag)
+{
+	return (dm->flags & flag);
+}
+
 void DM_to_mesh(DerivedMesh *dm, Mesh *me)
 {
 	/* dm might depend on me, so we need to do everything with a local copy */
@@ -640,8 +657,6 @@
 enum {
 	CALC_WP_MULTIPAINT           = (1 << 0),
 	CALC_WP_AUTO_NORMALIZE       = (1 << 1),
-	CALC_WP_USE_MODIFIER_PREVIEW = (1 << 2),
-	CALC_WP_MODIFIED_WEIGHTS     = (1 << 3)
 };
 
 static ColorBand *stored_cb= NULL;
@@ -731,23 +746,10 @@
  * so leave this as is - campbell */
 static unsigned char *calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, ColorBand *coba)
 {
-	Mesh *me = ob->data;
-	unsigned char *wtcol_v;
-	MDeformVert *dv= NULL;
-	int numVerts;
+	MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
+	int numVerts = dm->getNumVerts(dm);
+	unsigned char *wtcol_v = MEM_mallocN (sizeof(unsigned char) * numVerts * 4, "weightmap_v");
 
-	if(draw_flag & CALC_WP_MODIFIED_WEIGHTS) {
-		numVerts = dm->getNumVerts(dm);
-		dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
-	}
-	else {
-		numVerts = me->totvert;
-		if(me->dvert)
-			dv = me->dvert;
-	}
-
-	wtcol_v = MEM_mallocN (sizeof(unsigned char) * numVerts * 4, "weightmap_v");
-
 	if (dv) {
 		unsigned char *wc = wtcol_v;
 		unsigned int i;
@@ -777,40 +779,27 @@
 {
 	ColorBand *coba= stored_cb;	/* warning, not a local var */
 
-	Mesh *me = ob->data;
-	MFace *mf = NULL;
-	int numFaces;
+	MFace *mf = dm->getFaceArray(dm);
+	int numFaces = dm->getNumFaces(dm);
 	unsigned char *wtcol_v;
-	unsigned char *wtcol_f;
+	unsigned char *wtcol_f = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
 	int i;
 
-	if (draw_flag & CALC_WP_MODIFIED_WEIGHTS) {
-		numFaces = dm->getNumFaces(dm);
-		mf = dm->getFaceArray(dm);
-	}
-	else {
-		numFaces = me->totface;
-		mf = me->mface;
-	}
-
-	wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, coba);
-	wtcol_f = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
 	/* If no CD_WEIGHT_MCOL existed yet, add a new one! */
 	if (!wtcol_f)
 		wtcol_f = CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numFaces);
-	/* If we have a valid existing CD_WEIGHT_MCOL and use modifiers' preview, nothing else to do! */
-	else if (draw_flag & CALC_WP_USE_MODIFIER_PREVIEW)
-		return;
 
-	for (i=0; i<numFaces; i++, mf++) {
-		unsigned int fidx= mf->v4 ? 3:2;
-		do {
-			copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
-			                (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
-		} while (fidx--);
+	if (wtcol_f) {
+		wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, coba);
+		for (i=0; i<numFaces; i++, mf++) {
+			unsigned int fidx= mf->v4 ? 3:2;
+			do {
+				copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4],
+				                (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]);
+			} while (fidx--);
+		}
+		MEM_freeN(wtcol_v);
 	}
-
-	MEM_freeN(wtcol_v);
 }
 
 /* new value for useDeform -1  (hack for the gameengine):
@@ -837,10 +826,12 @@
 	int has_multires = mmd != NULL, multires_applied = 0;
 	int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt;
 
-	int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) |
-	                (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0) |
-	                (scene->toolsettings->weights_preview == WP_WPREVIEW_MOD ? CALC_WP_USE_MODIFIER_PREVIEW : 0) |
-	                (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL ? CALC_WP_MODIFIED_WEIGHTS : 0));
+	const int draw_flag= ((scene->toolsettings->multipaint ? CALC_WP_MULTIPAINT : 0) |
+	                      (scene->toolsettings->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
+	const int do_wmcol = ((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT));
+	const int do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol;
+	const int do_mod_wmcol = (((scene->toolsettings->weights_preview == WP_WPREVIEW_MOD) && do_wmcol) ||
+	                          (ob->mode == OB_MODE_OBJECT));
 
 	if(mmd && !mmd->sculptlvl)
 		has_multires = 0;
@@ -1020,8 +1011,10 @@
 					CDDM_calc_normals(dm);
 				}
 
-				if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
-					add_weight_mcol_dm(ob, dm, draw_flag); 
+				if(do_wmcol)
+					add_weight_mcol_dm(ob, dm, draw_flag);
+				if(do_mod_wmcol)
+					DM_set_flag(dm, DM_MOD_DO_WMCOL);
 
 				/* Constructive modifiers need to have an origindex
 				 * otherwise they wont have anywhere to copy the data from.
@@ -1109,7 +1102,7 @@
 
 			/* In case of dynamic paint or WeightVG with enabled preview, make sure
 			 * preview mask remains for following modifiers. */
-			if (modifier_usesWMColPreview(md))
+			if (modifier_usesWMColPreview(md) && do_mod_wmcol)
 				append_mask |= CD_MASK_WEIGHT_MCOL;
 		}
 
@@ -1138,14 +1131,14 @@
 		CDDM_apply_vert_coords(finaldm, deformedVerts);
 		CDDM_calc_normals(finaldm);
 
-		if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
+		/* In case we need modified weights in CD_WEIGHT_MCOL, we have to re-compute it. */
+		if(do_final_wmcol)
 			add_weight_mcol_dm(ob, finaldm, draw_flag);
 	} else if(dm) {
 		finaldm = dm;
 
 		/* In case we need modified weights in CD_WEIGHT_MCOL, we have to re-compute it. */
-		if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT) &&
-		   (draw_flag & CALC_WP_MODIFIED_WEIGHTS))
+		if(do_final_wmcol)
 			add_weight_mcol_dm(ob, finaldm, draw_flag);
 	} else {
 		finaldm = CDDM_from_mesh(me, ob);
@@ -1155,7 +1148,8 @@
 			CDDM_calc_normals(finaldm);
 		}
 
-		if((dataMask & CD_MASK_WEIGHT_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT))
+		/* In this case, we should never have weight-modifying modifiers in stack... */
+		if(do_wmcol)
 			add_weight_mcol_dm(ob, finaldm, draw_flag);
 	}
 

Modified: branches/vgroup_modifiers/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/intern/dynamicpaint.c	2011-12-24 14:09:43 UTC (rev 42863)
+++ branches/vgroup_modifiers/source/blender/blenkernel/intern/dynamicpaint.c	2011-12-24 14:22:16 UTC (rev 42864)
@@ -1556,7 +1556,7 @@
 		/* loop through surfaces */
 		for (; surface; surface=surface->next) {
 			PaintSurfaceData *sData = surface->data;
-			const int do_preview = (surface->flags & MOD_DPAINT_PREVIEW);
+			const int do_preview = ((surface->flags & MOD_DPAINT_PREVIEW) && DM_get_flag(result, DM_MOD_DO_WMCOL));
 
 			if (surface && surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ && sData) {
 				if (!(surface->flags & (MOD_DPAINT_ACTIVE))) continue;

Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c	2011-12-24 14:09:43 UTC (rev 42863)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c	2011-12-24 14:22:16 UTC (rev 42864)
@@ -356,7 +356,7 @@
 	int numIdx = 0;
 	int i;
 	/* Flags. */
-	int do_prev = (wmd->common_flags & MOD_WVG_CFLAG_WEIGHT_PREVIEW);
+	int do_prev = ((wmd->common_flags & MOD_WVG_CFLAG_WEIGHT_PREVIEW) && DM_get_flag(dm, DM_MOD_DO_WMCOL));
 
 #if DO_PROFILE
 	TIMEIT_START(perf)




More information about the Bf-blender-cvs mailing list