[Bf-blender-cvs] [4f7caab] master: Fix T41665, stroke jittering used when setting the clone cursor

Antony Riakiotakis noreply at git.blender.org
Mon Sep 1 21:12:21 CEST 2014


Commit: 4f7caabe9dd89a527f2b153274f0d323b49cd85b
Author: Antony Riakiotakis
Date:   Mon Sep 1 21:10:17 2014 +0200
Branches: master
https://developer.blender.org/rB4f7caabe9dd89a527f2b153274f0d323b49cd85b

Fix T41665, stroke jittering used when setting the clone cursor

===================================================================

M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/sculpt_paint/paint_stroke.c

===================================================================

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index cfdb1aa..76b0cad 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -930,39 +930,27 @@ void BKE_brush_scale_size(int *r_brush_size,
 
 void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
 {
-	int use_jitter = (brush->flag & BRUSH_ABSOLUTE_JITTER) ?
-		(brush->jitter_absolute != 0) : (brush->jitter != 0);
+	float rand_pos[2];
+	float spread;
+	int diameter;
 
-	/* jitter-ed brush gives weird and unpredictable result for this
-	 * kinds of stroke, so manually disable jitter usage (sergey) */
-	use_jitter &= (brush->flag & (BRUSH_DRAG_DOT | BRUSH_ANCHORED)) == 0;
+	do {
+		rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
+		rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
+	} while (len_squared_v2(rand_pos) > (0.5f * 0.5f));
 
-	if (use_jitter) {
-		float rand_pos[2];
-		float spread;
-		int diameter;
 
-		do {
-			rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
-			rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
-		} while (len_squared_v2(rand_pos) > (0.5f * 0.5f));
-
-
-		if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
-			diameter = 2 * brush->jitter_absolute;
-			spread = 1.0;
-		}
-		else {
-			diameter = 2 * BKE_brush_size_get(scene, brush);
-			spread = brush->jitter;
-		}
-		/* find random position within a circle of diameter 1 */
-		jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * spread;
-		jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * spread;
+	if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
+		diameter = 2 * brush->jitter_absolute;
+		spread = 1.0;
 	}
 	else {
-		copy_v2_v2(jitterpos, pos);
+		diameter = 2 * BKE_brush_size_get(scene, brush);
+		spread = brush->jitter;
 	}
+	/* find random position within a circle of diameter 1 */
+	jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * spread;
+	jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * spread;
 }
 
 void BKE_brush_randomize_texture_coordinates(UnifiedPaintSettings *ups, bool mask)
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 1e806e8..59a85b2 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -112,7 +112,7 @@ typedef struct PaintStroke {
 	float cached_size_pressure;
 	/* last pressure will store last pressure value for use in interpolation for space strokes */
 	float last_pressure;
-
+	int stroke_mode;
 
 	float zoom_2d;
 	int pen_flip;
@@ -347,6 +347,20 @@ static bool paint_brush_update(bContext *C,
 	return location_success;
 }
 
+static bool paint_stroke_use_jitter(PaintMode mode, Brush *brush, bool invert)
+{
+	bool use_jitter = (brush->flag & BRUSH_ABSOLUTE_JITTER) ?
+		(brush->jitter_absolute != 0) : (brush->jitter != 0);
+
+	/* jitter-ed brush gives weird and unpredictable result for this
+	 * kinds of stroke, so manually disable jitter usage (sergey) */
+	use_jitter &= (brush->flag & (BRUSH_DRAG_DOT | BRUSH_ANCHORED)) == 0;
+	use_jitter &= (!ELEM(mode, PAINT_TEXTURE_2D, PAINT_TEXTURE_PROJECTIVE) ||
+	               !(invert && brush->imagepaint_tool == PAINT_TOOL_CLONE));
+
+
+	return use_jitter;
+}
 
 /* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
 static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float mouse_in[2], float pressure)
@@ -382,6 +396,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float
 	copy_v2_v2(stroke->last_mouse_position, mouse_in);
 	stroke->last_pressure = pressure;
 
+	if (paint_stroke_use_jitter(mode, brush, stroke->stroke_mode == BRUSH_STROKE_INVERT))
 	{
 		float delta[2];
 		float factor = stroke->zoom_2d;
@@ -400,6 +415,9 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float
 			add_v2_v2v2(mouse_out, mouse_in, delta);
 		}
 	}
+	else {
+		copy_v2_v2(mouse_out, mouse_in);
+	}
 
 	if (!paint_brush_update(C, brush, mode, stroke, mouse_in, mouse_out, pressure, location)) {
 		return;
@@ -615,6 +633,7 @@ PaintStroke *paint_stroke_new(bContext *C,
 	stroke->done = done;
 	stroke->event_type = event_type; /* for modal, return event */
 	stroke->ups = ups;
+	stroke->stroke_mode = RNA_enum_get(op->ptr, "mode");
 
 	get_imapaint_zoom(C, &zoomx, &zoomy);
 	stroke->zoom_2d = max_ff(zoomx, zoomy);




More information about the Bf-blender-cvs mailing list