Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-05-04 14:04:46 +0400
committerJoshua Leung <aligorith@gmail.com>2009-05-04 14:04:46 +0400
commit22c2827d2de6cccf272cadeaa7632fc27f229a32 (patch)
tree915619bdf14144ff6560bd82d88b7415f163fc24
parent387df32933996850145487ddba07a3bd3c25d627 (diff)
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 :)
-rw-r--r--source/blender/blenkernel/intern/fcurve.c15
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c2
-rw-r--r--source/blender/makesdna/DNA_anim_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_fcurve.c7
4 files changed, 19 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 3bc80d64329..0585717e13e 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -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;
}
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index ee10e4ef3b3..16628f31b63 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -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 */
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index 755569fe0cb..f30cd63242a 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -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;
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index 5b8e05f840b..6c58c521535 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -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");