[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29404] branches/soc-2010-jwilkins: == Snake Hook Brush ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Jun 11 13:56:10 CEST 2010


Revision: 29404
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29404
Author:   jwilkins
Date:     2010-06-11 13:56:09 +0200 (Fri, 11 Jun 2010)

Log Message:
-----------
== Snake Hook Brush ==
Don't expect too much.  I think the brush exposes a flaw in the way that nodes are searched that causes gaps to appear in the mesh.  This is similar to what happens when you use a strong brush in a space where the nodes you are sculpting are not completely connected within the radius of the brush.  

A quick hack to make this workable was to combine the brush with smooth so that it eliminates most of the artifacts and stitches together any gaps that appear.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-11 10:46:47 UTC (rev 29403)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-11 11:56:09 UTC (rev 29404)
@@ -555,7 +555,7 @@
             else:
                 row.prop(brush, "size", slider=True, text="Pixels")
 
-            if brush.sculpt_tool not in ('GRAB', 'THUMB'):
+            if brush.sculpt_tool not in ('GRAB', 'THUMB', 'SNAKE_HOOK'):
                 row.prop(brush, "use_size_pressure", toggle=True, text="")
 
                 row = col.row(align=True)
@@ -568,7 +568,7 @@
                 #row.prop(brush, "jitter", slider=True)
                 #row.prop(brush, "use_jitter_pressure", toggle=True, text="")
 
-            if brush.sculpt_tool == 'GRAB':
+            if brush.sculpt_tool in ('GRAB'):
                 row = col.row(align=True)
                 row.prop(brush, "normal_weight", slider=True)
 

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-11 10:46:47 UTC (rev 29403)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-11 11:56:09 UTC (rev 29404)
@@ -771,6 +771,9 @@
 		case SCULPT_TOOL_THUMB:
 			return 0.5f;
 
+		case SCULPT_TOOL_SNAKE_HOOK:
+			return 1.0f;
+
 		default:
 			return 0;
 	}
@@ -1210,10 +1213,9 @@
 		copy_v3_v3(avg, ss->mvert[vert].co);
 }
 
-static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node)
+static void do_mesh_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node, float bstrength)
 {
 	Brush *brush = paint_brush(&sd->paint);
-	float bstrength= ss->cache->bstrength;
 	PBVHVertexIter vd;
 	SculptBrushTest test;
 	
@@ -1242,13 +1244,12 @@
 	BLI_pbvh_vertex_iter_end;
 }
 
-static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node)
+static void do_multires_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode *node, float bstrength)
 {
 	Brush *brush = paint_brush(&sd->paint);
 	SculptBrushTest test;
 	DMGridData **griddata, *data;
 	DMGridAdjacency *gridadj, *adj;
-	float bstrength= ss->cache->bstrength;
 	float co[3], (*tmpgrid)[3];
 	int v1, v2, v3, v4;
 	int *grid_indices, totgrid, gridsize, i, x, y;
@@ -1322,7 +1323,7 @@
 	MEM_freeN(tmpgrid);
 }
 
-static void do_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
+static void smooth(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode, float bstrength)
 {
 	int iteration, n;
 
@@ -1332,9 +1333,9 @@
 			sculpt_undo_push_node(ss, nodes[n]);
 
 			if(ss->multires)
-				do_multires_smooth_brush(sd, ss, nodes[n]);
+				do_multires_smooth_brush(sd, ss, nodes[n], bstrength);
 			else if(ss->fmap)
-				do_mesh_smooth_brush(sd, ss, nodes[n]);
+				do_mesh_smooth_brush(sd, ss, nodes[n], bstrength);
 
 			BLI_pbvh_node_mark_update(nodes[n]);
 		}
@@ -1344,6 +1345,11 @@
 	}
 }
 
+static void do_smooth_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
+{
+	smooth(sd, ss, nodes, totnode, ss->cache->bstrength);
+}
+
 static void do_pinch_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
 {
 	Brush *brush = paint_brush(&sd->paint);
@@ -1483,6 +1489,47 @@
 	}
 }
 
+static void do_snake_hook_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
+{
+	Brush *brush = paint_brush(&sd->paint);
+	float bstrength = ss->cache->bstrength;
+	float grab_delta[3];
+	int n;
+
+	copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
+
+	for(n = 0; n < totnode; n++) {
+		PBVHVertexIter vd;
+		SculptBrushTest test;
+
+		sculpt_undo_push_node(ss, nodes[n]);
+		sculpt_brush_test_init(ss, &test);
+
+		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
+			if(sculpt_brush_test(&test, vd.co)) {
+				float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist);
+				float val[3];
+
+				mul_v3_v3fl(val, grab_delta, fade);
+				symmetry_feather(sd, ss, vd.co, val);
+				add_v3_v3(val, vd.co);
+
+				sculpt_clip(sd, ss, vd.co, val);
+
+				if(vd.mvert) {
+					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+				}
+			}
+		}
+		BLI_pbvh_vertex_iter_end;
+
+		BLI_pbvh_node_mark_update(nodes[n]);
+	}
+
+	smooth(sd, ss, nodes, totnode, 4);
+}
+
 static void do_thumb_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
 {
 	Brush *brush = paint_brush(&sd->paint);
@@ -2077,6 +2124,9 @@
 	data.sd = sd;
 	data.radius_squared = ss->cache->radius * ss->cache->radius;
 
+	if (brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK)
+		data.radius_squared *= 4.0f;
+
 	/* Build a list of all nodes that are potentially within the brush's
 	   area of influence */
 	if (ELEM(brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) {
@@ -2113,6 +2163,9 @@
 		case SCULPT_TOOL_GRAB:
 			do_grab_brush(sd, ss, nodes, totnode);
 			break;
+		case SCULPT_TOOL_SNAKE_HOOK:
+			do_snake_hook_brush(sd, ss, nodes, totnode);
+			break;
 		case SCULPT_TOOL_NUDGE:
 			do_nudge_brush(sd, ss, nodes, totnode);
 			break;
@@ -2627,6 +2680,29 @@
 
 		copy_v3_v3(cache->old_grab_location, grab_location);
 	}
+	/* Find the snake hook delta */
+	else if(brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK) {
+		float grab_location[3], imat[4][4];
+
+		copy_v3_v3(cache->orig_grab_location, cache->true_location);
+
+		/* compute 3d coordinate at same z from original location + mouse */
+		initgrabz(cache->vc->rv3d, cache->orig_grab_location[0],
+			cache->orig_grab_location[1], cache->orig_grab_location[2]);
+		window_to_3d_delta(cache->vc->ar, grab_location, cache->mouse[0], cache->mouse[1]);
+
+		/* compute delta to move verts by */
+		if (!cache->first_time) {
+			sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location);
+			invert_m4_m4(imat, ss->ob->obmat);
+			mul_mat3_m4_v3(imat, cache->grab_delta);
+		}
+		else {
+			zero_v3(cache->grab_delta);
+		}
+
+		copy_v3_v3(cache->old_grab_location, grab_location);
+	}
 	/* Find the thumb delta */
 	else if(brush->sculpt_tool == SCULPT_TOOL_THUMB) {
 		float grab_location[3], imat[4][4];

Modified: branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-06-11 10:46:47 UTC (rev 29403)
+++ branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-06-11 11:56:09 UTC (rev 29404)
@@ -157,6 +157,7 @@
 #define SCULPT_TOOL_SCRAPE   10
 #define SCULPT_TOOL_NUDGE    11
 #define SCULPT_TOOL_THUMB    12
+#define SCULPT_TOOL_SNAKE_HOOK 13
 
 /* ImagePaintSettings.tool */
 #define PAINT_TOOL_DRAW		0

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-06-11 10:46:47 UTC (rev 29403)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-06-11 11:56:09 UTC (rev 29404)
@@ -103,8 +103,9 @@
 		{SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", ""},
 		{SCULPT_TOOL_INFLATE, "INFLATE", 0, "Inflate", ""},
 		{SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", ""},
+		{SCULPT_TOOL_SNAKE_HOOK, "SNAKE_HOOK", 0, "Snake Hook", ""},
+		{SCULPT_TOOL_THUMB, "THUMB", 0, "Thumb", ""},
 		{SCULPT_TOOL_NUDGE, "NUDGE", 0, "Nudge", ""},
-		{SCULPT_TOOL_THUMB, "THUMB", 0, "Thumb", ""},
 		{SCULPT_TOOL_LAYER, "LAYER", 0, "Layer", ""},
 		{SCULPT_TOOL_FLATTEN, "FLATTEN", 0, "Flatten", ""},
 		{SCULPT_TOOL_CLAY, "CLAY", 0, "Clay", ""},





More information about the Bf-blender-cvs mailing list