[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29793] branches/soc-2010-jwilkins: * draw and clay brushes now experimentally use the cylindrical distance ( from the center line of the brush location and area normal) instead of spherical distance.

Jason Wilkins Jason.A.Wilkins at gmail.com
Tue Jun 29 15:49:35 CEST 2010


Revision: 29793
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29793
Author:   jwilkins
Date:     2010-06-29 15:49:35 +0200 (Tue, 29 Jun 2010)

Log Message:
-----------
* draw and clay brushes now experimentally use the cylindrical distance (from the center line of the brush location and area normal) instead of spherical distance.
* the cylindrical distance calculation was found to work better with the new adaptive strength which determines the appropriate strength of the brush by sampling its effect and normalizing it automatically
* I reset the brushes to all act at their 'natural' strengths while I continue to investigate how they should best be set.
** I'm suspicious of any brush that appears to need a strength > 1
*** example: if fill/flatten/scrape are set to strength 1 and max curve their natural strength should make them completely flatten a surface in one pass
*** example: draw/inflate/crease/layer will move a vertex 1 brush radius at strength 1 and max curve, moving it further causes bad behavior
*** example: clay/wax move a vertex 1/4 a brush radius at strength 1 and max curve, moving any further and people complain that they are too much like draw... :(
*** example: smooth clips its strength to 1, setting it higher just clips the texture and curve to the point you may as well not have them
** Even at their natural strengths, many of the brushes can already be set so high that they cause artifacts.
** Is the problem that pressure is applied in a way that causes you to have to press too hard if you use a pen?
* The layer brush was too strong (even without any adjustment), it was moving vertexes as if the radius was always 1.0 (which is really big if you use the default subdivided cube) no matter how big the brush was.
* curvemapping_evaluateF now returns 1.0-p if the curve table can't be generated, before it returned p which was reversed what it should be for a sensible default
* changed some tooltip text
* made the 'use blender units' into a little lock/unlock icon
* removed 'sculpt tools' label from list of tools, was redundant

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
    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-29 13:23:07 UTC (rev 29792)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-29 13:49:35 UTC (rev 29793)
@@ -512,7 +512,7 @@
             if not context.sculpt_object:
                 row.template_list(settings, "brushes", settings, "active_brush_index", rows=2, maxrows=defaultbrushes)
             else:
-                col.template_ID_preview(settings, "brush", new="brush.add", filter="is_sculpt_brush", rows=3, cols=4)
+                col.template_ID_preview(settings, "brush", new="brush.add", filter="is_sculpt_brush", rows=4, cols=4)
 
         # Particle Mode #
 
@@ -548,7 +548,10 @@
             col.separator()
 
             row = col.row(align=True)
-            row.prop(brush, "lock_brush_size", text="Use BUnits")
+            if brush.lock_brush_size:
+                row.prop(brush, "lock_brush_size", toggle=True, text="", icon='LOCKED')
+            else:
+                row.prop(brush, "lock_brush_size", toggle=True, text="", icon='UNLOCKED')
 
             edit = context.user_preferences.edit
             if brush.lock_brush_size:
@@ -792,7 +795,7 @@
 
         if context.sculpt_object:
             if brush.sculpt_tool != 'LAYER':
-                layout.prop(brush, "restore_mesh", "Drag And Drop")
+                layout.prop(brush, "restore_mesh", "Drag Dot")
                 layout.prop(brush, "use_anchor")
                 if brush.use_anchor:
                     layout.prop(brush, "edge_to_edge", "Edge To Edge")

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c	2010-06-29 13:23:07 UTC (rev 29792)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/colortools.c	2010-06-29 13:49:35 UTC (rev 29793)
@@ -701,7 +701,7 @@
 	if(cuma->table==NULL) {
 		curvemap_make_table(cuma, &cumap->clipr);
 		if(cuma->table==NULL)
-			return value;
+			return 1.0f-value;
 	}
 	return curvemap_evaluateF(cuma, value);
 }

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-29 13:23:07 UTC (rev 29792)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-29 13:49:35 UTC (rev 29793)
@@ -381,6 +381,27 @@
 //	return 1;
 //}
 
+static int sculpt_brush_test_cyl(SculptBrushTest *test, float x0[3], float x1[3], float x2[3])
+{
+	float t0[3], t1[3], t2[3], t3[3], dist;
+
+	sub_v3_v3v3(t0, x2, x1);
+	sub_v3_v3v3(t1, x1, x0);
+	sub_v3_v3v3(t2, x2, x1);
+
+	cross_v3_v3v3(t3, t0, t1);
+
+	dist = len_v3(t3)/len_v3(t2);
+
+	if (dist*dist < test->radius_squared) {
+		test->dist = dist;
+		return 1;
+	}
+	else {
+		return 0;
+	}
+}
+
 static int sculpt_brush_test(SculptBrushTest *test, float co[3])
 {
 	//if (sculpt_brush_test_clip(test, co)) {
@@ -522,6 +543,48 @@
 	return circle_overlap(d) / M_PI;
 }
 
+static float overlapped_curve(Brush* br, float x)
+{
+	int i;
+	const int n = 100 / br->spacing;
+	const float h = br->spacing / 50.0f;
+	const float x0 = x-1;
+
+	float sum;
+
+	sum = 0;
+	for (i= 0; i < n; i++) {
+		float xx;
+
+		xx = fabs(x0 + i*h);
+
+		if (xx < 1.0f)
+			sum += brush_curve_strength(br, xx, 1);
+	}
+
+	return sum;
+}
+
+static float integrate_overlap(Brush* br)
+{
+	int i;
+	int m= 10;
+	float g = 1.0f/m;
+	float overlap;
+	float max;
+
+	overlap= 0;
+	max= 0;
+	for(i= 0; i < m; i++) {
+		overlap = overlapped_curve(br, i*g);
+
+		if (overlap > max)
+			max = overlap;
+	}
+
+	return max;
+}
+
 /* Return modified brush strength. Includes the direction of the brush, positive
    values pull vertices, negative values push. Uses tablet pressure and a
    special multiplier found experimentally to scale the strength factor. */
@@ -532,13 +595,16 @@
 	/* Primary strength input; square it to make lower values more sensitive */
 	float alpha        = brush->alpha * brush->alpha * brush->strength_multiplier;
 	float dir          = brush->flag & BRUSH_DIR_IN ? -1 : 1;
-	float pressure = brush->flag & BRUSH_ALPHA_PRESSURE ? cache->pressure : 1;
+	float pressure     = brush->flag & BRUSH_ALPHA_PRESSURE ? cache->pressure : 1;
 	float pen_flip     = cache->pen_flip ? -1 : 1;
 	float invert       = cache->invert ? -1 : 1;
+	float accum        = integrate_overlap(brush);
+	float overlap      = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? 1.0f/accum : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
+	//float overlap      = (brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100.0f) ? 1 - circle_overlap_percent(brush->spacing/50.0f) : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
+	//float overlap      = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? (float)brush->spacing/100.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
+	//float overlap      = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 50) ? (float)brush->spacing/50.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
+	float flip         = dir * invert * pen_flip;
 
-	//float overlap  = (brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100.0f) ? 1 - circle_overlap_percent(brush->spacing/50.0f) : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
-	float overlap  = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? (float)brush->spacing/100.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
-
 	// XXX not functionally cohesive to update this here
 	brush->autosmooth_overlap = overlap;
 
@@ -548,33 +614,32 @@
 		case SCULPT_TOOL_INFLATE:
 		case SCULPT_TOOL_WAX:
 		case SCULPT_TOOL_CREASE:
-			return alpha * 3.0f * dir * invert * pen_flip * pressure * overlap;
-			
 		case SCULPT_TOOL_LAYER:
-			return alpha * 2.0f * dir * invert * pen_flip * pressure * overlap;
-		
+			return alpha * flip * pressure * overlap;
+
 		case SCULPT_TOOL_FILL:
 		case SCULPT_TOOL_SCRAPE:
 		case SCULPT_TOOL_FLATTEN:
 			if (dir*invert*pen_flip > 0)
-				return alpha * 8.0f * dir * invert * pen_flip * pressure * overlap;	
+				return alpha * flip * pressure * overlap;
 			else
-				return alpha * 3.0f * dir * invert * pen_flip * pressure * overlap; /* reduce strength for DEEPEN, PEAKS, and CONTRAST */
+				/* reduce strength for DEEPEN, PEAKS, and CONTRAST */
+				return 0.5f * alpha * flip * pressure * overlap; 
 
 		case SCULPT_TOOL_SMOOTH:
-			return alpha * 10.0f * pressure * overlap;
+			return alpha * pressure * overlap;
 
 		case SCULPT_TOOL_PINCH:
-			return alpha * 3.5f * dir * invert * pen_flip * pressure * overlap;
+			return alpha * flip * pressure * overlap;
 
 		case SCULPT_TOOL_GRAB:
-			return dir*invert*pen_flip > 0 ? 1.0f : -1.0f;
+			return flip > 0 ? 1.0f : -1.0f;
 
 		case SCULPT_TOOL_NUDGE:
-			return alpha * 3.0f * pressure * overlap;
+			return alpha * pressure * overlap;
 
 		case SCULPT_TOOL_THUMB:
-			return pressure / 4.0f;
+			return pressure;
 
 		case SCULPT_TOOL_SNAKE_HOOK:
 			return pressure;
@@ -1150,6 +1215,7 @@
 	float offset[3], area_normal[3];
 	float bstrength= ss->cache->bstrength;
 	int n;
+	float p[3];
 
 	calc_area_normal(sd, ss, area_normal, nodes, totnode);
 	
@@ -1158,6 +1224,8 @@
 	mul_v3_v3(offset, ss->cache->scale);
 	mul_v3_fl(offset, bstrength);
 
+	add_v3_v3v3(p, ss->cache->location, area_normal);
+
 	/* threaded loop over nodes */
 	#pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
 	for(n=0; n<totnode; n++) {
@@ -1167,7 +1235,8 @@
 		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(&test, vd.co)) {
+			if(sculpt_brush_test_cyl(&test, vd.co, ss->cache->location, p)) {
 				/* offset vertex */
 				float fade = tex_strength(ss, brush, vd.co, test.dist);
 				float val[3];
@@ -1233,6 +1302,7 @@
 				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; 
@@ -1555,16 +1625,16 @@
 
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
 			if(sculpt_brush_test(&test, vd.co)) {
-				float fade = tex_strength(ss, brush, vd.co, test.dist)*bstrength;
+				float fade = tex_strength(ss, brush, vd.co, test.dist)*bstrength*ss->cache->radius;
 				float *disp= &layer_disp[vd.i];
 				float val[3];
-				
+
 				*disp+= fade;
-				
+
 				/* Don't let the displacement go past the limit */
 				if((lim < 0 && *disp < lim) || (lim > 0 && *disp > lim))
 					*disp = lim;
-				
+
 				mul_v3_v3fl(val, offset, *disp);
 
 				if(ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) {
@@ -1947,6 +2017,7 @@
 	int n;
 
 	float temp[3];
+	float p[3];
 
 	int flip;
 
@@ -1959,12 +2030,14 @@
 		radius    = -radius;
 	}
 
-	displace = radius * (0.5f+offset);
+	displace = radius * (0.25f+offset);
 
 	mul_v3_v3v3(temp, an, ss->cache->scale);
 	mul_v3_fl(temp, displace);
 	add_v3_v3(fc, temp);
 
+	add_v3_v3v3(p, ss->cache->location, an);
+
 	#pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
 	for (n = 0; n < totnode; n++) {
 		PBVHVertexIter vd;
@@ -1973,11 +2046,12 @@
 		sculpt_brush_test_init(ss, &test);
 
 		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
-			if (sculpt_brush_test_sq(&test, vd.co)) {
+			//if (sculpt_brush_test(&test, vd.co)) {
+			if (sculpt_brush_test_cyl(&test, vd.co, ss->cache->location, p)) {
 				float intr[3];
 				float val[3];
 
-				const float fade = bstrength*tex_strength(ss, brush, vd.co, sqrt(test.dist));

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list