diff options
Diffstat (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c index 5e5c60645ad..a27fb27d518 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c @@ -45,6 +45,7 @@ static void initData(GpencilModifierData *md) gpmd->pass_index = 0; gpmd->step = 1; gpmd->factor = 0.0f; + gpmd->length = 0.1f; gpmd->layername[0] = '\0'; } @@ -57,6 +58,7 @@ static void deformStroke(GpencilModifierData *md, Depsgraph *UNUSED(depsgraph), Object *ob, bGPDlayer *gpl, + bGPDframe *gpf, bGPDstroke *gps) { SimplifyGpencilModifierData *mmd = (SimplifyGpencilModifierData *)md; @@ -65,7 +67,7 @@ static void deformStroke(GpencilModifierData *md, mmd->layername, mmd->pass_index, mmd->layer_pass, - 4, + mmd->mode == GP_SIMPLIFY_SAMPLE ? 3 : 4, gpl, gps, mmd->flag & GP_SIMPLIFY_INVERT_LAYER, @@ -74,14 +76,29 @@ static void deformStroke(GpencilModifierData *md, return; } - if (mmd->mode == GP_SIMPLIFY_FIXED) { - for (int i = 0; i < mmd->step; i++) { - BKE_gpencil_simplify_fixed(gps); + /* Select simplification mode. */ + switch (mmd->mode) { + case GP_SIMPLIFY_FIXED: { + for (int i = 0; i < mmd->step; i++) { + BKE_gpencil_simplify_fixed(gps); + } + break; } - } - else { - /* simplify stroke using Ramer-Douglas-Peucker algorithm */ - BKE_gpencil_simplify_stroke(gps, mmd->factor); + case GP_SIMPLIFY_ADAPTIVE: { + /* simplify stroke using Ramer-Douglas-Peucker algorithm */ + BKE_gpencil_simplify_stroke(gps, mmd->factor); + break; + } + case GP_SIMPLIFY_SAMPLE: { + BKE_gpencil_sample_stroke(gps, mmd->length, false); + break; + } + case GP_SIMPLIFY_MERGE: { + BKE_gpencil_merge_distance_stroke(gpf, gps, mmd->length, true); + break; + } + default: + break; } } @@ -95,7 +112,7 @@ static void bakeModifier(struct Main *UNUSED(bmain), for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { - deformStroke(md, depsgraph, ob, gpl, gps); + deformStroke(md, depsgraph, ob, gpl, gpf, gps); } } } |