[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29662] branches/soc-2010-nicolasbishop/ source/blender: Enabled multiple paint mask layers for both regular and multires meshes.

Nicholas Bishop nicholasbishop at gmail.com
Thu Jun 24 01:29:35 CEST 2010


Revision: 29662
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29662
Author:   nicholasbishop
Date:     2010-06-24 01:29:35 +0200 (Thu, 24 Jun 2010)

Log Message:
-----------
Enabled multiple paint mask layers for both regular and multires meshes.

* Iteration over vertices in the PBVH now has two mask components, the active mask, which is editable by the mask brush, and the combined mask, which adds all the mask layers together (clamped to [0,1]), and is used to mask off other brushes
* Layer adds and removes are handled by the paint undo system used in sculpt mode
* Added a new customdata function that adds a layer at an offset (into other layers of its type.)

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.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/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h	2010-06-23 22:51:26 UTC (rev 29661)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_customdata.h	2010-06-23 23:29:35 UTC (rev 29662)
@@ -90,14 +90,18 @@
 void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctype,
 						   void *layer, int totelem, char *name);
 
-/* frees the active or first data layer with the give type.
+/* adds a layer and puts it at the specified offset */
+void *CustomData_add_layer_at_offset(struct CustomData *data, int type, int alloctype,
+				     void *layerdata, int totelem, int offset);
+
+/* frees the layer at index.
  * returns 1 on succes, 0 if no layer with the given type is found
  *
  * in editmode, use EM_free_data_layer instead of this function
  */
 int CustomData_free_layer(struct CustomData *data, int type, int totelem, int index);
 
-/* frees the layer index with the give type.
+/* frees the active layer of the give type.
  * returns 1 on succes, 0 if no layer with the given type is found
  *
  * in editmode, use EM_free_data_layer instead of this function

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-06-23 22:51:26 UTC (rev 29661)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-06-23 23:29:35 UTC (rev 29662)
@@ -849,7 +849,8 @@
 const CustomDataMask CD_MASK_DERIVEDMESH =
 	CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
 	CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
-	CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL;
+	CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_WEIGHT_MCOL |
+	CD_MASK_PAINTMASK;
 const CustomDataMask CD_MASK_BMESH = 
 	CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR;
 const CustomDataMask CD_MASK_FACECORNERS =
@@ -1276,7 +1277,7 @@
 	const LayerTypeInfo *typeInfo= layerType_getInfo(type);
 	
 	layer = customData_add_layer__internal(data, type, alloctype, layerdata,
-										   totelem, typeInfo->defaultname);
+					       totelem, typeInfo->defaultname);
 
 	if(layer)
 		return layer->data;
@@ -1284,6 +1285,32 @@
 	return NULL;
 }
 
+void *CustomData_add_layer_at_offset(CustomData *cd, int type, int alloctype,
+				     void *layerdata, int totelem, int offset)
+{
+	int type_first_layer, type_totlayer, i;
+	CustomDataLayer copy_of_new;
+
+	/* add the new layer as normal */
+	CustomData_add_layer(cd, type, alloctype, layerdata, totelem);
+
+	type_first_layer = CustomData_get_layer_index(cd, type);
+	type_totlayer = CustomData_number_of_layers(cd, type);
+	
+	/* make a copy of the new layer */
+	copy_of_new = cd->layers[type_first_layer + type_totlayer - 1];
+
+	/* move the old layers up to make room for the new layer */
+	for(i = type_first_layer + type_totlayer - 1;
+	    i > type_first_layer + offset; --i)
+		cd->layers[i] = cd->layers[i-1];
+
+	/* copy the new layer into the correct offset */
+	cd->layers[type_first_layer + offset] = copy_of_new;
+
+	return copy_of_new.data;
+}
+
 /*same as above but accepts a name*/
 void *CustomData_add_layer_named(CustomData *data, int type, int alloctype,
 						   void *layerdata, int totelem, char *name)

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-23 22:51:26 UTC (rev 29661)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-06-23 23:29:35 UTC (rev 29662)
@@ -447,11 +447,11 @@
 	return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0, 0);
 }
 
-static GridKey *create_gridkey(DerivedMesh *dm)
+static GridKey *create_gridkey(CustomData *cd)
 {
 	GridKey *gridkey = MEM_callocN(sizeof(GridKey), "create_gridkey");
 
-	GRIDELEM_KEY_INIT(gridkey, 1, 1, 1);
+	GRIDELEM_KEY_INIT(gridkey, 1, CustomData_number_of_layers(cd, CD_PAINTMASK), 1);
 
 	return gridkey;
 }
@@ -468,7 +468,7 @@
 	if(optimal)
 		smd.flags |= eSubsurfModifierFlag_ControlEdges;
 
-	return subsurf_make_derived_from_derived(dm, &smd, create_gridkey(dm), 0, NULL, 0, 0);
+	return subsurf_make_derived_from_derived(dm, &smd, create_gridkey(&get_mesh(ob)->vdata), 0, NULL, 0, 0);
 }
 
 static DMGridData **copy_grids(DMGridData **grids, int totgrid, int gridsize, GridKey *gridkey)
@@ -638,8 +638,7 @@
 	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;
+		int S, x, y, j, gIndex = gridOffset[i];
 
 		/* when adding new faces in edit mode, need to allocate disps */
 		if(!mdisp->disps)
@@ -648,20 +647,15 @@
 			multires_reallocate_mdisps(me, mdisps, totlvl);
 		}
 
-		if(stored_grids) {
-			stored_mask_layer = CustomData_get_layer(&stored_grids[i], CD_PAINTMASK);
+		/* Check masks */
+		assert(stored_grids);
+		assert(CustomData_number_of_layers(&stored_grids[i], CD_PAINTMASK) == gridkey->mask);
 
-			/* 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(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];
+			int stored_index = S*dGridSize*dGridSize;
+			float (*dispgrid)[3] = &mdisp->disps[stored_index];
 
 			for(y = 0; y < gridSize; y++) {
 				for(x = 0; x < gridSize; x++) {
@@ -673,9 +667,6 @@
 					float *no = GRIDELEM_NO_AT(subgrid, ccgdm_offset, gridkey);
 					float *data = dispgrid[stored_offset];
 
-					float *mask = GRIDELEM_MASK_AT(grid, ccgdm_offset, gridkey);
-					float *smask = GRIDELEM_MASK_AT(subgrid, ccgdm_offset, gridkey);
-
 					float tan_to_ob_mat[3][3], tx[3], ty[3], disp[3], d[3];
 
 					/* construct tangent space matrix */
@@ -716,7 +707,13 @@
 
 					
 					/* Paint Masks */
-					if(mask && smask && stored_mask) {
+					for(j = 0; j < gridkey->mask; ++j) {
+						float *mask = &GRIDELEM_MASK_AT(grid, ccgdm_offset, gridkey)[j];
+						float *smask = &GRIDELEM_MASK_AT(subgrid, ccgdm_offset, gridkey)[j];
+						float *stored_mask_layer = CustomData_get_layer_n(&stored_grids[i],
+												  CD_PAINTMASK, j);
+						float *stored_mask = &stored_mask_layer[stored_index];
+
 						switch(op) {
 						case APPLY_DISPS:
 							*mask = *smask + stored_mask[stored_offset];
@@ -797,7 +794,7 @@
 			for(i = 0; i < numGrids; ++i) {
 				for(j = 0; j < lowGridSize*lowGridSize; ++j) {
 					int k;
-					for(k = 0; k < 4 /* TODO */; ++k)
+					for(k = 0; k < GRIDELEM_INTERP_COUNT(gridkey); ++k)
 						((float*)GRIDELEM_AT(diffGrid, j, gridkey))[k] = ((float*)GRIDELEM_AT(gridData[i], j, gridkey))[k] - ((float*)GRIDELEM_AT(lowGridData[i], j, gridkey))[k];
 				}
 

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-23 22:51:26 UTC (rev 29661)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-06-23 23:29:35 UTC (rev 29662)
@@ -27,6 +27,7 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -437,30 +438,40 @@
 	MVert *mvert = dm->getVertArray(dm);
 	MEdge *medge = dm->getEdgeArray(dm);
 	MFace *mface = dm->getFaceArray(dm);
-	float *pmask;
 	MVert *mv;
 	MEdge *me;
 	MFace *mf;
+	float *vertData;
+	GridKey *gridkey = ccgSubSurf_getGridKey(ss);
+	int pmask_layer_count, pmask_first_layer;
 
 	ccgSubSurf_initFullSync(ss);
 
 	mv = mvert;
 	index = (int *)dm->getVertDataArray(dm, CD_ORIGINDEX);
-	pmask = CustomData_get_layer(&dm->vertData, CD_PAINTMASK);
+	pmask_layer_count = CustomData_number_of_layers(&dm->vertData, CD_PAINTMASK);
+	pmask_first_layer = CustomData_get_layer_index(&dm->vertData, CD_PAINTMASK);
+	vertData = MEM_callocN(GRIDELEM_SIZE(gridkey), "vertData");
+
+	assert(gridkey->mask == 0 || gridkey->mask == pmask_layer_count);
+
 	for(i = 0; i < totvert; i++, mv++) {
 		CCGVert *v;
+		int j;
 
-		/* 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;
 
+		/* copy paint mask data */
+		for(j = 0; j < gridkey->mask; ++j)
+			vertData[3 + j] = ((float*)dm->vertData.layers[pmask_first_layer+j].data)[i];
+
 		ccgSubSurf_syncVert(ss, SET_INT_IN_POINTER(i), vertData, 0, &v);
 
 		((int*)ccgSubSurf_getVertUserData(ss, v))[1] = (index)? *index++: i;
 	}
 
+	MEM_freeN(vertData);
+
 	me = medge;
 	index = (int *)dm->getEdgeDataArray(dm, CD_ORIGINDEX);
 	for(i = 0; i < totedge; i++, me++) {
@@ -2303,7 +2314,9 @@
 			   when the ccgdm gets remade, the assumption is that the topology
 			   does not change. */
 			ccgdm_create_grids(dm);
-			BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, (void**)ccgdm->gridFaces);
+			BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData,
+					      ccgdm->gridAdjacency, (void**)ccgdm->gridFaces,
+					      ccgDM_getGridKey(&ccgdm->dm));
 		}
 
 		ccgdm->pbvh = ob->sculpt->pbvh;
@@ -2326,7 +2339,7 @@
 		ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
 		BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency,
 				     numGrids, gridSize, gridkey, (void**)ccgdm->gridFaces,
-				     &ob->sculpt->hidden_areas);
+				     &get_mesh(ob)->vdata, &ob->sculpt->hidden_areas);
 		ccgdm->pbvh_draw = 1;
 	}
 	else if(ob->type == OB_MESH) {

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list