D1886: GPencil - Add smooth iterations parameter to get better quality
authorAntonio Vazquez <blendergit@gmail.com>
Sun, 8 May 2016 01:38:54 +0000 (13:38 +1200)
committerJoshua Leung <aligorith@gmail.com>
Sun, 8 May 2016 12:53:51 +0000 (00:53 +1200)
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.

release/scripts/startup/bl_ui/properties_grease_pencil_common.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenkernel/intern/gpencil.c
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/makesdna/DNA_gpencil_types.h
source/blender/makesrna/intern/rna_gpencil.c

index 894160c2c16d655c14e0798c53331cacb4a3492b..698a9f53119930f787b0944c08dba664c96d66e4 100644 (file)
@@ -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")
 
 
index 5e7fdb9164542e471911d60176eae43aa23c0576..618b36c5851585786cb72a86b70455b6766b4253 100644 (file)
@@ -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
index c23429d86b7e80f5ab54b4b20ef9bffa60835b5f..f3eb5430bce066b6c29ed648688168cfc119d32f 100644 (file)
@@ -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));
index 54b2582c56cde769eb06152568e5408be6417493..f7d208a6a1bb8ac3da6b9cdc61890e4e972124cb 100644 (file)
@@ -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) {
index 06829cc92be33e9f33043a1c21296dcc2ed650b9..fba2f30e7156c7195af085e9f2c363476c2622a5 100644 (file)
@@ -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
                        }
                }
                
index ab0fcb81379321f0c93e5aa4036caf948ec3a950..43d42012b2c6077c30de07877e43b76eecec7267 100644 (file)
@@ -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 */
index 10d7efe93740705a1b3f1e3e62b94eda98ca744c..0aebca8f56b38b14f807b0c2d5aa34af61ebddac 100644 (file)
@@ -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");