diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2016-03-27 13:24:14 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2016-03-27 17:21:28 +0300 |
commit | bfbbc8ec4001243ad5e9954665ddf9621329319f (patch) | |
tree | 95ec19c1cb7714e8d978a517676f4680cf1f8d88 /source/blender/editors/gpencil/gpencil_paint.c | |
parent | 71107208ddb2d70cc69d65f03088a8fa348ab030 (diff) |
Improve grease pencil stroke quality
Improve the quality of current grease pencil strokes adding a new dynamic smooth and subdivision. The level of smooth and subdivide can be adjusted using UI parameters. These options are disabled by default in order to keep the grease pencil stroke compatible with any existing add-on.
Both parameters are defined at layer level.
Reviewers: aligorith
Differential Revision: https://developer.blender.org/D1866
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_paint.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b76ed90a0f1..3784d11908f 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -571,6 +571,8 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) bGPDstroke *gps; bGPDspoint *pt; tGPspoint *ptc; + bGPDlayer *layer = gpencil_layer_getactive(p->gpd); + int i, totelem; /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ int depth_margin = (p->gpd->flag & GP_DATA_DEPTH_STROKE) ? 4 : 0; @@ -610,8 +612,20 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) gps->inittime = p->inittime; /* allocate enough memory for a continuous array for storage points */ - gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); - + int sublevel = layer->sublevel; + int new_totpoints = gps->totpoints; + for (i = 0; i < sublevel; ++i) + { + // Avoid error if subdivide is too big (assume totpoints is right) + if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX) + { + sublevel = i; // reduce sublevel + break; + } + new_totpoints += new_totpoints - 1; + } + gps->points = MEM_callocN(sizeof(bGPDspoint) * new_totpoints, "gp_stroke_points"); + /* set pointer to first non-initialized point */ pt = gps->points + (gps->totpoints - totelem); @@ -730,10 +744,29 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) pt->time = ptc->time; } + /* subdivide the stroke */ + if (sublevel > 0) + { + int sub = gps->totpoints; + for (i = 0; i < sublevel; ++i) + { + sub += sub - 1; + gp_subdivide_stroke(gps, sub); + } + } + /* smooth stroke */ + if (layer->smooth_drawfac > 0.0f) // only if something to do + { + for (i = 0; i < gps->totpoints; i++) + { + gp_smooth_stroke(gps, i, layer->smooth_drawfac); + } + } + if (depth_arr) MEM_freeN(depth_arr); } - + /* add stroke to frame */ BLI_addtail(&p->gpf->strokes, gps); gp_stroke_added_enable(p); |