From 82d7234ed97f3ec1c0d4b7f8d752e69de2101d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Jelov=C4=8Dan?= Date: Mon, 23 May 2022 15:54:35 +0200 Subject: GPencil: A Ping Pong effect to Time modifier This patch adds 4th option to Time offset modifier Modes. It loops from start frame to end frame and then back to start in reverse direction. In other words it is a combination of Normal and Reverse mode. Especially with offset control it adds the ability to create easy looping animations such as cheering crowds, flowers opening and closing at different offsets. Reviewed By: #grease_pencil, antoniov, pepeland, mendio Differential Revision: https://developer.blender.org/D14965 --- .../gpencil_modifiers/intern/MOD_gpenciltime.c | 24 ++++++++++++++++++++++ .../blender/makesdna/DNA_gpencil_modifier_types.h | 1 + .../blender/makesrna/intern/rna_gpencil_modifier.c | 1 + 3 files changed, 26 insertions(+) (limited to 'source/blender') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c index c576cfbe525..414231fcae5 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c @@ -122,6 +122,30 @@ static int remapTime(struct GpencilModifierData *md, nfra = (efra + 1 - (cfra + offset - 1) % (efra - sfra + 1)) - 1; } } + + if (mmd->mode == GP_TIME_MODE_PINGPONG) { + if ((mmd->flag & GP_TIME_KEEP_LOOP) == 0) { + if (((int)(cfra + offset - 1) / (efra - sfra)) % (2)) { + nfra = efra - (cfra + offset - 1) % (efra - sfra); + } + else { + nfra = sfra + (cfra + offset - 1) % (efra - sfra); + } + if (cfra > (efra - sfra) * 2) { + nfra = sfra + offset; + } + } + else { + + if (((int)(cfra + offset - 1) / (efra - sfra)) % (2)) { + nfra = efra - (cfra + offset - 1) % (efra - sfra); + } + else { + nfra = sfra + (cfra + offset - 1) % (efra - sfra); + } + } + } + return nfra; } diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h index 535533565dd..c20fb180fcd 100644 --- a/source/blender/makesdna/DNA_gpencil_modifier_types.h +++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h @@ -229,6 +229,7 @@ typedef enum eTimeGpencil_Mode { GP_TIME_MODE_NORMAL = 0, GP_TIME_MODE_REVERSE = 1, GP_TIME_MODE_FIX = 2, + GP_TIME_MODE_PINGPONG = 3, } eTimeGpencil_Mode; typedef enum eModifyColorGpencil_Flag { diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c index 778f5647417..ea2bb9630fb 100644 --- a/source/blender/makesrna/intern/rna_gpencil_modifier.c +++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c @@ -195,6 +195,7 @@ static const EnumPropertyItem rna_enum_time_mode_items[] = { {GP_TIME_MODE_NORMAL, "NORMAL", 0, "Regular", "Apply offset in usual animation direction"}, {GP_TIME_MODE_REVERSE, "REVERSE", 0, "Reverse", "Apply offset in reverse animation direction"}, {GP_TIME_MODE_FIX, "FIX", 0, "Fixed Frame", "Keep frame and do not change with time"}, + {GP_TIME_MODE_PINGPONG, "PINGPONG", 0, "Ping Pong", "Loop back and forth"}, {0, NULL, 0, NULL, NULL}, }; -- cgit v1.2.3