Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

auto scaling keyframes

Cow Forums : Adobe After Effects Expressions
cow
auto scaling keyframes
by chris smith on Jun 23, 2008 at 7:04:44 pm

I want to write an expression that will take the key frames from a "control" layer, transfer them to another layer and automatically adjust the key frames to the in point and out point. Hope that makes sense. I'm new to expressions and stuck. Thanks to anyone who can help.

Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by Filip Vandueren on Jun 24, 2008 at 12:27:01 pm

Do you mean that the keyframes that are set on one layer have to stretch in time to occur between the inPoint and outPoint of another layer, and if that layer get's longer or shorter, the animation "stretches" ?
Like: this layer has to go from point A to C via B, start when the layer starts, end when the layer ends, and adapt itself if I make the layer longer/shorter ?

Or is it more a fade-in /fade-out that occurs at start and end, but is always the same length for example, 20 frames...



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by chris smith on Jun 24, 2008 at 3:10:06 pm

Do you mean that the keyframes that are set on one layer have to stretch in time to occur between the inPoint and outPoint of another layer, and if that layer get's longer or shorter, the animation "stretches" ?

that's exactly what i mean, i'm not very good at explaining things. thanks.



Respond to this post     Return to posts index


cow
Re: auto scaling keyframes
by chris smith on Jun 24, 2008 at 3:26:35 pm

I've written this expression so that it will start the animation where ever the new layer is on the timeline, i just need it to scale the animation to the duration of the new layer:

thisComp.layer("Animate In").transform.position.valueAtTime(time - inPoint);



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by Filip Vandueren on Jun 24, 2008 at 6:39:15 pm

Hi Chris,

a slightly differenty aproach:


controlLayer=thisComp.layer("Animate In");
t=linear(time, thisLayer.inPoint, thisLayer.outPoint, controlLayer.inPoint, controlLayer.outPoint);

controlLayer.position.valueAtTime(t);


First I do linear mapping to compare this Layer's time between in & out to the control-layers' in and out.
then I can just use "t" to get the valueAtTime



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by chris smith on Jun 24, 2008 at 6:57:33 pm

That works! Now one more request, is there a way to keep the keyframes the same length as the control layer?



Respond to this post     Return to posts index


cow
Re: auto scaling keyframes
by chris smith on Jun 24, 2008 at 7:17:36 pm

BTW you're freaking amazing. Thanks for getting me this far.



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by Filip Vandueren on Jun 24, 2008 at 9:03:44 pm

Hi Chris,
I'm not sure what you mean.
On the one hand you want the keyframes to scale to the length of the new layer, on the other, you want it be the same length ?



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by chris smith on Jun 24, 2008 at 9:14:01 pm

See I can't explain myself very well, especially when it comes to expressions.

My control layer has 2 keyframes at its inpoint. and two keyframes at its outpoint, both sets of keyframes are 12 frames apart. I want to take the keyframes and place them at the inpoint and outpoint of another layer thats longer but keep the in and out keyframes the same duration instead of having them scale in porportion to the longer layer.

does that make sense?



Respond to this post     Return to posts index


cow
Re: auto scaling keyframes
by Filip Vandueren on Jun 25, 2008 at 12:59:07 pm

Yes, I get it now:


l=thisComp.layer("control");

if (l.position.numKeys>=4) {
t2=l.position.key(2).time- l.inPoint;
t3=l.position.key(3).time- l.outPoint;

if (inPoint+t2>=time) {
TT=linear(time,inPoint,inPoint+t2,l.inPoint,l.inPoint+t2);
} else if (outPoint+t3>=time) {
TT=linear(time,inPoint+t2,outPoint+t3, l.inPoint+t2, l.outPoint+t3);
} else {
TT=linear(time,outPoint+t3,outPoint,l.outPoint+t3,l.outPoint);
}

l.position.valueAtTime(TT);
} else {
value;
}


OK this looks a lot more complex, but it's not really:

first check if there are 4 position keyframes, otherwise we would get errors and this stuff wouldn't work.
There are 3fases:
-from the layer's inPoint to the 2nd keyframe,
-from 2nd to 3rd keyframe
-from 3rd keyframe to the layer's outPoint

so there are 3 if/then's to check in which stage of time we are now,
the correct corresponding time TT on the controlLayer is calculated with linear(), then we sample the value at time TT.

I suppose Keyframe 2 and 3 are identical ? A move in, and Move out, but this expression will work if they're not.
The expression will not work correctly if the new Layer has a length that's shorter than the moveIn + the Move Out (in your case 24 frames)



Respond to this post     Return to posts index

cow
Re: auto scaling keyframes
by chris smith on Jun 25, 2008 at 2:23:03 pm

Wow, you are smart. Thanks for being patient with me and helping me out.



Respond to this post     Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSLIBRARYPODCASTSBLOGSMAGAZINESERVICESNEWSLETTERSNEWSSTOREEVENTS

© CreativeCOW.net All rights are reserved.

[Top]