[Bf-blender-cvs] [e44fa493107] greasepencil-object: New Lazy Mouse option

Antonio Vazquez noreply at git.blender.org
Sat Jan 27 13:25:13 CET 2018


Commit: e44fa493107d69741f9c76d5b643c03478067597
Author: Antonio Vazquez
Date:   Sat Jan 27 13:25:02 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe44fa493107d69741f9c76d5b643c03478067597

New Lazy Mouse option

This option delays the mouse movements to create more controlled strokes.

The function calculate the optimal location anmix with th current location.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/util/undo.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 9238cc84914..10c5f168c1a 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -409,6 +409,16 @@ class GreasePencilBrushPanel:
             row = layout.row(align=False)
             row.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back")
 
+            if brush.fill_only is False:
+                row = layout.row(align=True)
+                row.prop(brush, "use_lazy_mouse", text="Lazy Mouse")
+                if brush.use_lazy_mouse:
+                    row = layout.row(align=True)
+                    row.prop(brush, "lazy_radius")
+                    row = layout.row(align=True)
+                    row.prop(brush, "lazy_factor", slider=True)
+
+
 class GreasePencilBrushOptionsPanel:
     # subclass must set
     # bl_space_type = 'IMAGE_EDITOR'
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 4905b0f87e0..124f221f4cf 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -557,6 +557,9 @@ static void gp_brush_curvemap_reset(CurveMap *cuma, int preset)
 /* create a set of default drawing brushes with predefined presets */
 void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 {
+	#define LAZY_RADIUS 40
+	#define LAZY_FACTOR 0.9f
+
 	bGPDbrush *brush;
 	CurveMapping *custom_curve;
 	float curcolor[3] = { 1.0f, 1.0f, 1.0f };
@@ -588,6 +591,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_PENCIL;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Pen brush */
 	brush = BKE_gpencil_brush_addnew(ts, "Pen", true);
 	brush->thickness = 30.0f;
@@ -615,6 +621,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_PEN;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Ink brush */
 	brush = BKE_gpencil_brush_addnew(ts, "Ink", true);
 	brush->thickness = 60.0f;
@@ -640,6 +649,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_INK;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Curve */
 	custom_curve = brush->cur_sensitivity;
 	curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -671,6 +683,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_INKNOISE;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Curve */
 	custom_curve = brush->cur_sensitivity;
 	curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
@@ -703,6 +718,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_BLOCK;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Marker brush */
 	brush = BKE_gpencil_brush_addnew(ts, "Marker", false);
 	brush->thickness = 80.0f;
@@ -728,6 +746,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	copy_v3_v3(brush->curcolor, curcolor);
 	brush->icon = GPBRUSH_MARKER;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	/* Fill brush */
 	brush = BKE_gpencil_brush_addnew(ts, "Fill", false);
 	brush->thickness = 1.0f;
@@ -744,6 +765,9 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	brush->thick_smoothlvl = 3;
 	brush->sublevel = 1;
 
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
 	brush->draw_strength = 1.0f;
 	copy_v3_v3(brush->curcolor, curcolor);
 }
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index f1807922403..bc1a0ceba46 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1239,7 +1239,7 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
 	/* setup cursor drawing */
 	//WM_cursor_modal_set(CTX_wm_window(C), BC_CROSSCURSOR);
 	if (gso->sa->spacetype != SPACE_VIEW3D) {
-		ED_gpencil_toggle_brush_cursor(C, true);
+		ED_gpencil_toggle_brush_cursor(C, true, NULL);
 	}
 	return true;
 }
@@ -1281,7 +1281,7 @@ static void gpsculpt_brush_exit(bContext *C, wmOperator *op)
 	ED_area_headerprint(CTX_wm_area(C), NULL);
 	WM_cursor_modal_restore(win);
 	if (gso->sa->spacetype != SPACE_VIEW3D) {
-		ED_gpencil_toggle_brush_cursor(C, false);
+		ED_gpencil_toggle_brush_cursor(C, false, NULL);
 	}
 	
 	/* disable temp invert flag */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 08d86199b88..c2da243a424 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -125,14 +125,14 @@ static void gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
 			gpd->flag &= ~GP_DATA_STROKE_PAINTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE;
-			ED_gpencil_toggle_brush_cursor(C, false);
+			ED_gpencil_toggle_brush_cursor(C, false, NULL);
 			break;
 		case OB_MODE_GPENCIL_PAINT:
 			gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
 			gpd->flag |= GP_DATA_STROKE_PAINTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE;
-			ED_gpencil_toggle_brush_cursor(C, true);
+			ED_gpencil_toggle_brush_cursor(C, true, NULL);
 			break;
 		case OB_MODE_GPENCIL_SCULPT:
 			gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
@@ -140,7 +140,7 @@ static void gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
 			gpd->flag |= GP_DATA_STROKE_SCULPTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE;
 			gpencil_verify_brush_type(C, OB_MODE_GPENCIL_SCULPT);
-			ED_gpencil_toggle_brush_cursor(C, true);
+			ED_gpencil_toggle_brush_cursor(C, true, NULL);
 			break;
 		case OB_MODE_GPENCIL_WEIGHT:
 			gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
@@ -148,13 +148,13 @@ static void gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
 			gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
 			gpd->flag |= GP_DATA_STROKE_WEIGHTMODE;
 			gpencil_verify_brush_type(C, OB_MODE_GPENCIL_WEIGHT);
-			ED_gpencil_toggle_brush_cursor(C, true);
+			ED_gpencil_toggle_brush_cursor(C, true, NULL);
 			break;
 		default:
 			gpd->flag &= ~GP_DATA_STROKE_EDITMODE;
 			gpd->flag &= ~GP_DATA_STROKE_PAINTMODE;
 			gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE;
-			ED_gpencil_toggle_brush_cursor(C, false);
+			ED_gpencil_toggle_brush_cursor(C, false, NULL);
 			break;
 	}
 }
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 66361d155f7..338e398741c 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -280,13 +280,23 @@ static void gp_get_3d_reference(tGPsdata *p, float vec[3])
 /* check if the current mouse position is suitable for adding a new point */
 static bool gp_stroke_filtermval(tGPsdata *p, const int mval[2], int pmval[2])
 {
+	bGPDbrush *brush = p->brush;
 	int dx = abs(mval[0] - pmval[0]);
 	int dy = abs(mval[1] - pmval[1]);
 
 	/* if buffer is empty, just let this go through (i.e. so that dots will work) */
-	if (p->gpd->sbuffer_size == 0)
+	if (p->gpd->sbuffer_size == 0) {
 		return true;
-
+	}
+	/* if lazy mouse, check minimum distance */
+	else if (brush->flag & GP_BRUSH_LAZY_MOUSE) {
+		if ((dx * dx + dy * dy) > (brush->lazy_radius * brush->lazy_radius)) {
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
 	/* check if mouse moved at least certain distance on both axes (best case)
 	 *	- aims to eliminate some jitter-noise from input when trying to draw straight lines freehand
 	 */
@@ -484,6 +494,59 @@ static void copy_v2float_v2int(float r[2], const int a[2])
 	r[1] = (float)a[1];
 }
 
+/**
+* Apply smooth while drawing
+*
+* This smooth allows the artist to get a feedback of the smooth process and
+* reduces the stroke changes when apply the post stroke smooth.
+*
+* \param gpd              Current gp datablock
+* \param inf              Amount of smoothing to apply
+*/
+static bool gp_smooth_buffer_point(bGPdata *gpd, float inf)
+{
+	tGPspoint *pt, *pta, *ptb;
+	float fpt[2], fpta[2], fptb[2];
+	float estimated_co[2] = { 0.0f };
+	float sco[3] = { 0.0f };
+
+	/* the influence never can be 1. We keep the range between 0 and 1 on the UI for
+	* consistency, but internally never can be 1 because then the estimated position
+	* would be used always and this makes impossible to draw.
+	* We adjust between 0 and 0.8 that gets good results
+	*/
+	inf *= 0.8f;
+
+	/* Do nothing if not enough points to smooth out */
+	if (gpd->sbuffer_size < 3) {
+		return false;
+	}
+
+	int i = gpd->sbuffer_size - 1;
+
+	/* points used as reference */
+	pta = (tGPspoint *)gpd->sbuffer + i - 2;
+	ptb = (tGPspoint *)gpd->sbuffer + i - 1;
+
+	/* current point */
+	pt = (tGPspoint *)gpd->sbuffer + i;
+
+	/* compute estimated position projecting over last two points vector the
+	* vector to new point.
+	*/
+	copy_v2float_v2int(fpta, &pta->x);
+	copy_v2float_v2int(fptb, &ptb->x);
+	copy_v2float_v2int(fpt, &pt->x);
+	float lambda = closest_to_line_v2(estimated_co, fpt, fpta, fptb);
+	if (lambda > 0.0f) {
+		/* blend between original and optimal smoothed coordinate */
+		interp_v2_v2v2(fpt, fpt, estimated_co, 1.0f - inf);
+		copy_v2int_v2float(&pt->x, fpt);
+	}
+
+	return true;
+}
+
 /* add current stroke-point to buffer (returns whether point was successfully added) */
 static short gp_stroke_addpoint(
         tGPsdata *p, const int mval[2], float pressure, double curtime)
@@ -603,6 +666,11 @@ static short gp_stroke_addpoint(
 		/* increment counters */
 		gpd->sbuffer_size++;
 
+		/* apply dynamic smooth to point if lazy mouse */
+		if (brush->flag & GP_BRUSH_LAZY_MOUSE) {
+			gp_smooth_buffer_point(gpd, brush->lazy_factor);
+		}
+
 		/* check if another operation can still occur */
 		if (gpd->s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list