[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30195] branches/soc-2010-nicolasbishop/ source/blender: == New VPaint ==

Nicholas Bishop nicholasbishop at gmail.com
Sun Jul 11 03:11:27 CEST 2010


Revision: 30195
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30195
Author:   nicholasbishop
Date:     2010-07-11 03:11:21 +0200 (Sun, 11 Jul 2010)

Log Message:
-----------
== New VPaint ==

* Make disabling All Faces option work. This is a little different from old vpaint, but basically it just fills in whatever face is under the brush. Unlike old vpaint, all corners are filled the same way.
* Display of this feature isn't too good right now. It may look like the colors are being assigned to the wrong face, or not at all. This is just due to the way VBOs are being filled though; switching temporarily to old vpaint shows the colors are on the correct face.

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-11 00:17:16 UTC (rev 30194)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-11 01:11:21 UTC (rev 30195)
@@ -94,7 +94,8 @@
 void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitCallback cb, void *data,
 			  float ray_start[3], float ray_normal[3], int original);
 int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
-	float ray_start[3], float ray_normal[3], float *dist);
+	float ray_start[3], float ray_normal[3], float *dist,
+	int *hit_index, int *grid_hit_index);
 
 /* Drawing */
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-11 00:17:16 UTC (rev 30194)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-11 01:11:21 UTC (rev 30195)
@@ -1363,10 +1363,14 @@
 }
 
 int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
-	float ray_start[3], float ray_normal[3], float *dist)
+			  float ray_start[3], float ray_normal[3], float *dist,
+			  int *hit_index, int *grid_hit_index)
 {
 	int hit= 0;
 
+	if(hit_index) *hit_index = -1;
+	if(grid_hit_index) *grid_hit_index = -1;
+
 	if(bvh->faces) {
 		MVert *vert = bvh->verts;
 		int *faces= node->prim_indices;
@@ -1376,10 +1380,11 @@
 
 		for(i = 0; i < totface; ++i) {
 			MFace *f = bvh->faces + faces[i];
+			int lhit = 0;
 
 			if(origco) {
 				/* intersect with backuped original coordinates */
-				hit |= ray_face_intersection(ray_start, ray_normal,
+				lhit = ray_face_intersection(ray_start, ray_normal,
 							 origco[face_verts[i*4+0]],
 							 origco[face_verts[i*4+1]],
 							 origco[face_verts[i*4+2]],
@@ -1388,13 +1393,18 @@
 			}
 			else {
 				/* intersect with current coordinates */
-				hit |= ray_face_intersection(ray_start, ray_normal,
+				lhit = ray_face_intersection(ray_start, ray_normal,
 							 vert[f->v1].co,
 							 vert[f->v2].co,
 							 vert[f->v3].co,
 							 f->v4 ? vert[f->v4].co : NULL,
 							 dist);
 			}
+
+			if(lhit && hit_index)
+				*hit_index = i;
+
+			hit |= lhit;
 		}
 	}
 	else {

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-11 00:17:16 UTC (rev 30194)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c	2010-07-11 01:11:21 UTC (rev 30195)
@@ -1786,7 +1786,7 @@
 
 	data->hit |= BLI_pbvh_node_raycast(data->ob->paint->pbvh, node, NULL,
 					   data->ray_start, data->ray_normal,
-					   &data->dist);
+					   &data->dist, NULL, NULL);
 }
 
 int vpaint_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2])
@@ -1926,7 +1926,8 @@
 	DAG_id_flush_update(ob->data, OB_RECALC_DATA);
 }
 
-static void vpaint_nodes(VPaint *vp, VPaintData *vpd, PBVH *pbvh, PBVHNode **nodes, int totnode,
+static void vpaint_nodes(VPaint *vp, VPaintData *vpd, PBVH *pbvh,
+			 PBVHNode **nodes, int totnode,
 			 float center[3], float radius)
 {
 	Brush *brush = paint_brush(&vp->paint);
@@ -1983,6 +1984,72 @@
 	}
 }
 
+typedef struct {
+	int hit_index;
+	int grid_hit_index;
+	PBVHNode *node;
+} VPaintColorOneFaceHitData;
+
+void vpaint_color_one_face_raycast_cb(PBVHNode *node, void *data_v)
+{
+	PaintStrokeRaycastData *data = data_v;
+	PaintSession *ps = data->ob->paint;
+	VPaintColorOneFaceHitData *mode_data = data->mode_data;
+
+	if(BLI_pbvh_node_raycast(ps->pbvh, node, NULL,
+				 data->ray_start, data->ray_normal,
+				 &data->dist, &mode_data->hit_index,
+				 &mode_data->grid_hit_index)) {
+		data->hit |= 1;
+		mode_data->node = node;
+	}
+}
+
+static void vpaint_color_one_face(bContext *C, PaintStroke *stroke,
+				  PointerRNA *itemptr)
+{
+	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);
+	float mouse[2], hit_loc[3];
+	VPaintColorOneFaceHitData hit_data;
+
+	RNA_float_get_array(itemptr, "mouse", mouse);
+
+	if(paint_stroke_get_location(C, stroke,
+				     vpaint_color_one_face_raycast_cb,
+				     &hit_data, hit_loc, mouse, 0)) {
+		MFace *mface;
+		CustomData *fdata;
+		MCol *mcol;
+		unsigned int *orig= (unsigned int*)vp->vpaint_prev;
+		int *face_indices;
+		int i, S;
+
+		BLI_pbvh_node_get_faces(vc->obact->paint->pbvh, hit_data.node,
+					&mface, &fdata, &face_indices,
+					NULL, NULL);
+
+		mcol = CustomData_get_layer(fdata, CD_MCOL);
+		mface += face_indices[hit_data.hit_index];
+		S = mface->v4 ? 4 : 3;
+
+		for(i = 0; i < S; ++i) {
+			int cndx = face_indices[hit_data.hit_index]*4 + i;
+			unsigned int *col = (unsigned int*)(mcol + cndx);
+			unsigned int *orig_col = (unsigned int*)(orig + cndx);
+
+			vpaint_blend(vp, col, orig_col,
+				     vpd->paintcol,
+				     brush->alpha * 255);
+		}
+
+		BLI_pbvh_node_set_flags(hit_data.node,
+			SET_INT_IN_POINTER(PBVH_UpdateColorBuffers|PBVH_UpdateRedraw));
+	}
+}
+
 /* uses PBVH */
 static void vpaint_stroke_update_step_new(bContext *C, PaintStroke *stroke,
 					  PointerRNA *itemptr)
@@ -1998,20 +2065,25 @@
 	int totnode;
 
 	RNA_float_get_array(itemptr, "location", center);
-	radius = paint_calc_object_space_radius(ob, vc, center, brush->size);
 
-	search_data.center = center;
-	search_data.radius_squared = radius*radius;
-	search_data.original = 0;
+	if(vp->flag & VP_AREA) {
+		radius = paint_calc_object_space_radius(ob, vc, center, brush->size);
+		search_data.center = center;
+		search_data.radius_squared = radius*radius;
+		search_data.original = 0;
 
-	BLI_pbvh_search_gather(ob->paint->pbvh, BLI_pbvh_search_sphere_cb,
-			       &search_data, &nodes, &totnode);
+		BLI_pbvh_search_gather(ob->paint->pbvh, BLI_pbvh_search_sphere_cb,
+				       &search_data, &nodes, &totnode);
 
-	vpaint_nodes(vp, vpd, ob->paint->pbvh, nodes, totnode,
-		     center, radius);
+		vpaint_nodes(vp, vpd, ob->paint->pbvh, nodes, totnode,
+			     center, radius);
 
-	if(nodes)
-		MEM_freeN(nodes);
+		if(nodes)
+			MEM_freeN(nodes);
+	}
+	else {
+		vpaint_color_one_face(C, stroke, itemptr);
+	}
 
 	/* was disabled because it is slow, but necessary for blur */
 	if(brush->vertexpaint_tool == VP_BLUR)

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-07-11 00:17:16 UTC (rev 30194)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-07-11 01:11:21 UTC (rev 30195)
@@ -1965,7 +1965,7 @@
 	}
 
 	data->hit |= BLI_pbvh_node_raycast(ps->pbvh, node, origco,
-		data->ray_start, data->ray_normal, &data->dist);
+		data->ray_start, data->ray_normal, &data->dist, NULL, NULL);
 }
 
 int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke,





More information about the Bf-blender-cvs mailing list