[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29284] branches/soc-2010-nicolasbishop/ source/blender: * Started integrating the customdata facegrids type.

Nicholas Bishop nicholasbishop at gmail.com
Sun Jun 6 23:13:03 CEST 2010


Revision: 29284
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29284
Author:   nicholasbishop
Date:     2010-06-06 23:13:03 +0200 (Sun, 06 Jun 2010)

Log Message:
-----------
* Started integrating the customdata facegrids type. For now it's used for storing paintmasks with multires, more to come here.
* Updated disp_run to update masks. I'm treating mask layers as actual values rather than displacements as is done with mdisps; results look better this way I think.
* Added color buffer updating for VBOs built from grids.
* Changed the paint_mask_set operator to update multires too.

Notes
* For now I've hardcoded the use of mask data into DMGridData and other places. We don't actually always want that extra float though, that's temporary. Plan is to set up something similar to the way CCGSubsurf deals with variable-sized vert/edge/face data.
* This commit enables all the calculations needed to create, show, and update masks, but they aren't used for sculpting yet, that comes soon

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h	2010-06-06 20:19:22 UTC (rev 29283)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_DerivedMesh.h	2010-06-06 21:13:03 UTC (rev 29284)
@@ -70,6 +70,7 @@
 
 typedef struct DMGridData {
 	float co[3];
+	float mask;
 	float no[3];
 } DMGridData;
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-06-06 20:19:22 UTC (rev 29283)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-06-06 21:13:03 UTC (rev 29284)
@@ -819,7 +819,7 @@
 const CustomDataMask CD_MASK_MESH =
 	CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE |
 	CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL |
-	CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS;
+	CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_PAINTMASK;
 const CustomDataMask CD_MASK_EDITMESH =
 	CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
 	CD_MASK_MCOL|CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS;

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-06 20:19:22 UTC (rev 29283)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-06 21:13:03 UTC (rev 29284)
@@ -297,6 +297,26 @@
 {
 	int i;
 
+	CustomData *cd_facegrids;
+
+	cd_facegrids = CustomData_get_layer(&me->fdata, CD_FACEGRID);
+	if(!cd_facegrids)
+		cd_facegrids = CustomData_add_layer(&me->fdata, CD_FACEGRID, CD_CALLOC, NULL, me->totface);
+
+	for(i = 0; i < me->totface; ++i) {
+		int nvert = (me->mface[i].v4)? 4: 3;
+		int totelem = multires_grid_tot[lvl]*nvert;
+		CustomData old, *cd = cd_facegrids + i;
+
+		/* Resize all existing layers */
+		old = *cd;
+		memset(cd, 0, sizeof(*cd));
+		CustomData_copy(&old, cd, ~0, CD_CALLOC, totelem);
+		CustomData_free(&old, 0);
+	}
+
+	/* This will be replaced when we do CD_DISPS */
+
 	/* reallocate displacements to be filled in */
 	for(i = 0; i < me->totface; ++i) {
 		int nvert = (me->mface[i].v4)? 4: 3;
@@ -338,7 +358,7 @@
 	}
 }
 
-static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int sizeA, int sizeB)
+static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int finterpCount, int sizeA, int sizeB)
 {
 	int x, y, j, skip;
 
@@ -347,14 +367,14 @@
 
 		for(j = 0, y = 0; y < sizeB; y++)
 			for(x = 0; x < sizeB; x++, j++)
-				copy_v3_v3(gridA[y*skip*sizeA + x*skip].co, gridB[j].co);
+				memcpy(&gridA[y*skip*sizeA + x*skip], &gridB[j], sizeof(float) * finterpCount);
 	}
 	else {
 		skip = (sizeB-1)/(sizeA-1);
 
 		for(j = 0, y = 0; y < sizeA; y++)
 			for(x = 0; x < sizeA; x++, j++)
-				copy_v3_v3(gridA[j].co, gridB[y*skip*sizeB + x*skip].co);
+				memcpy(&gridA[j], &gridB[y*skip*sizeB + x*skip], sizeof(float) * finterpCount);
 	}
 }
 
@@ -486,7 +506,7 @@
 			memcpy(subGridData[i], highGridData[i], sizeof(DMGridData)*highGridSize*highGridSize);
 
 			/* overwrite with current displaced grids */
-			multires_copy_dm_grid(highGridData[i], lowGridData[i], highGridSize, lowGridSize);
+			multires_copy_dm_grid(highGridData[i], lowGridData[i], 4 /* TODO */, highGridSize, lowGridSize);
 		}
 
 		/* low lower level dm no longer needed at this point */
@@ -541,12 +561,32 @@
 	}
 }
 
+#if 0
+static void debug_print_paintmask_grids(CustomData *grids, int gridsize)
+{
+	float *pmask;
+	int x, y;
+
+	printf("debug_print_paintmask_grids:\n");
+	pmask = CustomData_get_layer(grids, CD_PAINTMASK);
+	
+	for(y = 0; y < gridsize; ++y) {
+		for(x = 0; x < gridsize; ++x, ++pmask)
+			printf("%.2f ", *pmask);
+		printf("\n");
+	}
+
+	printf("\n");
+}
+#endif
+
 static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DispOp op, DMGridData **oldGridData, int totlvl)
 {
 	CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm;
 	DMGridData **gridData, **subGridData;
 	MFace *mface = me->mface;
 	MDisps *mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
+	CustomData *stored_grids;
 	int *gridOffset;
 	int i, numGrids, gridSize, dGridSize, dSkip;
 
@@ -566,11 +606,14 @@
 	dGridSize = multires_side_tot[totlvl];
 	dSkip = (dGridSize-1)/(gridSize-1);
 
+	stored_grids = CustomData_get_layer(&me->fdata, CD_FACEGRID);
+
 	//#pragma omp parallel for private(i) schedule(static)
 	for(i = 0; i < me->totface; ++i) {
 		const int numVerts = mface[i].v4 ? 4 : 3;
 		MDisps *mdisp = &mdisps[i];
 		int S, x, y, gIndex = gridOffset[i];
+		float *stored_mask_layer;
 
 		/* when adding new faces in edit mode, need to allocate disps */
 		if(!mdisp->disps)
@@ -579,17 +622,36 @@
 			multires_reallocate_mdisps(me, mdisps, totlvl);
 		}
 
+		if(stored_grids) {
+			stored_mask_layer = CustomData_get_layer(&stored_grids[i], CD_PAINTMASK);
+
+			/* TODO: for now we just always have a paintmask layer */
+			if(!stored_mask_layer) {
+				stored_mask_layer = CustomData_add_layer(&stored_grids[i], CD_PAINTMASK, CD_CALLOC, NULL, dGridSize*dGridSize*numVerts);
+				for(x = 0; x < dGridSize*dGridSize*numVerts; ++x)
+					stored_mask_layer[x] = 1;
+			}
+		}
+
 		for(S = 0; S < numVerts; ++S, ++gIndex) {
 			DMGridData *grid = gridData[gIndex];
 			DMGridData *subgrid = subGridData[gIndex];
 			float (*dispgrid)[3] = &mdisp->disps[S*dGridSize*dGridSize];
+			float *stored_mask = &stored_mask_layer[S*dGridSize*dGridSize];
 
 			for(y = 0; y < gridSize; y++) {
 				for(x = 0; x < gridSize; x++) {
-					float *co = grid[x + y*gridSize].co;
-					float *sco = subgrid[x + y*gridSize].co;
-					float *no = subgrid[x + y*gridSize].no;
-					float *data = dispgrid[dGridSize*y*dSkip + x*dSkip];
+					int ccgdm_offset = x + y*gridSize;
+					int stored_offset = dGridSize*y*dSkip + x*dSkip;
+
+					float *co = grid[ccgdm_offset].co;
+					float *sco = subgrid[ccgdm_offset].co;
+					float *no = subgrid[ccgdm_offset].no;
+					float *data = dispgrid[stored_offset];
+
+					float *mask = &grid[ccgdm_offset].mask;
+					float *smask = &subgrid[ccgdm_offset].mask;
+
 					float tan_to_ob_mat[3][3], tx[3], ty[3], disp[3], d[3];
 
 					/* construct tangent space matrix */
@@ -627,6 +689,24 @@
 						add_v3_v3(data, d);
 						break;
 					}
+
+					
+					/* Paint Masks */
+					if(mask && smask && stored_mask) {
+						switch(op) {
+						case APPLY_DISPS:
+							*mask = stored_mask[stored_offset];
+							break;
+						case CALC_DISPS:
+							stored_mask[stored_offset] = *mask;
+							CLAMP(stored_mask[stored_offset], 0, 1);
+							break;
+						case ADD_DISPS:
+							stored_mask[stored_offset] = *mask;
+							CLAMP(stored_mask[stored_offset], 0, 1);
+							break;
+						}
+					}
 				}
 			}
 		}
@@ -691,10 +771,13 @@
 				memcpy(subGridData[i], highGridData[i], sizeof(DMGridData)*highGridSize*highGridSize);
 
 				/* write difference of subsurf and displaced low level into high subsurf */
-				for(j = 0; j < lowGridSize*lowGridSize; ++j)
-					sub_v3_v3v3(diffGrid[j].co, gridData[i][j].co, lowGridData[i][j].co);
+				for(j = 0; j < lowGridSize*lowGridSize; ++j) {
+					int k;
+					for(k = 0; k < 4 /* TODO */; ++k)
+						((float*)&diffGrid[j])[k] = ((float*)&gridData[i][j])[k] - ((float*)&lowGridData[i][j])[k];
+				}
 
-				multires_copy_dm_grid(highGridData[i], diffGrid, highGridSize, lowGridSize);
+				multires_copy_dm_grid(highGridData[i], diffGrid, 4 /* TODO */, highGridSize, lowGridSize);
 			}
 
 			/* lower level dm no longer needed at this point */

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-06-06 20:19:22 UTC (rev 29283)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-06-06 21:13:03 UTC (rev 29284)
@@ -115,7 +115,7 @@
 		ifc.vertUserSize = ifc.edgeUserSize = ifc.faceUserSize = 8;
 	}
 	ifc.vertDataSize = sizeof(DMGridData);
-	ifc.finterpCount = 3;
+	ifc.finterpCount = 4;
 
 	if (useArena) {
 		CCGAllocatorIFC allocatorIFC;
@@ -420,7 +420,7 @@
 }
 
 static void ss_sync_from_derivedmesh(CCGSubSurf *ss, DerivedMesh *dm,
-									 float (*vertexCos)[3], int useFlatSubdiv)
+				     float (*vertexCos)[3], int useFlatSubdiv)
 {
 	float creaseFactor = (float) ccgSubSurf_getSubdivisionLevels(ss);
 	CCGVertHDL fVerts[4];
@@ -432,6 +432,7 @@
 	MVert *mvert = dm->getVertArray(dm);
 	MEdge *medge = dm->getEdgeArray(dm);
 	MFace *mface = dm->getFaceArray(dm);
+	float *pmask;
 	MVert *mv;
 	MEdge *me;
 	MFace *mf;
@@ -440,15 +441,18 @@
 
 	mv = mvert;
 	index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
+	pmask = CustomData_get_layer(&dm->vertData, CD_PAINTMASK);
 	for(i = 0; i < totvert; i++, mv++) {
 		CCGVert *v;
 
-		if(vertexCos) {
-			ccgSubSurf_syncVert(ss, SET_INT_IN_POINTER(i), vertexCos[i], 0, &v);
-		} else {
-			ccgSubSurf_syncVert(ss, SET_INT_IN_POINTER(i), mv->co, 0, &v);
-		}
+		/* TODO: this will become more flexible; for now four floats is the right size */
+		float vertData[4];
 
+		copy_v3_v3(vertData, vertexCos ? vertexCos[i] : mv->co);
+		vertData[3] = pmask ? pmask[i] : 0;
+
+		ccgSubSurf_syncVert(ss, SET_INT_IN_POINTER(i), vertData, 0, &v);
+
 		((int*)ccgSubSurf_getVertUserData(ss, v))[1] = (index)? *index++: i;
 	}
 
@@ -477,7 +481,7 @@
 		fVerts[2] = SET_INT_IN_POINTER(mf->v3);
 		fVerts[3] = SET_INT_IN_POINTER(mf->v4);
 
-		// this is very bad, means mesh is internally consistent.
+		// this is very bad, means mesh is internally inconsistent.
 		// it is not really possible to continue without modifying
 		// other parts of code significantly to handle missing faces.
 		// since this really shouldn't even be possible we just bail.

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-06-06 20:19:22 UTC (rev 29283)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list