ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Re: Pose 2 Pose with ONE SLIDER controlling a Layer with Multiple Sliders (And therefore: keyframes)

COW Forums : Adobe After Effects

Respond to this post   •   Return to posts index   •   Read entire thread

Filip Vandueren
Re: Pose 2 Pose with ONE SLIDER controlling a Layer with Multiple Sliders (And therefore: keyframes)
on May 9, 2019 at 6:55:35 pm

Yes ☺

global remark: I've use "a ? b : c;" a few times, which is a javacsript shorthand for simple if/then/else statements:

if (a<10) { b= "smaller" } else { b = "larger" }

is the same as
b = (a<10) ? "smaller" : "larger";

myIndex = 1; // number of the slider. (this is used in the comparison below)

sl=thisComp.layer("Null 1").effect("Slider Control")("Slider");
// this is the controlling slider that rules 'em all.

// we want every slider to interpolate between 0 and 100
// but if the original slider is not animated (has 1 or no keyframes) or we are before or after the first/last keyframe
// then we shouldn't bother with calculating and just jump to the else{} statement
if (sl.numKeys>1 && time>sl.key(1).time && time<sl.key(sl.numKeys).time) {

nk = sl.nearestKey(time);
prevK = nk.time<time ? nk : sl.key(nk.index-1);
nextK = sl.key(prevK.index+1);
// this is just the kind of messy code you need to find out what is the previous and what is the next keyframe of the main slider at this point in time
// AE only has nearestKey() and that doesn't care if the nearest key is before or after this time.
// that's why we're checking if nk (nearestKey) of the slider is before or after the current time,

fromValue= (prevK.value == myIndex) ? 100 : 0;
toValue= (nextK.value == myIndex) ? 100 : 0;
// that's the main logic you needed: only my slider at full if that other slider points to "myIndex"
// We check if both the previous and the next keyframe are equal to "myIndex"

// Usually you would interpolate using the current time and the time of the keys
// But that would mean the interpolation is always linear() or ease(), depending on what we hardcode.
// Here I'm looking at the actual current value of the slider, and that tells me how fast it's going from it's previous keyframe's value to the next keyframes value, we map that to our two values (0 and 100 maybe)
// However: linear (or ease) expects its second parameter to always be smaller than the third, so I check with an if-then statement if that is the case, if it's not, I re-order them.
// linear (t, 10,0, 100,200) doesn't work -> linear (t, 0,10, 200,100) does work
if (prevK.value<nextK.value) {
linear(sl.value, prevK.value, nextK.value, fromValue, toValue);
} else {
linear(sl.value, nextK.value, prevK.value, toValue, fromValue);
// and we're done…

} else {
// or, if the slider is not animating; just check if its value == me.
sl.value == myIndex ? 100 : 0;

Posts IndexRead Thread 

Current Message Thread:

© 2019 All Rights Reserved