[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30970] branches/soc-2010-jwilkins: == Adaptive Spacing ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Mon Aug 2 10:58:04 CEST 2010


Revision: 30970
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30970
Author:   jwilkins
Date:     2010-08-02 10:58:04 +0200 (Mon, 02 Aug 2010)

Log Message:
-----------
== Adaptive Spacing ==
Spacing takes into account the angle of the surface relative to the view port and reduces the spacing accordingly.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.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-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-08-02 08:58:04 UTC (rev 30970)
@@ -887,6 +887,9 @@
                 row = col.row()
                 row.active = brush.use_space
                 row.prop(brush, "spacing", text="Spacing")
+                row = col.row()
+                row.active = brush.use_space
+                row.prop(brush, "use_adaptive_space", text="Adaptive Spacing")
 
             if brush.sculpt_tool not in ('GRAB', 'THUMB', 'SNAKE_HOOK', 'ROTATE') and (not brush.use_anchor) and (not brush.restore_mesh):
                 col = layout.column()

Modified: branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c	2010-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/source/blender/blenloader/intern/readfile.c	2010-08-02 08:58:04 UTC (rev 30970)
@@ -10863,7 +10863,6 @@
 		Scene *scene;
 		bScreen *sc;
 		Tex *tex;
-		Brush *brush;
 
 		for (sc= main->screen.first; sc; sc= sc->id.next) {
 			ScrArea *sa;
@@ -10982,7 +10981,9 @@
 	}
 
 	/* GSOC Sculpt 2010 - Sanity check on Sculpt/Paint settings */
-	if (main->versionfile < 253) {
+	/* These sanity checks are useful for any version so do not
+	   put a condition on them */
+	{
 		Scene *sce;
 		for (sce= main->scene.first; sce; sce= sce->id.next) {
 			if (sce->toolsettings->sculpt_paint_unified_alpha == 0)
@@ -10996,13 +10997,12 @@
 		}
 	}
 
-
 	{
 		/* GSOC 2010 Sculpt - New settings for Brush */
 
 		Brush *brush;
 		for (brush= main->brush.first; brush; brush= brush->id.next) {
-			/* Sanity Check */
+			/* Sanity Check for Brushes 2.52 */
 			/* These sanity checks are useful for any version so do not
 			   put a condition on them */
 
@@ -11044,11 +11044,17 @@
 
 			// same as dots
 			if (brush->rate == 0)
-				brush->rate = 0.1f;
+				brush->rate= 0.1f;
 
+			/* Sanity Check for Brushes 2.53 */
+
+			// divide by zero
+			if (brush->adaptive_space_factor == 0)
+				brush->adaptive_space_factor= 1;
+
 			/* New Settings */
 			if (main->versionfile < 252 || (main->versionfile == 252 && main->subversionfile < 5)) {
-				brush->flag |= BRUSH_SPACE_ATTEN; // explicitly enable adaptive space
+				brush->flag |= BRUSH_SPACE_ATTEN; // explicitly enable adaptive strength
 
 				// spacing was originally in pixels, convert it to percentage for new version
 				// size should not be zero due to sanity check above
@@ -11072,17 +11078,24 @@
 					brush->sub_col[2] = 1.00;
 				}
 			}
+
+			if (main->versionfile < 253) {
+				brush->flag |= BRUSH_ADAPTIVE_SPACE; // explicitly enable adaptive space
+			}
 		}
 	}
 
-	/* MatCaps */
-	if (main->versionfile < 253) {
+	{
 		Object *ob;
+
+		/* MatCaps */
 		for (ob=main->object.first; ob; ob=ob->id.next) {
+			if (main->versionfile < 253) {
 			/* If max drawtype is textured then assume user won't mind if we bump it up to use MatCaps, */
 			/* Otherwise, assume that if max drawtype is less than textured then user doesn't want to use MatCaps */
-			if (ob->dt == OB_TEXTURE)
-				ob->dt = OB_MATCAP;
+				if (ob->dt == OB_TEXTURE)
+					ob->dt = OB_MATCAP;
+			}
 		}
 	}
 

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-08-02 08:58:04 UTC (rev 30970)
@@ -1596,18 +1596,17 @@
 	int cnt = 0;
 
 	if(paint_space_stroke_enabled(stroke->brush)) {
-		float mouse[2];
 		float vec[2];
 		float length, scale;
+		float start_mouse[2];
 
-		copy_v2_v2(mouse, stroke->last_mouse_position);
-		sub_v2_v2v2(vec, final_mouse, mouse);
+		copy_v2_v2(start_mouse, stroke->last_mouse_position);
+		sub_v2_v2v2(vec, final_mouse, start_mouse);
 
-		length = len_v2(vec);
+		length= len_v2(vec);
 
 		if(length > FLT_EPSILON) {
-			int steps;
-			int i;
+			float t;
 			float pressure = 1;
 
 			// XXX duplicate code
@@ -1618,13 +1617,31 @@
 			}
 
 			scale = (brush_size(stroke->brush)*pressure*stroke->brush->spacing/50.0f) / length;
-			mul_v2_fl(vec, scale);
 
-			steps = (int)(1.0f / scale);
+			if (scale < FLT_EPSILON) // paranoia here: make sure scale is big enough have an effect when added
+				scale= FLT_EPSILON;
 
-			for(i = 0; i < steps; ++i, ++cnt) {
-				add_v2_v2(mouse, vec);
+			t= 0;
+			while (t < 1) {
+				float dvec[2];
+				float mouse[2];
+				float f;
+				float d;
+
+				mul_v2_v2fl(dvec, vec, t);
+				add_v2_v2v2(mouse, start_mouse, dvec);
+
 				paint_brush_stroke_add_step(C, op, event, mouse);
+
+				f= stroke->brush->adaptive_space_factor;
+				CLAMP(f, 0.1f, 1); // make sure that adaptive strength never sets spacing to zero
+
+				d= f*scale;
+				CLAMP(d, FLT_EPSILON, scale); // paranoia here: d has to be big enough to increment t
+
+				t += d;
+
+				cnt++;
 			}
 		}
 	}

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-08-02 08:58:04 UTC (rev 30970)
@@ -100,6 +100,10 @@
  *
  */
 
+static void calc_sculpt_normal(const Sculpt *sd, const SculptSession *ss, float an[3], PBVHNode **nodes, int totnode);
+
+
+
 void ED_sculpt_force_update(bContext *C)
 {
 	Object *ob= CTX_data_active_object(C);
@@ -454,6 +458,25 @@
 	}
 }
 
+static void set_adaptive_space_factor(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode, float an_in[3])
+{
+	Brush *brush = paint_brush(&(sd->paint));
+
+	if (brush->flag & BRUSH_ADAPTIVE_SPACE) {
+		float an[3];
+
+		if (an_in)
+			copy_v3_v3(an, an_in);
+		else
+			calc_sculpt_normal(sd, ss, an, nodes, totnode);
+
+		brush->adaptive_space_factor= dot_v3v3(an, ss->cache->view_normal);
+	}
+	else {
+		brush->adaptive_space_factor= 1;
+	}
+}
+
 #if 0
 
 static int sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float location[3], float an[3])
@@ -486,7 +509,7 @@
 static float overlapped_curve(Brush* br, float x)
 {
 	int i;
-	const int n = 100 / br->spacing;
+	const int n = 100 / (br->adaptive_space_factor*br->spacing);
 	const float h = br->spacing / 50.0f;
 	const float x0 = x-1;
 
@@ -686,8 +709,6 @@
 
 /* Texture Sampling */
 
-static void calc_sculpt_normal(const Sculpt *sd, const SculptSession *ss, float an[3], PBVHNode **nodes, int totnode);
-
 static void set_brush_local_mat(const Sculpt *sd, const SculptSession *ss, const Brush *brush, PBVHNode **nodes, int totnode, float *an_in)
 {
 	float tmat[4][4];
@@ -865,9 +886,12 @@
 		   the texture is not rotated by skipping the calls to
 		   atan2, sqrtf, sin, and cos. */
 		if (rotation > 0.001 || rotation < -0.001) {
-			const float angle    = atan2(y, x) + rotation;
+			float angle    = atan2(y, x) + rotation;
 			const float flen     = sqrtf(x*x + y*y);
 
+			if (br->flag & BRUSH_RANDOM_ROTATION)
+				angle += ss->cache->special_rotation;
+
 			x = flen * cos(angle);
 			y = flen * sin(angle);
 		}
@@ -1326,6 +1350,8 @@
 
 	set_brush_local_mat(sd, ss, brush, NULL, 0, area_normal);
 
+	set_adaptive_space_factor(sd, ss, NULL, 0, area_normal);
+
 	/* offset with as much as possible factored in already */
 	mul_v3_v3fl(offset, area_normal, ss->cache->radius);
 	mul_v3_v3(offset, ss->cache->scale);
@@ -3208,8 +3234,8 @@
 	if(!(brush->flag & BRUSH_ANCHORED || ELEM4(brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB, SCULPT_TOOL_ROTATE))) {
 		copy_v2_v2(cache->tex_mouse, cache->mouse);
 
-		if  ( (brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) &&
-			  (brush->flag & BRUSH_RANDOM_ROTATION) &&
+		if  (ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_WRAP) &&
+			 (brush->flag & BRUSH_RANDOM_ROTATION) &&
 			 !(brush->flag & BRUSH_RAKE))
 		{
 			cache->special_rotation = 2*M_PI*BLI_frand();

Modified: branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-08-02 08:58:04 UTC (rev 30970)
@@ -92,6 +92,8 @@
 
 	float unprojected_radius;
 
+	float adaptive_space_factor, pad2;
+
 	float add_col[3];
 	float sub_col[3];
 } Brush;

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-08-02 07:50:58 UTC (rev 30969)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-08-02 08:58:04 UTC (rev 30970)
@@ -708,10 +708,9 @@
 	RNA_def_property_ui_text(prop, "Use Automatic Strength Adjustment", "Automatically adjusts strength to give consistent results for different spacings");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
-	/* adaptive space is not implemented yet */
 	prop= RNA_def_property(srna, "use_adaptive_space", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_ADAPTIVE_SPACE);
-	RNA_def_property_ui_text(prop, "Adaptive Spacing", "Space daubs according to surface orientation instead of screen space");
+	RNA_def_property_ui_text(prop, "Adaptive Spacing", "Space dabs according to surface orientation instead of screen space");
 	RNA_def_property_update(prop, 0, "rna_Brush_update");
 
 	prop= RNA_def_property(srna, "use_locked_size", PROP_BOOLEAN, PROP_NONE);





More information about the Bf-blender-cvs mailing list