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

Jason Wilkins Jason.A.Wilkins at gmail.com
Mon Jun 6 19:10:39 CEST 2011


Revision: 37256
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37256
Author:   jwilkins
Date:     2011-06-06 17:10:38 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
Revision: 30195
Author: nicholasbishop
Date: 8:11:21 PM, Saturday, July 10, 2010
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.


** jwilkins:
** I'm thinking that disabling 'All Faces' should change the appearance of the paint cursor.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.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-30174,30196,30694
/trunk/blender:36833-37206
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-30174,30195-30196,30694
/trunk/blender:36833-37206

Modified: branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h	2011-06-06 16:54:53 UTC (rev 37255)
+++ branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h	2011-06-06 17:10:38 UTC (rev 37256)
@@ -108,7 +108,8 @@
 void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback 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-2011-onion/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c	2011-06-06 16:54:53 UTC (rev 37255)
+++ branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c	2011-06-06 17:10:38 UTC (rev 37256)
@@ -1513,10 +1513,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;
@@ -1526,10 +1530,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]],
@@ -1538,13 +1543,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-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 16:54:53 UTC (rev 37255)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c	2011-06-06 17:10:38 UTC (rev 37256)
@@ -1754,7 +1754,9 @@
 			NULL,
 			data->ray_start,
 			data->ray_normal,
-			&data->dist))
+			&data->dist,
+			NULL,
+			NULL))
 	{
 		data->hit= 1;
 		*tmin= data->dist;
@@ -1902,7 +1904,8 @@
 	DAG_id_tag_update(ob->data, 0);
 }
 
-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);
@@ -1964,6 +1967,79 @@
 	}
 }
 
+typedef struct {
+	int hit_index;
+	int grid_hit_index;
+	PBVHNode *node;
+} VPaintColorOneFaceHitData;
+
+void vpaint_color_one_face_raycast_cb(PBVHNode *node, PaintStrokeRaycastData *data, float* tmin)
+{
+	VPaintColorOneFaceHitData *mode_data = data->mode_data;
+
+	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,
+			&mode_data->hit_index,
+			&mode_data->grid_hit_index))
+	{
+		data->hit= 1;
+		*tmin= data->dist;
+
+		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)
@@ -1979,8 +2055,9 @@
 	int totnode;
 
 	RNA_float_get_array(itemptr, "location", center);
-	radius = paint_calc_object_space_radius(vc, center, brush->size);
 
+	if(vp->flag & VP_AREA) {
+		radius = paint_calc_object_space_radius(vc, center, brush->size);
 	search_data.center = center;
 	search_data.radius_squared = radius*radius;
 	search_data.original = 0;
@@ -1993,6 +2070,10 @@
 
 	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-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-06 16:54:53 UTC (rev 37255)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-06 17:10:38 UTC (rev 37256)
@@ -3957,7 +3957,7 @@
 			origco= unode ? unode->co : NULL;
 		}
 
-		if (BLI_pbvh_node_raycast(ps->pbvh, node, origco, data->ray_start, data->ray_normal, &data->dist)) {
+		if (BLI_pbvh_node_raycast(ps->pbvh, node, origco, data->ray_start, data->ray_normal, &data->dist, NULL, NULL)) {
 			data->hit= 1;
 			*tmin= data->dist;
 		}




More information about the Bf-blender-cvs mailing list