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

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jun 4 06:46:58 CEST 2011


Revision: 37163
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37163
Author:   jwilkins
Date:     2011-06-04 04:46:55 +0000 (Sat, 04 Jun 2011)
Log Message:
-----------
Revision: 29514
Author: nicholasbishop
Date: 1:19:07 AM, Thursday, June 17, 2010
Message:
Added undo for masks in sculpt.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.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

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-29483,29503
/trunk/blender:36833-37054
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29483,29503,29514
/trunk/blender:36833-37054

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 03:58:40 UTC (rev 37162)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/subsurf_ccg.c	2011-06-04 04:46:55 UTC (rev 37163)
@@ -74,7 +74,7 @@
 /* Declared extern in BKE_subsurf.h */
 DMGridElemKeyInfo GridElemKeyInfo[GRID_ELEM_KEY_TOTAL] = {
 	/*size,            has_mask,  no_offset,        mask_offset,      interp_count */
-	{sizeof(float)*6,  0,         sizeof(float)*3,  0,                3            },
+	{sizeof(float)*6,  0,         sizeof(float)*3,  -1,               3            },
 	{sizeof(float)*7,  1,         sizeof(float)*4,  sizeof(float)*3,  4            }
 };
 

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-04 03:58:40 UTC (rev 37162)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-04 04:46:55 UTC (rev 37163)
@@ -4412,8 +4412,14 @@
 	sculpt_update_mesh_elements(scene, sd, ob, 0);
 }
 
+static void update_cb(PBVHNode *node, void *UNUSED(data))
+{
+	BLI_pbvh_node_mark_update(node);
+}
+
 static int sculpt_area_hide_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+	Object *ob = CTX_data_active_object(C);
 	int show_all = RNA_boolean_get(op->ptr, "show_all");
 
 	if(show_all) {
@@ -4429,7 +4435,7 @@
 			if(ss->multires) {
 				BLI_pbvh_search_callback(ss->pbvh, NULL, NULL,
 							 update_cb, NULL);
-				multires_stitch_grids(ss->ob);
+				multires_stitch_grids(ob);
 			}
 
 			ED_region_tag_redraw(ar);

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-06-04 03:58:40 UTC (rev 37162)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-06-04 04:46:55 UTC (rev 37163)
@@ -77,7 +77,9 @@
 int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2]);
 
 /* Undo */
-
+/* Sculpt has its own undo, for each undo step there can be multiple
+   SculptUndoNodes, added as they are needed. SculptUndoNodes contain undo data
+   for one PBVHNode. */
 typedef struct SculptUndoNode {
 	struct SculptUndoNode *next, *prev;
 
@@ -104,6 +106,9 @@
 
 	/* shape keys */
 	char shapeName[sizeof(((KeyBlock *)0))->name];
+
+	/* paint mask */
+	float *pmask;
 } SculptUndoNode;
 
 SculptUndoNode *sculpt_undo_push_node(const Object *ob, PBVHNode *node);

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c	2011-06-04 03:58:40 UTC (rev 37162)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c	2011-06-04 04:46:55 UTC (rev 37163)
@@ -102,6 +102,8 @@
 			continue;
 
 		if(unode->maxvert) {
+			float *pmask;
+
 			/* regular mesh restore */
 			if(ss->totvert != unode->maxvert)
 				continue;
@@ -126,16 +128,30 @@
 			index= unode->index;
 			mvert= ss->mvert;
 
+			/* check for restoring paint mask */
+			if(unode->pmask) {
+				Mesh *me = get_mesh(ob);
+				pmask = CustomData_get_layer(&me->vdata,
+							     CD_PAINTMASK);
+			}
+
 			if (ss->kb) {
 				float (*vertCos)[3];
 				vertCos= key_to_vertcos(ob, ss->kb);
 
 				for(i=0; i<unode->totvert; i++) {
-					if(ss->modifiers_active) sculpt_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
+					if(ss->modifiers_active) {
+						sculpt_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
+					}
 					else {
-						if(unode->orig_co) swap_v3_v3(vertCos[index[i]], unode->orig_co[i]);
-						else swap_v3_v3(vertCos[index[i]], unode->co[i]);
+						if(unode->orig_co)
+							swap_v3_v3(vertCos[index[i]], unode->orig_co[i]);
+						else
+							swap_v3_v3(vertCos[index[i]], unode->co[i]);
 					}
+
+					if(unode->pmask)
+						SWAP(float, pmask[index[i]], unode->pmask[i]);
 				}
 
 				/* propagate new coords to keyblock */
@@ -146,21 +162,29 @@
 				BLI_pbvh_apply_vertCos(ss->pbvh, vertCos);
 
 				MEM_freeN(vertCos);
-			} else {
+			}
+			else {
 				for(i=0; i<unode->totvert; i++) {
-					if(ss->modifiers_active) sculpt_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
+					if(ss->modifiers_active) {
+						sculpt_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
+					}
 					else {
-						if(unode->orig_co) swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
-						else swap_v3_v3(mvert[index[i]].co, unode->co[i]);
+						if(unode->orig_co)
+							swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
+						else
+							swap_v3_v3(mvert[index[i]].co, unode->co[i]);
 					}
 					mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
+
+					if(unode->pmask)
+						SWAP(float, pmask[index[i]], unode->pmask[i]);
 				}
 			}
 		}
 		else if(unode->maxgrid && dm->getGridData) {
 			/* multires restore */
 			DMGridData **grids, *grid;
-			float (*co)[3];
+			float (*co)[3], *pmask;
 			int gridsize;
 			int gridkey;
 
@@ -174,11 +198,20 @@
 			gridkey= dm->getGridKey(dm);
 
 			co = unode->co;
+
+			if(unode->pmask)
+				pmask = unode->pmask;
+
 			for(j=0; j<unode->totgrid; j++) {
 				grid= grids[unode->grids[j]];
 
-				for(i=0; i<gridsize*gridsize; i++, co++)
+				for(i=0; i<gridsize*gridsize; i++, co++) {
 					swap_v3_v3(GRIDELEM_CO_AT(grid, i, gridkey), co[0]);
+					if(pmask) {
+						SWAP(float, *GRIDELEM_MASK_AT(grid, i, gridkey), *pmask);
+						++pmask;
+					}
+				}
 			}
 		}
 
@@ -231,6 +264,8 @@
 			MEM_freeN(unode->layer_disp);
 		if(unode->orig_co)
 			MEM_freeN(unode->orig_co);
+		if(unode->pmask)
+			MEM_freeN(unode->pmask);
 	}
 }
 
@@ -254,7 +289,7 @@
 	ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
 	SculptSession *ss = ob->sculpt;
 	SculptUndoNode *unode;
-	int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
+	int totvert, allvert, totgrid, maxgrid, gridsize, *grids, gridkey;
 
 	/* list is manipulated by multiple threads, so we lock */
 	BLI_lock_thread(LOCK_CUSTOM1);
@@ -270,7 +305,7 @@
 
 	BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
 	BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
-		&maxgrid, &gridsize, NULL, NULL, NULL);
+		&maxgrid, &gridsize, NULL, NULL, &gridkey);
 
 	unode->totvert= totvert;
 	/* we will use this while sculpting, is mapalloc slow to access then? */
@@ -285,11 +320,17 @@
 		unode->totgrid= totgrid;
 		unode->gridsize= gridsize;
 		unode->grids= MEM_mapallocN(sizeof(int)*totgrid, "SculptUndoNode.grids");
+
+		if(GRIDELEM_HAS_MASK(gridkey))
+			unode->pmask= MEM_mapallocN(sizeof(float)*allvert, "SculptUndoNode.pmask");
 	}
 	else {
 		/* regular mesh */
 		unode->maxvert= ss->totvert;
 		unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index");
+
+		if(CustomData_get_layer(&get_mesh(ob)->vdata, CD_PAINTMASK))
+			unode->pmask= MEM_mapallocN(sizeof(float)*allvert, "SculptUndoNode.pmask");
 	}
 
 	if(ss->modifiers_active)
@@ -303,12 +344,20 @@
 
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
 			copy_v3_v3(unode->co[vd.i], vd.co);
-			if(vd.no) VECCOPY(unode->no[vd.i], vd.no)
-			else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
-			if(vd.vert_indices) unode->index[vd.i]= vd.vert_indices[vd.i];
 
+			if(vd.no)
+				VECCOPY(unode->no[vd.i], vd.no)
+			else
+				normal_float_to_short_v3(unode->no[vd.i], vd.fno);
+
+			if(vd.vert_indices)
+				unode->index[vd.i]= vd.vert_indices[vd.i];
+
 			if(ss->modifiers_active)
 				copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]);
+
+			if(vd.mask)
+				unode->pmask[vd.i]= *vd.mask;
 		}
 		BLI_pbvh_vertex_iter_end;
 	}




More information about the Bf-blender-cvs mailing list