[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30884] branches/soc-2010-nicolasbishop/ source/blender: == Paint/PBVH ==

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 30 02:55:37 CEST 2010


Revision: 30884
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30884
Author:   nicholasbishop
Date:     2010-07-30 02:55:37 +0200 (Fri, 30 Jul 2010)

Log Message:
-----------
== Paint/PBVH ==

Undo refactor

* Renamed sculpt_undo.c to pbvh_undo.c
* Modified node push take a flag (PBVHUndoFlag) that controls what data gets pushed
* Changed sculpt code to only push coords, changed masking to only push paint masks
* Added undo code to save/restore mcols too, but not used yet
* Fixed a weight paint crash

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_dmgrid.h
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt_intern.h

Added Paths:
-----------
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c

Removed Paths:
-------------
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt_undo.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_dmgrid.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_dmgrid.h	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_dmgrid.h	2010-07-30 00:55:37 UTC (rev 30884)
@@ -1,6 +1,8 @@
 #ifndef BKE_DMGRID_H
 #define BKE_DMGRID_H
 
+struct CustomData;
+
 /* Each grid element can contain zero or more layers of coordinates,
    paint masks, and normals; these numbers are stored in the GridKey
 
@@ -45,4 +47,8 @@
 #define GRIDELEM_MASK_AT(_grid, _elem, _key) GRIDELEM_MASK(GRIDELEM_AT(_grid, _elem, _key), _key)
 #define GRIDELEM_NO_AT(_grid, _elem, _key) GRIDELEM_NO(GRIDELEM_AT(_grid, _elem, _key), _key)
 
+/* returns the active gridelem layer offset for either colors
+   or masks, -1 if not found */
+int gridelem_active_offset(struct CustomData *data, GridKey *gridkey, int type);
+
 #endif

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -67,6 +67,38 @@
 
 #include "CCGSubSurf.h"
 
+/* From BKE_dmgrid.h */
+int gridelem_active_offset(CustomData *data, GridKey *gridkey, int type)
+{
+	char (*names)[32] = NULL;
+	int active, tot, i;
+
+	active = CustomData_get_active_layer_index(data, type);
+	
+	if(active == -1)
+		return -1;
+
+	switch(type) {
+	case CD_MCOL:
+		tot = gridkey->color;
+		names = gridkey->color_names;
+		break;
+	case CD_PAINTMASK:
+		tot = gridkey->mask;
+		names = gridkey->mask_names;
+		break;
+	default:
+		return -1;
+	}
+
+	for(i = 0; i < tot; ++i) {
+		if(!strcmp(names[i], data->layers[active].name))
+			return i;
+	}
+
+	return -1;
+}
+
 static int ccgDM_getVertMapIndex(CCGSubSurf *ss, CCGVert *v);
 static int ccgDM_getEdgeMapIndex(CCGSubSurf *ss, CCGEdge *e);
 static int ccgDM_getFaceMapIndex(CCGSubSurf *ss, CCGFace *f);

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -1349,7 +1349,7 @@
 {
 	if(bvh->grids) {
 		if(totvert) *totvert= node->totprim*bvh->gridsize*bvh->gridsize;
-		if(uniquevert) *uniquevert= *totvert;
+		if(uniquevert) *uniquevert= node->totprim*bvh->gridsize*bvh->gridsize;
 	}
 	else {
 		if(totvert) *totvert= node->uniq_verts + node->face_verts;

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-07-30 00:55:37 UTC (rev 30884)
@@ -222,5 +222,27 @@
 void PAINT_OT_mask_set(struct wmOperatorType *ot);
 void PAINT_OT_mask_from_texture(struct wmOperatorType *ot);
 
+/* pbvh_undo.c */
+typedef enum {
+	PBVH_UNDO_CO_NO = (1<<0),
+	PBVH_UNDO_PMASK = (1<<1),
+	PBVH_UNDO_COLOR = (1<<2)
+} PBVHUndoFlag;
+
+typedef struct PBVHUndoNode PBVHUndoNode;
+
+PBVHUndoNode *pbvh_undo_push_node(PBVHNode *node, PBVHUndoFlag flag, struct Object *ob);
+void pbvh_undo_push_begin(char *name);
+void pbvh_undo_push_end(void);
+/* undo node access */
+PBVHUndoNode *pbvh_undo_get_node(struct PBVHNode *node);
+typedef float (*pbvh_undo_f3)[3];
+typedef short (*pbvh_undo_s3)[3];
+int pbvh_undo_node_totvert(PBVHUndoNode *unode);
+pbvh_undo_f3 pbvh_undo_node_co(PBVHUndoNode *unode);
+pbvh_undo_s3 pbvh_undo_node_no(PBVHUndoNode *unode);
+float *pbvh_undo_node_layer_disp(PBVHUndoNode *unode);
+void pbvh_undo_node_set_layer_disp(PBVHUndoNode *unode, float *layer_disp);
+
 #endif /* ED_PAINT_INTERN_H */
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -82,7 +82,7 @@
 		PBVHVertexIter vd;
 		PaintStrokeTest test;
 		
-		/* XXX: sculpt_undo_push_node(ob, nodes[n]); */
+		pbvh_undo_push_node(nodes[n], PBVH_UNDO_PMASK, ob);
 		paint_stroke_test_init(&test, stroke);
 
 		BLI_pbvh_vertex_iter_begin(ob->paint->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
@@ -200,7 +200,6 @@
 	Mesh *me;
 	struct MultiresModifierData *mmd;
 	PaintSession *ps;
-	SculptSession *ss;
 	MTex *tex_slot;
 	DerivedMesh *dm = NULL;
 	PBVH *pbvh;
@@ -214,12 +213,10 @@
 	scene = CTX_data_scene(C);
 	ob = CTX_data_active_object(C);
 	ps = ob->paint;
-	ss = ps->sculpt;
 	me = get_mesh(ob);
 	mmd = paint_multires_active(scene, ob);
 	
-	if(ss) // TODO
-		sculpt_undo_push_begin("Paint mask from texture");
+	pbvh_undo_push_begin("Paint mask from texture");
 
 	active = CustomData_get_active_layer(&me->vdata, CD_PAINTMASK);
 
@@ -256,8 +253,7 @@
 			GridKey *gridkey;
 			int *grid_indices, totgrid, gridsize;
 
-			if(ss) // TODO
-				sculpt_undo_push_node(ob, nodes[n]);
+			pbvh_undo_push_node(nodes[n], PBVH_UNDO_PMASK, ob);
 
 			BLI_pbvh_node_get_grids(pbvh, nodes[n], &grid_indices,
 						&totgrid, NULL, &gridsize,
@@ -291,8 +287,7 @@
 			MFace *mface;
 			int *face_indices, totface;
 
-			if(ss) // TODO
-				sculpt_undo_push_node(ob, nodes[n]);
+			pbvh_undo_push_node(nodes[n], PBVH_UNDO_PMASK, ob);
 
 			BLI_pbvh_node_get_faces(pbvh, nodes[n], &mface,
 						&face_indices, NULL, &totface);
@@ -316,8 +311,7 @@
 	
 	MEM_freeN(nodes);
 
-	if(ss) // TODO
-		sculpt_undo_push_end();
+	pbvh_undo_push_end();
 
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 	
@@ -356,14 +350,12 @@
 	DerivedMesh *dm;
 	struct MultiresModifierData *mmd;
 	PaintSession *ps;
-	SculptSession *ss;
 	Mesh *me;
 	PBVH *pbvh;
 
 	scene = CTX_data_scene(C);
 	ob = CTX_data_active_object(C);
 	ps = ob->paint;
-	ss = ps->sculpt;
 	me = get_mesh(ob);
 	mmd = paint_multires_active(scene, ob);
 
@@ -376,14 +368,12 @@
 
 		BLI_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
 
-		if(ss) // TODO
-			sculpt_undo_push_begin("Paint mask fill");
+		pbvh_undo_push_begin("Paint mask fill");
 
 		for(n=0; n<totnode; n++) {
 			PBVHVertexIter vd;
 
-			if(ss) // TODO
-				sculpt_undo_push_node(ob, nodes[n]);
+			pbvh_undo_push_node(nodes[n], PBVH_UNDO_PMASK, ob);
 
 			BLI_pbvh_vertex_iter_begin(pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
 				if(vd.mask_active)
@@ -400,8 +390,7 @@
 		if(mmd)
 			multires_mark_as_modified(ob);
 
-		if(ss) // TODO
-			sculpt_undo_push_end();
+		pbvh_undo_push_end();
 
 		WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
 	}

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -1048,7 +1048,7 @@
 	}
 
 	// XXX: temporary check for sculpt mode until things are more unified
-	if(stroke->vc.obact->paint->sculpt) {
+	if(stroke->vc.obact->paint && stroke->vc.obact->paint->sculpt) {
 		float delta[3];
 
 		brush_jitter_pos(stroke->brush, mouse_in, stroke->mouse);

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c	2010-07-30 00:20:05 UTC (rev 30883)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -1815,24 +1815,6 @@
 	BLI_pbvh_vertex_iter_end;
 }
 
-static int vpaint_find_gridkey_active_layer(CustomData *fdata, GridKey *gridkey)
-{
-	int active, i;
-
-	active = CustomData_get_active_layer_index(fdata, CD_MCOL);
-	
-	if(active == -1)
-		return -1;
-
-	for(i = 0; i < gridkey->color; ++i) {
-		if(!strcmp(gridkey->color_names[i],
-			   fdata->layers[active].name))
-			return i;
-	}
-
-	return -1;
-}
-
 static void vpaint_nodes(VPaint *vp, PaintStroke *stroke,
 			 Scene *scene, Object *ob,
 			 PBVHNode **nodes, int totnode)
@@ -1858,8 +1840,7 @@
 						&totgrid, NULL, &gridsize, &grids,
 						NULL, &gridkey);
 
-			active = vpaint_find_gridkey_active_layer(fdata,
-								  gridkey);
+			active = gridelem_active_offset(fdata, gridkey, CD_MCOL);
 
 			if(active != -1) {
 				if(blur) {
@@ -2018,8 +1999,7 @@
 						NULL, NULL, &gridsize, &grids,
 						NULL, &gridkey);
 
-			active = vpaint_find_gridkey_active_layer(fdata,
-								  gridkey);
+			active = gridelem_active_offset(fdata, gridkey, CD_MCOL);
 
 			if(active != -1) {
 				vpaint_color_single_gridelem(brush,

Copied: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c (from rev 30791, branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt_undo.c)
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c	                        (rev 0)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/pbvh_undo.c	2010-07-30 00:55:37 UTC (rev 30884)
@@ -0,0 +1,594 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list