[Bf-blender-cvs] [a051c2e8701] greasepencil-object: New parameter to adjust stabilization

Antonio Vazquez noreply at git.blender.org
Tue Nov 7 10:44:04 CET 2017


Commit: a051c2e8701a856533681a0ec0a329eebdc55da7
Author: Antonio Vazquez
Date:   Tue Nov 7 10:43:42 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa051c2e8701a856533681a0ec0a329eebdc55da7

New parameter to adjust stabilization

Parameter to control the stabilization amount of the brush.

This stabilization works as a dynamic smooth using the previous points to calculate the estimated position and average the position to get smoother strokes.

This is not a replace of smooth factor that works after finish stroke. This new parameter is applyed while drawing before ending the stroke.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/gpencil_paint.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 f45195fa5f5..b3f1baae194 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -417,6 +417,7 @@ class GreasePencilBrushOptionsPanel:
             col.label(text="Stroke Quality:")
             col.prop(brush, "pen_smooth_factor")
             col.prop(brush, "pen_smooth_steps")
+            col.prop(brush, "pen_stabilize_factor")
             col.separator()
             row = col.row(align=False)
             row.prop(brush, "pen_subdivision_steps")
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 1b1452babef..238fcdff617 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -490,7 +490,12 @@ static bool gp_smooth_buffer_point(bGPdata *gpd, float inf)
 {
 	tGPspoint *pt, *pta, *ptb;
 	float fpt[2], fpta[2], fptb[2];
-	float sco[2] = { 0.0f };
+	float estimated_co[2] = { 0.0f };
+	/* the influence never can be 1. We keep the value 1 on the UI for consistency,
+	 * but internally never can be 1 because then the estimated position is always used
+	 * and is impossible to draw
+	 */
+	CLAMP(inf, 0.0f, 0.9f);
 
 	/* Do nothing if not enough points to smooth out */
 	if (gpd->sbuffer_size < 3) {
@@ -510,10 +515,10 @@ static bool gp_smooth_buffer_point(bGPdata *gpd, float inf)
 	copy_v2float_v2int(fpta, &pta->x);
 	copy_v2float_v2int(fptb, &ptb->x);
 	copy_v2float_v2int(fpt, &pt->x);
-	float lambda = closest_to_line_v2(sco, fpt, fpta, fptb);
+	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, sco, inf);
+		interp_v2_v2v2(fpt, fpt, estimated_co, inf);
 		copy_v2int_v2float(&pt->x, fpt);
 	}
 	return true;
@@ -640,8 +645,7 @@ static short gp_stroke_addpoint(
 		gpd->sbuffer_size++;
 
 		/* apply dynamic smooth to point */
-		/* TODO: now the influence is harcoded to 0.6, maybe need a parameter by brush or session? */
-		gp_smooth_buffer_point(gpd, 0.6f);
+		gp_smooth_buffer_point(gpd, brush->draw_stabifac);
 
 		/* check if another operation can still occur */
 		if (gpd->sbuffer_size == GP_STROKE_BUFFER_MAX)
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 708de563521..c19d6e366f3 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -120,7 +120,7 @@ typedef struct bGPDbrush {
 	struct CurveMapping *cur_jitter;
 
 	float curcolor[3];
-	char pad[4];
+	float draw_stabifac;      /* amount of stabilization while drawing */
 } bGPDbrush;
 
 /* bGPDbrush->flag */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 2f6401d092c..4d2267f1e6e 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2374,7 +2374,7 @@ static void rna_def_gpencil_brush(BlenderRNA *brna)
 	RNA_def_property_float_sdna(prop, NULL, "draw_smoothfac");
 	RNA_def_property_range(prop, 0.0, 2.0f);
 	RNA_def_property_ui_text(prop, "Smooth",
-	                         "Amount of smoothing to apply to newly created strokes, to reduce jitter/noise");
+	                         "Amount of smoothing to apply after finish newly created strokes, to reduce jitter/noise");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
 	/* Iterations of the Smoothing factor */
@@ -2385,6 +2385,15 @@ static void rna_def_gpencil_brush(BlenderRNA *brna)
 	                         "Number of times to smooth newly created strokes");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
+	/* Stabilization factor for new strokes while drawing */
+	prop = RNA_def_property(srna, "pen_stabilize_factor", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "draw_stabifac");
+	RNA_def_property_range(prop, 0.0, 1.0f);
+	RNA_def_property_float_default(prop, 0.6f);
+	RNA_def_property_ui_text(prop, "Stabilize",
+		"Amount of smoothing while drawing to reduce jitter/noise");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+
 	/* Subdivision level for new strokes */
 	prop = RNA_def_property(srna, "pen_subdivision_steps", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "sublevel");



More information about the Bf-blender-cvs mailing list