[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58022] branches/soc-2013-paint/source/ blender: Anchored brushes for texture paint.

Antony Riakiotakis kalast at gmail.com
Fri Jul 5 19:46:06 CEST 2013


Revision: 58022
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58022
Author:   psy-fi
Date:     2013-07-05 17:46:06 +0000 (Fri, 05 Jul 2013)
Log Message:
-----------
Anchored brushes for texture paint.

To support this I added size support to the RNA stroke so the stroke
size can be calculated in the stroke system and passed on to paint
systems. Also, the output mouse coordinate is directly modified now and
the size is tweaked accordingly. Looks sculpt does not directly use this
for anchored strokes as far as I have seen, but accidents could happen
there so I hope there will be some artist testing.

Also fixed error in texture coordinates for jittered strokes.

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-05 14:26:49 UTC (rev 58021)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-05 17:46:06 UTC (rev 58022)
@@ -582,17 +582,19 @@
 
 	float mouse[2];
 	float pressure;
+	float size;
 	int eraser;
 
 	RNA_float_get_array(itemptr, "mouse", mouse);
 	pressure = RNA_float_get(itemptr, "pressure");
 	eraser = RNA_boolean_get(itemptr, "pen_flip");
+	size = RNA_float_get(itemptr, "size");
 
 	if (BKE_brush_use_alpha_pressure(scene, brush))
 		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure));
-	if (BKE_brush_use_size_pressure(scene, brush))
-		BKE_brush_size_set(scene, brush, max_ff(1.0f, startsize * pressure));
 
+	BKE_brush_size_set(scene, brush, max_ff(1.0f, size));
+
 	if ((brush->flag & BRUSH_RESTORE_MESH) || (brush->flag & BRUSH_ANCHORED)) {
 		paint_stroke_restore(C);
 	}

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-07-05 14:26:49 UTC (rev 58021)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-07-05 17:46:06 UTC (rev 58022)
@@ -601,7 +601,7 @@
 		}
 		else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM)
 			do_random = true;
-		else
+		else if (!(brush->flag & BRUSH_ANCHORED))
 			do_partial_update = true;
 
 		brush_painter_2d_tex_mapping(s, size, painter->startpaintpos, pos, mouse,

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c	2013-07-05 14:26:49 UTC (rev 58021)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c	2013-07-05 17:46:06 UTC (rev 58022)
@@ -152,13 +152,16 @@
 
 
 /* Initialize the stroke cache variants from operator properties */
-static void paint_brush_update(bContext *C, Brush *brush, PaintMode mode,
+static void paint_brush_update(bContext *C, UnifiedPaintSettings *ups,
+                                         Brush *brush,
+                                         PaintMode mode,
                                          struct PaintStroke *stroke,
-                                         const float mouse[2], float pressure)
+                                         const float mouse_init[2],
+                                         float mouse[2], float pressure,
+                                         float location[3])
 {
 	Scene *scene = CTX_data_scene(C);
-	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
-
+	bool location_sampled = false;
 	/* XXX: Use pressure value from first brush step for brushes which don't
 	 *      support strokes (grab, thumb). They depends on initial state and
 	 *      brush coord/pressure/etc.
@@ -222,14 +225,13 @@
 		ups->brush_rotation = atan2(dx, dy) + M_PI;
 
 		if (brush->flag & BRUSH_EDGE_TO_EDGE) {
-			float out[3];
-
 			halfway[0] = dx * 0.5f + stroke->initial_mouse[0];
 			halfway[1] = dy * 0.5f + stroke->initial_mouse[1];
 
 			if (stroke->get_location) {
-				if (stroke->get_location(C, out, halfway)) {
+				if (stroke->get_location(C, location, halfway)) {
 					hit = true;
+					location_sampled = true;
 				}
 			}
 			else {
@@ -239,21 +241,33 @@
 		if (hit) {
 			copy_v2_v2(ups->anchored_initial_mouse, halfway);
 			copy_v2_v2(ups->tex_mouse, halfway);
+			copy_v2_v2(mouse, halfway);
 			ups->anchored_size /= 2.0f;
 			ups->pixel_radius  /= 2.0f;
 		}
-		else
+		else {
 			copy_v2_v2(ups->anchored_initial_mouse, stroke->initial_mouse);
-
+			copy_v2_v2(mouse, stroke->initial_mouse);
+		}
+		ups->pixel_radius /= stroke->zoom_2d;
 		ups->draw_anchored = 1;
 	}
 	else if (brush->flag & BRUSH_RAKE) {
+		/* here we are using the initial mouse coordinate because we do not want the rake
+		 * result to depend on jittering */
 		if (!stroke->brush_init)
-			copy_v2_v2(ups->last_rake, mouse);
+			copy_v2_v2(ups->last_rake, mouse_init);
 		else
-			paint_calculate_rake_rotation(ups, mouse);
+			paint_calculate_rake_rotation(ups, mouse_init);
 	}
 
+	if (!location_sampled) {
+		if (stroke->get_location)
+			stroke->get_location(C, location, mouse);
+		else
+			zero_v3(location);
+	}
+
 	stroke->brush_init = TRUE;
 }
 
@@ -262,6 +276,7 @@
 static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float mouse_in[2], float pressure)
 {
 	Scene *scene = CTX_data_scene(C);
+	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
 	wmWindow *window = CTX_wm_window(C);
 	ARegion *ar = CTX_wm_region(C);
 	Paint *paint = BKE_paint_get_active_from_context(C);
@@ -293,8 +308,6 @@
 	copy_v2_v2(stroke->last_mouse_position, mouse_in);
 	stroke->last_pressure = pressure;
 
-	paint_brush_update(C, brush, mode, stroke, mouse_in, pressure);
-
 	{
 		float delta[2];
 		float factor = stroke->zoom_2d;
@@ -314,15 +327,11 @@
 		}
 	}
 
-	/* TODO: can remove the if statement once all modes have this */
-	if (stroke->get_location)
-		stroke->get_location(C, location, mouse_out);
-	else
-		zero_v3(location);
+	paint_brush_update(C, ups, brush, mode, stroke, mouse_in, mouse_out, pressure, location);
 
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
-
+	RNA_float_set(&itemptr, "size", ups->pixel_radius);
 	RNA_float_set_array(&itemptr, "location", location);
 	RNA_float_set_array(&itemptr, "mouse", mouse_out);
 	RNA_boolean_set(&itemptr, "pen_flip", stroke->pen_flip);

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c	2013-07-05 14:26:49 UTC (rev 58021)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/sculpt.c	2013-07-05 17:46:06 UTC (rev 58022)
@@ -4028,16 +4028,9 @@
 	cache->radius_squared = cache->radius * cache->radius;
 
 	if (brush->flag & BRUSH_ANCHORED) {
+		/* true location has been calculated as part of the stroke system already here */
 		if (brush->flag & BRUSH_EDGE_TO_EDGE) {
-			float halfway[2];
-			float out[3];
-			halfway[0] = 0.5f * (cache->mouse[0] + cache->initial_mouse[0]);
-			halfway[1] = 0.5f * (cache->mouse[1] + cache->initial_mouse[1]);
-
-			if (sculpt_stroke_get_location(C, out, halfway)) {
-				copy_v3_v3(cache->anchored_location, out);
-				copy_v3_v3(cache->true_location, cache->anchored_location);
-			}
+			RNA_float_get_array(ptr, "location", cache->true_location);
 		}
 
 		cache->radius = paint_calc_object_space_radius(cache->vc,

Modified: branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-07-05 14:26:49 UTC (rev 58021)
+++ branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-07-05 17:46:06 UTC (rev 58022)
@@ -1289,6 +1289,11 @@
 	RNA_def_property_range(prop, 0.0f, 1.0f);
 	RNA_def_property_ui_text(prop, "Pressure", "Tablet pressure");
 
+	prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_IDPROPERTY);
+	RNA_def_property_range(prop, 0.0f, FLT_MAX);
+	RNA_def_property_ui_text(prop, "Brush Size", "Brush Size in screen space");
+
 	prop = RNA_def_property(srna, "pen_flip", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_flag(prop, PROP_IDPROPERTY);
 	RNA_def_property_ui_text(prop, "Flip", "");




More information about the Bf-blender-cvs mailing list