Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2016-03-27 13:24:14 +0300
committerJoshua Leung <aligorith@gmail.com>2016-03-27 17:21:28 +0300
commitbfbbc8ec4001243ad5e9954665ddf9621329319f (patch)
tree95ec19c1cb7714e8d978a517676f4680cf1f8d88 /source/blender/editors/gpencil/gpencil_brush.c
parent71107208ddb2d70cc69d65f03088a8fa348ab030 (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_brush.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c65
1 files changed, 2 insertions, 63 deletions
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 95314445045..ab6217c20e3 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -223,70 +223,9 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso, bGPDstroke *gps, int i
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 */
- if (gps->totpoints <= 2) {
- return false;
- }
-
- /* Only affect endpoints by a fraction of the normal strength,
- * to prevent the stroke from shrinking too much
- */
- if ((i == 0) || (i == gps->totpoints - 1)) {
- inf *= 0.1f;
- }
-
- /* Compute smoothed coordinate by taking the ones nearby */
- /* 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;
- const float average_fac = 1.0f / (float)(steps * 2 + 1);
- int step;
-
- /* 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
- for (step = 1; step <= steps; step++) {
- bGPDspoint *pt1, *pt2;
- int before = i - step;
- int after = i + step;
-
- CLAMP_MIN(before, 0);
- CLAMP_MAX(after, gps->totpoints - 1);
-
- pt1 = &gps->points[before];
- pt2 = &gps->points[after];
-
- /* 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 */
- interp_v3_v3v3(&pt->x, &pt->x, sco, inf);
-
- if (brush->flag & GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE) {
- pt->pressure = pressure;
- }
-
- return true;
+ /* perform smoothing */
+ return gp_smooth_stroke(gps, i, inf);
}
/* ----------------------------------------------- */