Cycles F-Curve Modifier: 'Mirrored' Option
Using this cycling mode option, the keyframe range will be repeated in reverse order every second repeat. Thanks for the idea mfoxdogg :)
This commit is contained in:
@@ -1736,6 +1736,7 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float cvalue, float e
|
||||
/* find relative place within a cycle */
|
||||
{
|
||||
float cycdx=0, cycdy=0, ofs=0;
|
||||
float cycle= 0;
|
||||
|
||||
/* ofs is start frame of cycle */
|
||||
ofs= prevkey[0];
|
||||
@@ -1748,13 +1749,16 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float cvalue, float e
|
||||
if (cycdx == 0)
|
||||
return evaltime;
|
||||
|
||||
/* calculate the 'number' of the cycle */
|
||||
cycle= ((float)side * (evaltime - ofs) / cycdx);
|
||||
|
||||
/* check that cyclic is still enabled for the specified time */
|
||||
if (cycles == 0) {
|
||||
/* catch this case so that we don't exit when we have cycles=0
|
||||
* as this indicates infinite cycles...
|
||||
*/
|
||||
}
|
||||
else if ( ((float)side * (evaltime - ofs) / cycdx) > (cycles+1) ) {
|
||||
else if (cycle > (cycles+1)) {
|
||||
/* we are too far away from range to evaluate
|
||||
* TODO: but we should still hold last value...
|
||||
*/
|
||||
@@ -1768,7 +1772,14 @@ static float fcm_cycles_time (FCurve *fcu, FModifier *fcm, float cvalue, float e
|
||||
}
|
||||
|
||||
/* calculate where in the cycle we are (overwrite evaltime to reflect this) */
|
||||
evaltime= (float)(fmod(evaltime-ofs, cycdx) + ofs);
|
||||
if ((mode == FCM_EXTRAPOLATE_MIRROR) && ((int)(cycle) % 2)) {
|
||||
/* when 'mirror' option is used and cycle number is odd, this cycle is played in reverse */
|
||||
evaltime= (float)(lastkey[0] - fmod(evaltime-ofs, cycdx));
|
||||
}
|
||||
else {
|
||||
/* the cycle is played normally... */
|
||||
evaltime= (float)(fmod(evaltime-ofs, cycdx) + ofs);
|
||||
}
|
||||
if (evaltime < ofs) evaltime += cycdx;
|
||||
}
|
||||
|
||||
|
||||
@@ -545,7 +545,7 @@ static void draw_modifier__generator(uiBlock *block, FCurve *fcu, FModifier *fcm
|
||||
static void draw_modifier__cycles(uiBlock *block, FCurve *fcu, FModifier *fcm, int *yco, short *height, short width, short active, int rb_col)
|
||||
{
|
||||
FMod_Cycles *data= (FMod_Cycles *)fcm->data;
|
||||
char cyc_mode[]="Cycling Mode%t|No Cycles%x0|Repeat Motion%x1|Repeat with Offset%x2";
|
||||
char cyc_mode[]="Cycling Mode%t|No Cycles%x0|Repeat Motion%x1|Repeat with Offset%x2|Repeat Mirrored%x3";
|
||||
int cy= (*yco - 30), cy1= (*yco - 50), cy2= (*yco - 70);
|
||||
|
||||
/* set the height */
|
||||
|
||||
@@ -144,6 +144,7 @@ enum {
|
||||
FCM_EXTRAPOLATE_NONE = 0, /* don't do anything */
|
||||
FCM_EXTRAPOLATE_CYCLIC, /* repeat keyframe range as-is */
|
||||
FCM_EXTRAPOLATE_CYCLIC_OFFSET, /* repeat keyframe range, but with offset based on gradient between values */
|
||||
FCM_EXTRAPOLATE_MIRROR, /* alternate between forward and reverse playback of keyframe range */
|
||||
} eFMod_Cycling_Modes;
|
||||
|
||||
|
||||
|
||||
@@ -325,9 +325,10 @@ static void rna_def_fmodifier_cycles(BlenderRNA *brna)
|
||||
PropertyRNA *prop;
|
||||
|
||||
static EnumPropertyItem prop_type_items[] = {
|
||||
{0, "NONE", "No Cycles", ""},
|
||||
{1, "REPEAT", "Repeat Motion", ""},
|
||||
{1, "REPEAT_OFFSET", "Repeat with Offset", ""},
|
||||
{FCM_EXTRAPOLATE_NONE, "NONE", "No Cycles", "Don't do anything."},
|
||||
{FCM_EXTRAPOLATE_CYCLIC, "REPEAT", "Repeat Motion", "Repeat keyframe range as-is."},
|
||||
{FCM_EXTRAPOLATE_CYCLIC_OFFSET, "REPEAT_OFFSET", "Repeat with Offset", "Repeat keyframe range, but with offset based on gradient between values"},
|
||||
{FCM_EXTRAPOLATE_MIRROR, "MIRROR", "Repeat Mirrored", "Alternate between forward and reverse playback of keyframe range"},
|
||||
{0, NULL, NULL, NULL}};
|
||||
|
||||
srna= RNA_def_struct(brna, "FModifierCycles", "FModifier");
|
||||
|
||||
Reference in New Issue
Block a user