[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30162] branches/soc-2010-nicolasbishop: Begin updating vpaint to use the PBVH

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 9 23:27:29 CEST 2010


Revision: 30162
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30162
Author:   nicholasbishop
Date:     2010-07-09 23:27:29 +0200 (Fri, 09 Jul 2010)

Log Message:
-----------
Begin updating vpaint to use the PBVH
* Added a new flag (plus RNA/UI) to switch between old vpaint and new vpaint
* For new vpaint, draw using the PBVH. Lighting is enabled for new vpaint.
* Note that the full model is still being redrawn, partial redraw isn't enabled yet.
* For new vpaint, use the PBVH to determine which faces to paint on. Only mix brush works right now.

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
    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/gpu/intern/gpu_buffers.c
    branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-07-09 21:05:17 UTC (rev 30161)
+++ branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-07-09 21:27:29 UTC (rev 30162)
@@ -898,6 +898,7 @@
         col.prop(vpaint, "all_faces")
         col.prop(vpaint, "normals")
         col.prop(vpaint, "spray")
+        col.prop(vpaint, "backbuf")
 
 # Commented out because the Apply button isn't an operator yet, making these settings useless
 #		col.label(text="Gamma:")

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c	2010-07-09 21:05:17 UTC (rev 30161)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/cdderivedmesh.c	2010-07-09 21:27:29 UTC (rev 30162)
@@ -420,6 +420,39 @@
 	}
 }
 
+/* draw using the PBVH; returns true if drawing is done,
+   false if regular drawing should be used */
+static int cddm_draw_pbvh(DerivedMesh *dm, float (*partial_redraw_planes)[4],
+			  int (*setMaterial)(int, void *attribs),
+			  GPUDrawFlags drawflags)
+{
+	CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
+	MFace *mface = cddm->mface;
+	float (*face_nors)[3];
+
+	if(cddm->pbvh && cddm->pbvh_draw) {
+		if(dm->numFaceData) {
+			face_nors = CustomData_get_layer(&dm->faceData, CD_NORMAL);
+
+			/* should be per face */
+			if(setMaterial && !setMaterial(mface->mat_nr+1, NULL))
+				return 1;
+			if(mface->flag & ME_SMOOTH)
+				drawflags |= GPU_DRAW_SMOOTH;
+
+			glEnable(GL_LIGHTING);
+
+			BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, drawflags);
+
+			glDisable(GL_LIGHTING);
+		}
+
+		return 1;
+	}
+
+	return 0;
+}
+
 static void cdDM_drawFacesSolid(DerivedMesh *dm,
 				float (*partial_redraw_planes)[4],
 				int fast, int (*setMaterial)(int, void *attribs))
@@ -438,22 +471,8 @@
 	glVertex3fv(mvert[index].co);	\
 }
 
-	if(cddm->pbvh && cddm->pbvh_draw) {
-		if(dm->numFaceData) {
-			GPUDrawFlags drawflags = 0;
-			float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL);
-
-			/* should be per face */
-			if(!setMaterial(mface->mat_nr+1, NULL))
-				return;
-			if(mface->flag & ME_SMOOTH)
-				drawflags |= GPU_DRAW_SMOOTH;
-
-			BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, drawflags);
-		}
-
+	if(cddm_draw_pbvh(dm, partial_redraw_planes, setMaterial, 0))
 		return;
-	}
 
 	if( GPU_buffer_legacy(dm) ) {
 		DEBUG_VBO( "Using legacy code. cdDM_drawFacesSolid\n" );
@@ -791,6 +810,10 @@
 	float *nors= dm->getFaceDataArray(dm, CD_NORMAL);
 	int i, orig, *index = DM_get_face_data_layer(dm, CD_ORIGINDEX);
 
+	if(cddm_draw_pbvh(dm, NULL, NULL,
+			  useColors ? GPU_DRAW_ACTIVE_MCOL : 0))
+		return;
+
 	mc = DM_get_face_data_layer(dm, CD_ID_MCOL);
 	if(!mc)
 		mc = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);

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-09 21:05:17 UTC (rev 30161)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-07-09 21:27:29 UTC (rev 30162)
@@ -47,6 +47,7 @@
 struct ListBase;
 
 /* paint_stroke.c */
+typedef struct PaintStroke PaintStroke;
 typedef int (*StrokeGetLocation)(struct bContext *C, struct PaintStroke *stroke, float location[3], float mouse[2]);
 typedef int (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
 typedef void (*StrokeUpdateStep)(struct bContext *C, struct PaintStroke *stroke, struct PointerRNA *itemptr);

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-09 21:05:17 UTC (rev 30161)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-09 21:27:29 UTC (rev 30162)
@@ -53,7 +53,7 @@
 #include <float.h>
 #include <math.h>
 
-typedef struct PaintStroke {
+struct PaintStroke {
 	void *mode_data;
 	void *smooth_stroke_cursor;
 	wmTimer *timer;
@@ -74,7 +74,7 @@
 	StrokeTestStart test_start;
 	StrokeUpdateStep update_step;
 	StrokeDone done;
-} PaintStroke;
+};
 
 /*** Cursor ***/
 static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata) 

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-09 21:05:17 UTC (rev 30161)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c	2010-07-09 21:27:29 UTC (rev 30162)
@@ -276,9 +276,6 @@
 	//else
 
 	memset(me->mcol, 255, 4*sizeof(MCol)*me->totface);
-	
-	DAG_id_flush_update(&me->id, OB_RECALC_DATA);
-	
 }
 
 static void copy_vpaint_prev(VPaint *vp, unsigned int *mcol, int tot)
@@ -1406,7 +1403,7 @@
 				wpd->vgroup_mirror= actdef;
 		}
 	}
-	
+
 	return 1;
 }
 
@@ -1697,11 +1694,10 @@
 		return OPERATOR_PASS_THROUGH;
 	}
 	
-	if(me && me->mcol==NULL) make_vertexcol(ob);
-	
 	/* toggle: end vpaint */
 	if(ob->mode & OB_MODE_VERTEX_PAINT) {
-		
+		free_paintsession(ob);
+
 		ob->mode &= ~OB_MODE_VERTEX_PAINT;
 	}
 	else {
@@ -1712,15 +1708,26 @@
 		
 		if(vp==NULL)
 			vp= scene->toolsettings->vpaint= new_vpaint(0);
+
+		if(me->mcol==NULL)
+			make_vertexcol(ob);
+
+		create_paintsession(ob);
 		
 		paint_cursor_start(C, vertex_paint_poll);
 
 		paint_init(&vp->paint, PAINT_CURSOR_VERTEX_PAINT);
 	}
 	
-	if (me)
+	if(vp->flag & VP_BACKBUF)
 		/* update modifier stack for mapping requirements */
 		DAG_id_flush_update(&me->id, OB_RECALC_DATA);
+
+	/* create pbvh */
+	if(!(vp->flag & VP_BACKBUF) && ob->mode & OB_MODE_VERTEX_PAINT) {
+		DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_MCOL);
+		ob->paint->pbvh = dm->getPBVH(ob, dm);
+	}
 	
 	WM_event_add_notifier(C, NC_SCENE|ND_MODE, scene);
 	
@@ -1767,19 +1774,34 @@
 */
 
 typedef struct VPaintData {
-	ViewContext vc;
 	unsigned int paintcol;
 	int *indexar;
 	float *vertexcosnos;
 	float vpimat[3][3];
 } VPaintData;
 
+void paint_raycast_cb(PBVHNode *node, void *data_v)
+{
+	PaintStrokeRaycastData *data = data_v;
+
+	data->hit |= BLI_pbvh_node_raycast(data->ob->paint->pbvh, node, NULL,
+					   data->ray_start, data->ray_normal,
+					   &data->dist);
+}
+
+int vpaint_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2])
+{
+	// XXX: sculpt_stroke_modifiers_check(C, ss);
+	return paint_stroke_get_location(C, stroke, paint_raycast_cb, NULL, out, mouse, 0);		
+}
+
 static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *event)
 {
 	ToolSettings *ts= CTX_data_tool_settings(C);
 	struct PaintStroke *stroke = op->customdata;
 	VPaint *vp= ts->vpaint;
 	struct VPaintData *vpd;
+	ViewContext *vc = paint_stroke_view_context(stroke);
 	Object *ob= CTX_data_active_object(C);
 	Mesh *me;
 	float mat[4][4], imat[4][4];
@@ -1788,32 +1810,37 @@
 	me= get_mesh(ob);
 	if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH;
 	
-	if(me->mcol==NULL) make_vertexcol(ob);
 	if(me->mcol==NULL) return OPERATOR_CANCELLED;
 	
 	/* make mode data storage */
 	vpd= MEM_callocN(sizeof(struct VPaintData), "VPaintData");
 	paint_stroke_set_mode_data(stroke, vpd);
-	view3d_set_viewcontext(C, &vpd->vc);
 	
-	vpd->vertexcosnos= mesh_get_mapped_verts_nors(vpd->vc.scene, ob);
-	vpd->indexar= get_indexarray(me);
+	vpd->vertexcosnos= mesh_get_mapped_verts_nors(vc->scene, ob);
+	if(vp->flag & VP_BACKBUF)
+		vpd->indexar= get_indexarray(me);
 	vpd->paintcol= vpaint_get_current_col(vp);
 	
 	/* for filtering */
 	copy_vpaint_prev(vp, (unsigned int *)me->mcol, me->totface);
 	
 	/* some old cruft to sort out later */
-	mul_m4_m4m4(mat, ob->obmat, vpd->vc.rv3d->viewmat);
+	mul_m4_m4m4(mat, ob->obmat, vc->rv3d->viewmat);
 	invert_m4_m4(imat, mat);
 	copy_m3_m4(vpd->vpimat, imat);
 
+	if(!(CTX_data_tool_settings(C)->vpaint->flag & VP_BACKBUF)) {
+		Scene *scene = CTX_data_scene(C);
+		DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH|CD_MASK_MCOL);
+		ob->paint->pbvh = dm->getPBVH(ob, dm);
+	}
+
 	return 1;
 }
 
-static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2], float pressure, int flip)
+static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, ViewContext *vc, int index, float mval[2], float pressure, int flip)
 {
-	ViewContext *vc = &vpd->vc;
+	Object *ob = vc->obact;
 	Brush *brush = paint_brush(&vp->paint);
 	Mesh *me = get_mesh(ob);
 	MFace *mface= ((MFace*)me->mface) + index;
@@ -1845,29 +1872,28 @@
 	}
 }
 
-static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
+/* uses GL backbuf projection */
+static void vpaint_stroke_update_step_old(bContext *C, PaintStroke *stroke, PointerRNA *itemptr)
 {
-	ToolSettings *ts= CTX_data_tool_settings(C);
-	struct VPaintData *vpd = paint_stroke_mode_data(stroke);
-	VPaint *vp= ts->vpaint;
+	VPaint *vp= CTX_data_tool_settings(C)->vpaint;
+	VPaintData *vpd = paint_stroke_mode_data(stroke);
+	ViewContext *vc = paint_stroke_view_context(stroke);
 	Brush *brush = paint_brush(&vp->paint);
-	ViewContext *vc= &vpd->vc;
-	Object *ob= vc->obact;
-	Mesh *me= ob->data;
-	float mat[4][4];
+	Object *ob = vc->obact;
+	Mesh *me = get_mesh(ob);
 	int *indexar= vpd->indexar;
+	float mat[4][4], mval[2], pressure;
 	int totindex, index, flip;
-	float pressure, mval[2];
 
-	RNA_float_get_array(itemptr, "mouse", mval);
-	flip = RNA_boolean_get(itemptr, "flip");
-	pressure = RNA_float_get(itemptr, "pressure");
-			
 	view3d_operator_needs_opengl(C);
 			
 	/* load projection matrix */
 	mul_m4_m4m4(mat, ob->obmat, vc->rv3d->persmat);
 
+	RNA_float_get_array(itemptr, "mouse", mval);
+	flip = RNA_boolean_get(itemptr, "flip");
+	pressure = RNA_float_get(itemptr, "pressure");
+
 	mval[0]-= vc->ar->winrct.xmin;
 	mval[1]-= vc->ar->winrct.ymin;
 
@@ -1886,7 +1912,7 @@
 			
 	for(index=0; index<totindex; index++) {				

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list