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
This commit is contained in:
Aleš Jelovčan 2022-05-23 15:54:35 +02:00 committed by Antonio Vazquez
parent 698e394e7e
commit 82d7234ed9
3 changed files with 26 additions and 0 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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},
};