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.
This commit is contained in:
parent
dc78e47b77
commit
9dbe7bbe9a
|
@ -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")
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue