From 8d4244691a2d54fb746f253633f546d85a16a014 Mon Sep 17 00:00:00 2001 From: Henrik Dick Date: Thu, 24 Mar 2022 10:51:14 +0100 Subject: GPencil: lower bounds for gap in dot dash modifier This patch maximizes the possible bounds for the dash and gap parameters in the dot dash modifier. This makes e.g. chopping up lines without gaps possible. Differential Revision: http://developer.blender.org/D14428 --- .../gpencil_modifiers/intern/MOD_gpencildash.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencildash.c') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c b/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c index 439073752da..25c7fdca9f6 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c @@ -97,12 +97,13 @@ static bool stroke_dash(const bGPDstroke *gps, int new_stroke_offset = 0; int trim_start = 0; + int sequence_length = 0; for (int i = 0; i < dmd->segments_len; i++) { - if (dmd->segments[i].dash + real_gap(&dmd->segments[i]) < 1) { - BLI_assert_unreachable(); - /* This means there's a part that doesn't have any length, can't do dot-dash. */ - return false; - } + sequence_length += dmd->segments[i].dash + real_gap(&dmd->segments[i]); + } + if (sequence_length < 1) { + /* This means the whole segment has no length, can't do dot-dash. */ + return false; } const DashGpencilModifierSegment *const first_segment = &dmd->segments[0]; @@ -204,9 +205,10 @@ static void apply_dash_for_frame( dmd->flag & GP_LENGTH_INVERT_PASS, dmd->flag & GP_LENGTH_INVERT_LAYERPASS, dmd->flag & GP_LENGTH_INVERT_MATERIAL)) { - stroke_dash(gps, dmd, &result); - BLI_remlink(&gpf->strokes, gps); - BKE_gpencil_free_stroke(gps); + if (stroke_dash(gps, dmd, &result)) { + BLI_remlink(&gpf->strokes, gps); + BKE_gpencil_free_stroke(gps); + } } } bGPDstroke *gps_dash; @@ -232,6 +234,18 @@ static void bakeModifier(Main *UNUSED(bmain), /* -------------------------------- */ +static bool isDisabled(GpencilModifierData *md, int UNUSED(userRenderParams)) +{ + DashGpencilModifierData *dmd = (DashGpencilModifierData *)md; + + int sequence_length = 0; + for (int i = 0; i < dmd->segments_len; i++) { + sequence_length += dmd->segments[i].dash + real_gap(&dmd->segments[i]); + } + /* This means the whole segment has no length, can't do dot-dash. */ + return sequence_length < 1; +} + /* Generic "generateStrokes" callback */ static void generateStrokes(GpencilModifierData *md, Depsgraph *depsgraph, Object *ob) { @@ -362,7 +376,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Dash = { /* initData */ initData, /* freeData */ freeData, - /* isDisabled */ NULL, + /* isDisabled */ isDisabled, /* updateDepsgraph */ NULL, /* dependsOnTime */ NULL, /* foreachIDLink */ foreachIDLink, -- cgit v1.2.3 From 97f2210157dbd36bc0a44674c8470202fe808301 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Fri, 25 Mar 2022 20:13:04 +0800 Subject: GPencil: Cyclic flag for dot dash modifier Cyclic option per segment, allows interesting "loop" visual effects. Reviewed by: Antonio Vazquez (antoniov) Differential Revision: https://developer.blender.org/D14439 --- source/blender/gpencil_modifiers/intern/MOD_gpencildash.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/blender/gpencil_modifiers/intern/MOD_gpencildash.c') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c b/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c index 25c7fdca9f6..e57b9df03f5 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencildash.c @@ -148,6 +148,9 @@ static bool stroke_dash(const bGPDstroke *gps, bGPDstroke *stroke = BKE_gpencil_stroke_new( ds->mat_nr < 0 ? gps->mat_nr : ds->mat_nr, size, gps->thickness); + if (ds->flag & GP_DASH_USE_CYCLIC) { + stroke->flag |= GP_STROKE_CYCLIC; + } for (int is = 0; is < size; is++) { bGPDspoint *p = &gps->points[new_stroke_offset + is]; @@ -337,6 +340,7 @@ static void panel_draw(const bContext *C, Panel *panel) uiItemR(sub, &ds_ptr, "radius", 0, NULL, ICON_NONE); uiItemR(sub, &ds_ptr, "opacity", 0, NULL, ICON_NONE); uiItemR(sub, &ds_ptr, "material_index", 0, NULL, ICON_NONE); + uiItemR(sub, &ds_ptr, "use_cyclic", 0, NULL, ICON_NONE); } gpencil_modifier_panel_end(layout, ptr); -- cgit v1.2.3