[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29779] branches/soc-2010-nicolasbishop/ source/blender: Multires+mask bugfixes:

Nicholas Bishop nicholasbishop at gmail.com
Mon Jun 28 23:12:32 CEST 2010


Revision: 29779
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29779
Author:   nicholasbishop
Date:     2010-06-28 23:12:32 +0200 (Mon, 28 Jun 2010)

Log Message:
-----------
Multires+mask bugfixes:

* Crash when changing modes from sculptmode
* Crash when adding multires modifier on a mesh that already has paintmask layers
* Smooth brush eating holes in a mesh without a paintmask layer

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-28 18:40:17 UTC (rev 29778)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-28 21:12:32 UTC (rev 29779)
@@ -293,7 +293,7 @@
 	}
 }
 
-static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, int lvl)
+static void multires_reallocate_mdisps(Mesh *me, MDisps *mdisps, GridKey *gridkey, int lvl)
 {
 	int i;
 
@@ -306,6 +306,7 @@
 	for(i = 0; i < me->totface; ++i) {
 		int nvert = (me->mface[i].v4)? 4: 3;
 		int totelem = multires_grid_tot[lvl]*nvert;
+		int pmask_totlayer;
 		CustomData old, *cd = cd_facegrids + i;
 
 		/* Resize all existing layers */
@@ -314,6 +315,16 @@
 		CustomData_copy(&old, cd, ~0, CD_CALLOC, totelem);
 		CustomData_free(&old, 0);
 		CustomData_set_num_grid_elements(cd, totelem);
+
+		/* If multires modifier is added after mask layers were
+		   created, update the grids to have those layers as well */
+		if(gridkey) {
+			pmask_totlayer = CustomData_number_of_layers(cd, CD_PAINTMASK);
+			while(pmask_totlayer < gridkey->mask) {
+				CustomData_add_layer(cd, CD_PAINTMASK, CD_CALLOC, NULL, totelem);
+				++pmask_totlayer;
+			}
+		}
 	}
 
 	/* This will be replaced when we do CD_DISPS */
@@ -540,7 +551,7 @@
 		ccgSubSurf_updateLevels(ss, lvl, NULL, 0);
 
 		/* reallocate displacements */
-		multires_reallocate_mdisps(me, mdisps, totlvl); 
+		multires_reallocate_mdisps(me, mdisps, NULL, totlvl); 
 
 		/* compute displacements */
 		multiresModifier_disp_run(highdm, me, CALC_DISPS, subGridData, totlvl);
@@ -553,7 +564,7 @@
 	}
 	else {
 		/* only reallocate, nothing to upsample */
-		multires_reallocate_mdisps(me, mdisps, totlvl); 
+		multires_reallocate_mdisps(me, mdisps, NULL, totlvl); 
 	}
 
 	multires_set_tot_level(ob, mmd, totlvl);
@@ -640,16 +651,21 @@
 		MDisps *mdisp = &mdisps[i];
 		int S, x, y, j, gIndex = gridOffset[i];
 
-		/* when adding new faces in edit mode, need to allocate disps */
-		if(!mdisp->disps)
+		/* when adding new faces in edit mode, need to allocate disps;
+		   may need to allocate paintmask storage after adding multires as well */
+		if(!mdisp->disps ||
+		   (gridkey->mask && 
+		    (!stored_grids ||
+		     CustomData_number_of_layers(&stored_grids[i], CD_PAINTMASK) != gridkey->mask)))
 		//#pragma omp critical
 		{
-			multires_reallocate_mdisps(me, mdisps, totlvl);
+			multires_reallocate_mdisps(me, mdisps, gridkey, totlvl);
 		}
 
 		/* Check masks */
-		assert(stored_grids);
-		assert(CustomData_number_of_layers(&stored_grids[i], CD_PAINTMASK) == gridkey->mask);
+		assert(gridkey->mask == 0 || stored_grids);
+		if(stored_grids)
+			assert(CustomData_number_of_layers(&stored_grids[i], CD_PAINTMASK) == gridkey->mask);
 
 		for(S = 0; S < numVerts; ++S, ++gIndex) {
 			DMGridData *grid = gridData[gIndex];

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-06-28 18:40:17 UTC (rev 29778)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-06-28 21:12:32 UTC (rev 29779)
@@ -1059,7 +1059,9 @@
 				copy_v3_v3(co, GRIDELEM_CO_AT(data, x + y*gridsize, gridkey));
 
 				if(sculpt_brush_test(&test, co)) {
-					float fade = tex_strength(ss, brush, co, *GRIDELEM_MASK_AT(data, x + y*gridsize, gridkey), test.dist)*bstrength;
+					float mask = (gridkey->mask ?
+						      *GRIDELEM_MASK_AT(data, x + y*gridsize, gridkey) : 0);
+					float fade = tex_strength(ss, brush, co, mask, test.dist)*bstrength;
 					float avg[3], val[3];
 
 					copy_v3_v3(avg, tmpgrid[x + y*gridsize]);





More information about the Bf-blender-cvs mailing list