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 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/blender/gpencil_modifiers') 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; } -- cgit v1.2.3