[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30209] branches/soc-2010-jwilkins: == Planar Trim ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Sun Jul 11 18:53:06 CEST 2010


Revision: 30209
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30209
Author:   jwilkins
Date:     2010-07-11 18:53:06 +0200 (Sun, 11 Jul 2010)

Log Message:
-----------
== Planar Trim ==

Ability to limit the distance that planar brushes act.  If trim is enabled then vertexes further away from the offset plane than the trim distance are ignored when sculpting.

Works best with 'use original normal' or the view normal.

Clay acts really strange when on, its either a bug or expected behavior.  Wax works much better with trim.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c
    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-07-11 16:28:28 UTC (rev 30208)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-07-11 16:53:06 UTC (rev 30209)
@@ -646,8 +646,16 @@
                 row.prop(brush, "plane_offset", slider=True)
                 row.prop(brush, "use_offset_pressure", text="")
 
+                col.separator()
 
+                row= col.row()
+                row.prop(brush, "use_plane_trim", text="Trim")
+                row= col.row()
+                row.active=brush.use_plane_trim
+                row.prop(brush, "plane_trim", slider=True, text="Distance")
 
+
+
             if brush.sculpt_tool in ('DRAW', 'CREASE', 'BLOB', 'LAYER', 'CLAY', 'CLAY_TUBES', 'WAX'):
                 col.separator()
                 col.row().prop(brush, "direction", expand=True)

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-07-11 16:28:28 UTC (rev 30208)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-07-11 16:53:06 UTC (rev 30209)
@@ -120,6 +120,8 @@
 	
 	brush->image_icon = NULL;
 
+	brush->plane_trim = 0.5f;
+
 	return brush;
 }
 

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-11 16:28:28 UTC (rev 30208)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-11 16:53:06 UTC (rev 30209)
@@ -227,6 +227,7 @@
 	char saved_active_brush_name[24];
 	int alt_smooth;
 
+	float plane_trim_squared;
 } StrokeCache;
 
 /* ===== OPENGL =====
@@ -1920,6 +1921,11 @@
     sub_v3_v3v3(intr, co, intr); 
 }
 
+static int plane_trim(StrokeCache *cache, Brush *brush, float val[3])
+{
+	return !(brush->flag & BRUSH_PLANE_TRIM) || (dot_v3v3(val, val) <= cache->radius_squared*cache->plane_trim_squared);
+}
+
 static int plane_point_side_flip(float co[3], float plane_normal[3], float plane_center[3], int flip)
 {
     float delta[3];
@@ -1991,18 +1997,22 @@
 		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)) {
+			if (sculpt_brush_test_sq(&test, vd.co)) {
 				float intr[3];
 				float val[3];
 
-				const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist);
+				point_plane_project(intr, vd.co, an, fc);
 
-				point_plane_project(intr, vd.co, an, fc);
 				sub_v3_v3v3(val, intr, vd.co);
-				mul_v3_v3fl(proxy[vd.i], val, fade);
 
-				if(vd.mvert)
-					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+				if (plane_trim(ss->cache, brush, val)) {
+					const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrt(test.dist));
+
+					mul_v3_v3fl(proxy[vd.i], val, fade);
+
+					if(vd.mvert)
+						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+				}
 			}
 		}
 		BLI_pbvh_vertex_iter_end;
@@ -2057,18 +2067,22 @@
 		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)) {
+			if (sculpt_brush_test_sq(&test, vd.co)) {
 			//if (sculpt_brush_test_cyl(&test, vd.co, ss->cache->location, p)) {
 				float intr[3];
 
-				const float fade = bstrength*tex_strength(ss, brush, vd.co, test.dist);
+				point_plane_project(intr, vd.co, an, fc);
 
-				point_plane_project(intr, vd.co, an, fc);
 				sub_v3_v3v3(proxy[vd.i], intr, vd.co);
-				mul_v3_fl(proxy[vd.i], fade);
 
-				if(vd.mvert)
-					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+				if (plane_trim(ss->cache, brush, proxy[vd.i])) {
+					const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist));
+
+					mul_v3_fl(proxy[vd.i], fade);
+
+					if(vd.mvert)
+						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+				}
 			}
 		}
 		BLI_pbvh_vertex_iter_end;
@@ -2125,14 +2139,18 @@
 					float intr[3];
 					float val[3];
 
-					const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist));
+					point_plane_project(intr, vd.co, an, fc);
 
-					point_plane_project(intr, vd.co, an, fc);
 					sub_v3_v3v3(val, intr, vd.co);
-					mul_v3_v3fl(proxy[vd.i], val, fade);
 
-					if(vd.mvert)
-						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					if (plane_trim(ss->cache, brush, val)) {
+						const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist));
+
+						mul_v3_v3fl(proxy[vd.i], val, fade);
+
+						if(vd.mvert)
+							vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					}
 				}
 			}
 		}
@@ -2202,14 +2220,18 @@
 					float intr[3];
 					float val[3];
 
-					const float fade = bstrength*tex_strength(ss, brush, vd.co, ss->cache->radius*test.dist);
+					point_plane_project(intr, vd.co, an, fc);
 
-					point_plane_project(intr, vd.co, an, fc);
 					sub_v3_v3v3(val, intr, vd.co);
-					mul_v3_v3fl(proxy[vd.i], val, fade);
 
-					if(vd.mvert)
-						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					if (plane_trim(ss->cache, brush, val)) {
+						const float fade = bstrength*tex_strength(ss, brush, vd.co, ss->cache->radius*test.dist);
+
+						mul_v3_v3fl(proxy[vd.i], val, fade);
+
+						if(vd.mvert)
+							vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					}
 				}
 			}
 		}
@@ -2253,19 +2275,23 @@
 		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)) {
+			if (sculpt_brush_test_sq(&test, vd.co)) {
 				if (plane_point_side(vd.co, an, fc)) {
 					float intr[3];
 					float val[3];
 
-					const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist);
+					point_plane_project(intr, vd.co, an, fc);
 
-					point_plane_project(intr, vd.co, an, fc);
 					sub_v3_v3v3(val, intr, vd.co);
-					mul_v3_v3fl(proxy[vd.i], val, fade);
 
-					if(vd.mvert)
-						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					if (plane_trim(ss->cache, brush, val)) {
+						const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrt(test.dist));
+
+						mul_v3_v3fl(proxy[vd.i], val, fade);
+
+						if(vd.mvert)
+							vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					}
 				}
 			}
 		}
@@ -2309,19 +2335,23 @@
 		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)) {
+			if (sculpt_brush_test_sq(&test, vd.co)) {
 				if (!plane_point_side(vd.co, an, fc)) {
 					float intr[3];
 					float val[3];
 
-					const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist);
+					point_plane_project(intr, vd.co, an, fc);
 
-					point_plane_project(intr, vd.co, an, fc);
 					sub_v3_v3v3(val, intr, vd.co);
-					mul_v3_v3fl(proxy[vd.i], val, fade);
 
-					if(vd.mvert)
-						vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					if (plane_trim(ss->cache, brush, val)) {
+						const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrt(test.dist));
+
+						mul_v3_v3fl(proxy[vd.i], val, fade);
+
+						if(vd.mvert)
+							vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
+					}
 				}
 			}
 		}
@@ -2894,6 +2924,8 @@
 	ss->cache->scale[1] = 1.0f / ob->size[1];
 	ss->cache->scale[2] = 1.0f / ob->size[2];
 
+	ss->cache->plane_trim_squared = brush->plane_trim * brush->plane_trim;
+
 	/* Initialize mirror modifier clipping */
 
 	ss->cache->flag = 0;

Modified: branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-11 16:28:28 UTC (rev 30208)
+++ branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-11 16:53:06 UTC (rev 30209)
@@ -85,13 +85,17 @@
 
 	float crease_pinch_factor;
 
-	// all this below is used to communicate with the cursor drawing routine
+	float plane_trim;
 
+	int pad2;
+
 	float texture_sample_bias;
 	int   texture_overlay_alpha;
 
 	float unprojected_radius;
 
+	// all this below is used to communicate with the cursor drawing routine
+
 	/* record movement of mouse so that rake can start at an intuitive angle */
 	float last_x, last_y;
 	float last_angle;
@@ -136,6 +140,7 @@
 #define BRUSH_RESTORE_MESH	(1<<23)
 #define BRUSH_INVERSE_SMOOTH_PRESSURE (1<<24)
 #define BRUSH_RANDOM_ROTATION (1<<25)
+#define BRUSH_PLANE_TRIM (1<<26)
 
 /* Brush.sculpt_tool */
 #define SCULPT_TOOL_DRAW        1

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-11 16:28:28 UTC (rev 30208)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-11 16:53:06 UTC (rev 30209)
@@ -434,6 +434,13 @@
 	RNA_def_property_ui_text(prop, "Plane Offset", "Adjusts plane on which the brush acts towards or away from the object surface");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+	prop= RNA_def_property(srna, "plane_trim", PROP_FLOAT, PROP_DISTANCE);
+	RNA_def_property_float_sdna(prop, NULL, "plane_trim");
+	RNA_def_property_float_default(prop, 0);
+	RNA_def_property_range(prop, 0, 1.0f);
+	RNA_def_property_ui_text(prop, "Plane Trim", "If a vertex is further from offset plane than this then it is not affected");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
+
 	prop= RNA_def_property(srna, "texture_sample_bias", PROP_FLOAT, PROP_DISTANCE);
 	RNA_def_property_float_sdna(prop, NULL, "texture_sample_bias");
 	RNA_def_property_float_default(prop, 0);
@@ -525,6 +532,11 @@
 	RNA_def_property_ui_text(prop, "Random Rotation", "Rotate the brush texture at random");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+	prop= RNA_def_property(srna, "use_plane_trim", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_PLANE_TRIM);
+	RNA_def_property_ui_text(prop, "Use Plane Trim", "Enable Plane Trim");
+	RNA_def_property_update(prop, 0, "rna_Brush_update");
+
 	prop= RNA_def_property(srna, "use_anchor", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_ANCHORED);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list