[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37177] branches/soc-2011-onion: Revision: 29662

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jun 4 17:43:02 CEST 2011


Revision: 37177
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37177
Author:   jwilkins
Date:     2011-06-04 15:43:02 +0000 (Sat, 04 Jun 2011)
Log Message:
-----------
Revision: 29662
Author: nicholasbishop
Date: 6:29:35 PM, Wednesday, June 23, 2010
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-2011-onion/source/blender/blenkernel/BKE_customdata.h
    branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h
    branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c
    branches/soc-2011-onion/source/blender/blenkernel/intern/mesh.c
    branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
    branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c

Property Changed:
----------------
    branches/soc-2011-onion/


Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29585,29596
/trunk/blender:36833-37054
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29585,29596,29662
/trunk/blender:36833-37054

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_customdata.h	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_customdata.h	2011-06-04 15:43:02 UTC (rev 37177)
@@ -98,14 +98,18 @@
 void *CustomData_add_layer_named(struct CustomData *data, int type, int alloctype,
 						   void *layer, int totelem, const 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-2011-onion/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_mesh.h	2011-06-04 15:43:02 UTC (rev 37177)
@@ -72,7 +72,7 @@
 float *get_mesh_orco_verts(struct Object *ob);
 void transform_mesh_orco_verts(struct Mesh *me, float (*orco)[3], int totvert, int invert);
 int test_index_face(struct MFace *mface, struct CustomData *mfdata, int mfindex, int nr);
-struct Mesh *get_mesh(struct Object *ob);
+struct Mesh *get_mesh(const struct Object *ob);
 void set_mesh(struct Object *ob, struct Mesh *me);
 void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
 int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *_totvert,

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c	2011-06-04 15:43:02 UTC (rev 37177)
@@ -899,7 +899,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 =
@@ -1325,7 +1326,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;
@@ -1333,6 +1334,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, const char *name)

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/mesh.c	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/mesh.c	2011-06-04 15:43:02 UTC (rev 37177)
@@ -523,7 +523,7 @@
 	return nr;
 }
 
-Mesh *get_mesh(Object *ob)
+Mesh *get_mesh(const Object *ob)
 {
 	
 	if(ob==NULL) return NULL;

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-06-04 15:43:02 UTC (rev 37177)
@@ -493,11 +493,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;
 }
@@ -513,7 +513,7 @@
 	if(optimal)
 		smd.flags |= eSubsurfModifierFlag_ControlEdges;
 
-	return subsurf_make_derived_from_derived(dm, &smd, create_gridkey(dm), 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
+	return subsurf_make_derived_from_derived(dm, &smd, create_gridkey(&get_mesh(ob)->vdata), 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
 }
 
 
@@ -812,8 +812,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)
@@ -822,20 +821,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++) {
@@ -847,9 +841,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 */
@@ -889,7 +880,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];
@@ -971,7 +968,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-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c	2011-06-04 14:57:25 UTC (rev 37176)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c	2011-06-04 15:43:02 UTC (rev 37177)
@@ -32,6 +32,7 @@
  */
 
 
+#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -444,30 +445,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;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list