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

Jason Wilkins Jason.A.Wilkins at gmail.com
Mon Jun 6 17:47:23 CEST 2011


Revision: 37251
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37251
Author:   jwilkins
Date:     2011-06-06 15:47:22 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
Revision: 30162
Author: nicholasbishop
Date: 4:27:29 PM, Friday, July 09, 2010
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.

** jwilkins:
** this revision crashed if you tried to vpaint with multires modifier, i put a bandaid on it since its easy to do
** reminder, VBO still needs to be enabled for colors to show

Modified Paths:
--------------
    branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
    branches/soc-2011-onion/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c
    branches/soc-2011-onion/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2011-onion/source/blender/makesrna/intern/rna_sculpt_paint.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-29913,30093,30096,30196,30694
/trunk/blender:36833-37206
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29913,30093,30096,30162,30196,30694
/trunk/blender:36833-37206

Modified: branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-06-06 15:47:22 UTC (rev 37251)
@@ -1151,6 +1151,7 @@
         col.prop(vpaint, "use_all_faces")
         col.prop(vpaint, "use_normal")
         col.prop(vpaint, "use_spray")
+        col.prop(vpaint, "backbuf")
 
         col.label(text="Unified Settings:")
         col.prop(tool_settings, "sculpt_paint_use_unified_size", text="Size")

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h	2011-06-06 15:47:22 UTC (rev 37251)
@@ -75,7 +75,6 @@
 	struct ListBase *fmap;
 
 	/* Painting on deformed mesh */
-	int modifiers_active; /* object is deformed with some modifiers */
 	float (*orig_cos)[3]; /* coords of undeformed mesh */
 	float (*deform_cos)[3]; /* coords of deformed mesh but without stroke displacement */
 	float (*deform_imats)[3][3]; /* crazyspace deformation matricies */
@@ -100,6 +99,9 @@
 	/* PBVH acceleration structure */
 	struct PBVH *pbvh;
 
+	/* Painting on deformed mesh */
+	int modifiers_active; /* object is deformed with some modifiers */
+
 	/* Partial redraw */
 	int partial_redraw;
 } PaintSession;

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/cdderivedmesh.c	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/cdderivedmesh.c	2011-06-06 15:47:22 UTC (rev 37251)
@@ -194,24 +194,31 @@
 	CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
 	Mesh *me= ob->data;
 	int deformed= 0;
+	int has_kb;
 
+	if (!(ob->paint))
+		return 0;
+
+	if(ob->paint->modifiers_active)
+		return 0;
+
 	/* active modifiers means extra deformation, which can't be handled correct
 	   on bith of PBVH and sculpt "layer" levels, so use PBVH only for internal brush
 	   stuff and show final DerivedMesh so user would see actual object shape */
-	deformed|= ob->paint->sculpt->modifiers_active;
+	deformed|= ob->paint->modifiers_active;
 
-	if(ob->paint->sculpt && ob->paint->sculpt->modifiers_active)
-		return 0;
-
 	/* as in case with modifiers, we can't synchronize deformation made against
 	   PBVH and non-locked keyblock, so also use PBVH only for brushes and
 	   final DM to give final result to user */
-	deformed|= ob->paint->sculpt->kb && (ob->shapeflag&OB_SHAPE_LOCK) == 0;
+	if (ob->paint->sculpt) {
+		deformed|= ob->paint->sculpt->kb && (ob->shapeflag&OB_SHAPE_LOCK) == 0;
+		has_kb= (int)ob->paint->sculpt->kb;
+	}
+	else {
+		has_kb= 0;
+	}
 
-	if(deformed)
-		return 0;
-
-	return (cddm->mvert == me->mvert) || ob->paint->sculpt->kb;
+	return deformed ? 0 : (cddm->mvert == me->mvert) || has_kb;
 }
 
 static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
@@ -246,7 +253,7 @@
 				    me->totvert,
 				    ss ? &ss->hidden_areas : NULL);
 
-		if(ss->modifiers_active && ob->derivedDeform) {
+		if(ob->paint->modifiers_active && ob->derivedDeform) {
 			DerivedMesh *deformdm= ob->derivedDeform;
 			float (*vertCos)[3];
 			int totvert;
@@ -467,6 +474,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 UNUSED(fast), int (*setMaterial)(int, void *attribs))
@@ -485,22 +525,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" );
@@ -858,6 +884,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-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h	2011-06-06 15:47:22 UTC (rev 37251)
@@ -54,6 +54,7 @@
 struct wmOperatorType;
 
 /* 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-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c	2011-06-06 15:47:22 UTC (rev 37251)
@@ -68,7 +68,7 @@
 #include <float.h>
 #include <math.h>
 
-typedef struct PaintStroke {
+struct PaintStroke {
 	void *mode_data;
 	void *smooth_stroke_cursor;
 	wmTimer *timer;
@@ -91,7 +91,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-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c	2011-06-06 14:27:26 UTC (rev 37250)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c	2011-06-06 15:47:22 UTC (rev 37251)
@@ -1660,10 +1660,9 @@
 		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;
 	}
@@ -1676,15 +1675,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_tag_update(&me->id, 0);
 	
+	/* 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);
 	
 	return OPERATOR_FINISHED;
@@ -1729,19 +1739,41 @@
 */
 
 typedef struct VPaintData {
-	ViewContext vc;
 	unsigned int paintcol;
 	int *indexar;
 	float *vertexcosnos;
 	float vpimat[3][3];
 } VPaintData;
 
-static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *UNUSED(event))
+void paint_raycast_cb(PBVHNode *node, PaintStrokeRaycastData *data, float *tmin)
 {
+	if (BLI_pbvh_node_get_tmin(node) < *tmin &&
+		BLI_pbvh_node_raycast(
+			data->ob->paint->pbvh,
+			node,
+			NULL,
+			data->ray_start,
+			data->ray_normal,
+			&data->dist))
+	{
+		data->hit= 1;
+		*tmin= 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];
@@ -1750,15 +1782,14 @@
 	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");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list