[Bf-blender-cvs] [9dbe7bb] master: D1886: GPencil - Add smooth iterations parameter to get better quality

Antonio Vazquez noreply at git.blender.org
Sun May 8 15:11:28 CEST 2016


Commit: 9dbe7bbe9a943ffd18fa670c4f68b4f90a6fc773
Author: Antonio Vazquez
Date:   Sun May 8 13:38:54 2016 +1200
Branches: master
https://developer.blender.org/rB9dbe7bbe9a943ffd18fa670c4f68b4f90a6fc773

D1886: GPencil - Add smooth iterations parameter to get better quality

After some test, a new iteration parameter has been added in order to
apply repetitive smoothing to the stroke. By default 1 iteration is applied,
but can used any number between 1 and 3.

The repetition uses different levels of intensity from 100% of the defined smooth
factor for the first loop, 50% for the second and 25% for the third. We use in each
loop a smaller value in order to avoid deform too much the stroke.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.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 894160c..698a9f5 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -629,6 +629,8 @@ class GreasePencilDataPanel:
         col = layout.column(align=True)
         col.label(text="New Stroke Quality:")
         col.prop(gpl, "pen_smooth_factor")
+        col.prop(gpl, "pen_smooth_steps")
+        col.separator()
         col.prop(gpl, "pen_subdivision_steps")
 
 
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 5e7fdb9..618b36c 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -28,7 +28,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         277
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 /* Several breakages with 270, e.g. constraint deg vs rad */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   6
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index c23429d..f3eb543 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -262,9 +262,12 @@ bGPDlayer *gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setactive)
 	ARRAY_SET_ITEMS(gpl->gcolor_prev, 0.145098f, 0.419608f, 0.137255f); /* green */
 	ARRAY_SET_ITEMS(gpl->gcolor_next, 0.125490f, 0.082353f, 0.529412f); /* blue */
 	
-	/* HQ fill by default */
+	/* high quality fill by default */
 	gpl->flag |= GP_LAYER_HQ_FILL;
-
+	
+	/* default smooth iterations */
+	gpl->draw_smoothlvl = 1;
+	
 	/* auto-name */
 	BLI_strncpy(gpl->info, name, sizeof(gpl->info));
 	BLI_uniquename(&gpd->layers, gpl, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 54b2582..f7d208a 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1040,6 +1040,15 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 
+		/* init grease pencil smooth level iterations */
+		for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
+			for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+				if (gpl->draw_smoothlvl == 0) {
+					gpl->draw_smoothlvl = 1;
+				}
+			}
+		}
+
 		for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
 			for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 				for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 06829cc..fba2f30 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -716,11 +716,18 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
 			}
 		}
 		
-		/* smooth stroke - only if there's something to do */
-		/* NOTE: No pressure smoothing, or else we get annoying thickness changes while drawing... */
+		/* smooth stroke after subdiv - only if there's something to do 
+		 * for each iteration, the factor is reduced to get a better smoothing without changing too much 
+		 * the original stroke
+		 */
 		if (gpl->draw_smoothfac > 0.0f) {
-			for (i = 0; i < gps->totpoints; i++) {
-				gp_smooth_stroke(gps, i, gpl->draw_smoothfac, false);
+			float reduce = 0.0f;
+			for (int r = 0; r < gpl->draw_smoothlvl; ++r) {
+				for (i = 0; i < gps->totpoints; i++) {
+					/* NOTE: No pressure smoothing, or else we get annoying thickness changes while drawing... */
+					gp_smooth_stroke(gps, i, gpl->draw_smoothfac - reduce, false);
+				}
+				reduce += 0.25f;  // reduce the factor
 			}
 		}
 		
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index ab0fcb8..43d4201 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -146,8 +146,9 @@ typedef struct bGPDlayer {
 							 * this is used for the name of the layer  too and kept unique. */
 	
 	float draw_smoothfac;   /* amount of smoothing to apply to newly created strokes */
+	short draw_smoothlvl;   /* number of times to apply smooth factor to new strokes */
 	short sublevel;         /* number of times to subdivide new strokes */
-	short pad[5];           /* padding for compiler error */
+	short pad[4];           /* padding for compiler error */
 } bGPDlayer;
 
 /* bGPDlayer->flag */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 10d7efe..0aebca8 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -810,6 +810,13 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Smooth", "Amount of smoothing to apply to newly created strokes, to reduce jitter/noise");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 	
+	/* Iterations of the Smoothing factor */
+	prop = RNA_def_property(srna, "pen_smooth_steps", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "draw_smoothlvl");
+	RNA_def_property_range(prop, 1, 3);
+	RNA_def_property_ui_text(prop, "Iterations", "Number of times to smooth newly created strokes [+ reason/effect of using higher values of this property]");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
 	/* 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