[Bf-blender-cvs] [32c7b72] GPencil_Editing_Stage3: GPencil Smooth Brush: Added "Affect Pressure" option

Joshua Leung noreply at git.blender.org
Fri Jul 10 15:42:24 CEST 2015


Commit: 32c7b72ff289a90a3e1313a9a8050fb05f7219c5
Author: Joshua Leung
Date:   Sat Jul 11 01:24:15 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB32c7b72ff289a90a3e1313a9a8050fb05f7219c5

GPencil Smooth Brush: Added "Affect Pressure" option

Use the "Affect Pressure" option to smooth out the pressure values of strokes,
in addition to smoothing the coordinates.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.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 6519fac..6e9f902 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -185,6 +185,9 @@ class GreasePencilStrokeSculptPanel:
         row.prop(brush, "strength", slider=True)
         row.prop(brush, "use_pressure_strength", text="")
         col.prop(brush, "use_falloff")
+		
+        if settings.tool == 'SMOOTH':
+            col.prop(brush, "affect_pressure")
 
         layout.prop(settings, "use_select_mask")
 
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 86bfd1a..dceec41 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -206,8 +206,10 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c
 static bool gp_brush_smooth_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i,
                                   const int radius, const int co[2])
 {
+	GP_EditBrush_Data *brush = gso->brush;
 	bGPDspoint *pt = &gps->points[i];
 	float inf = gp_brush_influence_calc(gso, radius, co);
+	float pressure = 0.0f;
 	float sco[3] = {0.0f};
 	
 	/* Do nothing if not enough points to smooth out */
@@ -223,8 +225,7 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i
 	}
 	
 	/* Compute smoothed coordinate by taking the ones nearby */
-	// XXX: This is slow, and suffers from accumulation error as earlier points are handled before later ones
-	// TODO: affect pressure too...
+	/* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */
 	{	
 		// XXX: this is hardcoded to look at 2 points on either side of the current one (i.e. 5 items total)
 		const int   steps = 2;
@@ -234,6 +235,10 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i
 		/* add the point itself */
 		madd_v3_v3fl(sco, &pt->x, average_fac);
 		
+		if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) {
+			pressure += pt->pressure * average_fac;
+		}
+		
 		/* n-steps before/after current point */
 		// XXX: review how the endpoints are treated by this algorithm
 		// XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight
@@ -251,13 +256,22 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i
 			/* add both these points to the average-sum (s += p[i]/n) */
 			madd_v3_v3fl(sco, &pt1->x, average_fac);
 			madd_v3_v3fl(sco, &pt2->x, average_fac);
+			
+			/* do pressure too? */
+			if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) {
+				pressure += pt1->pressure * average_fac;
+				pressure += pt2->pressure * average_fac;
+			}
 		}
 	}
 	
 	/* Based on influence factor, blend between original and optimal smoothed coordinate */
-	// TODO: affect pressure too...
 	interp_v3_v3v3(&pt->x, &pt->x, sco, inf);
 	
+	if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) {
+		pt->pressure = pressure;
+	}
+	
 	return true;
 }
 
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index f54ae77..12e85e1 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1092,6 +1092,9 @@ typedef enum eGP_EditBrush_Flag {
 	
 	/* strength of brush falls off with distance from cursor */
 	GP_EDITBRUSH_FLAG_USE_FALLOFF  = (1 << 2),
+	
+	/* smooth brush affects pressure values as well */
+	GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE  = (1 << 3)
 } eGP_EditBrush_Flag;
 
 
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 0b2f410..8040477 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -1006,6 +1006,10 @@ static void rna_def_gpencil_sculpt(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "use_falloff", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_EDITBRUSH_FLAG_USE_FALLOFF);
 	RNA_def_property_ui_text(prop, "Use Falloff", "Strength of brush decays with distance from cursor");
+	
+	prop = RNA_def_property(srna, "affect_pressure", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE);
+	RNA_def_property_ui_text(prop, "Affect Pressure", "Affect pressure values as well when smoothing strokes");
 }
 
 void RNA_def_sculpt_paint(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list