Skip to content

Instantly share code, notes, and snippets.

@juancabrera
Last active April 25, 2021 01:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save juancabrera/026fb883cb2bae93bd21 to your computer and use it in GitHub Desktop.
Save juancabrera/026fb883cb2bae93bd21 to your computer and use it in GitHub Desktop.
After Effect Script for getting the cubic-bezier (css friendly) of a specific layer's transition
// Source:
// https://forums.adobe.com/thread/1471138
function getCubicbeziers(){
var curItem = app.project.activeItem;
var selectedLayers = curItem.selectedLayers;
var selectedProperties = app.project.activeItem.selectedProperties;
if (selectedLayers == 0){
alert("Please Select at least one Layer");
} else if(selectedLayers !=0){
for (var i = 0; i < selectedLayers.length; i++){
for (var f in selectedProperties){
var currentProperty = selectedProperties[f];
if (currentProperty.numKeys > 1){
for(var i = 1; i < currentProperty.numKeys; i++) {
var t1 = currentProperty.keyTime(i);
var t2 = currentProperty.keyTime(i+1);
var val1 = currentProperty.keyValue(i);
var val2 = currentProperty.keyValue(i+1);
var delta_t = t2-t1;
var delta = val2-val1;
avSpeed = Math.abs(val2-val1)/(t2-t1);
if (val1<val2){//, this should reproduce your website:
x1 = currentProperty.keyOutTemporalEase(i)[0].influence /100;
y1 = x1*currentProperty.keyOutTemporalEase(i)[0].speed / avSpeed;
x2 = 1-currentProperty.keyInTemporalEase(i+1)[0].influence /100;
y2 = 1-(1-x2)*(currentProperty.keyInTemporalEase(i+1)[0].speed / avSpeed);
}
if (val2<val1){//, to get a curve starting from point [0,1] going to point [1,0], it would be:
x1 = currentProperty.keyOutTemporalEase(i)[0].influence /100;
y1 = (-x1)*currentProperty.keyOutTemporalEase(i)[0].speed / avSpeed;
x2 = currentProperty.keyInTemporalEase(i+1)[0].influence /100;
y2 = 1+x2*(currentProperty.keyInTemporalEase(i+1)[0].speed / avSpeed);
x2 = 1-x2;
}
if (val1==val2){
x1 = currentProperty.keyOutTemporalEase(i)[0].influence /100;
y1 = (-x1)*currentProperty.keyOutTemporalEase(i)[0].speed / ((currentProperty.maxValue-currentProperty.minValue)/(t2-t1)) ;
x2 = currentProperty.keyInTemporalEase(i+1)[0].influence /100;
y2 = 1+x2*(currentProperty.keyInTemporalEase(i+1)[0].speed / ((currentProperty.maxValue-currentProperty.minValue)/(t2-t1)));
x2 = 1-x2;
}
alert("keyframe: " + i +" Cubic-bezier["+x1+", "+y1 +", "+x2+", "+y2 +"]");
}
}
}
}
}
}
getCubicbeziers();
@juanbrujo
Copy link

U know you can self-enclose the function so it calls itself right?

(function getCubicbeziers(){
  ...
})();

Just saying...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment