Organic animation preset script
================================
Goal
———
You have an existing animation between two keyframes A and B.
This script adds some variation on A and B values.
It actually only works with linear interpolation between A and B.
Use case, why?
———–
I have a video with two guys fighting.
In order to make the fight more spectacular, I want to create some impacts on every punch, like on a “street fighter” game.
So I manage to create an impact glow on a layer, using the “CC Light Burst 2.5” and Glow effects.
To add more realism, I add some short animation on those effects (using a start and end keyframe on different props of the effects).
Now I know that I need to repeat the process for every punch, so I save the layer’s effects as an animation preset.
Then I just need to re-apply the animation preset on every layer, …
the only problem with that is that the effects will look exactly the same on each layer,
so I want to induce little variation on them: instead of having keyframe A=>x and B=>y, I want A => x+-v and B => y+-v.
So, that’s what the script below basically does, it chooses a variation number and applies it to the keyframes.
How
———
Animate a property using two keyframes A and B.
Set the value of the property at keyframe A to x,
and the value of the property at keyframe B to y.
Then, add the script below as an expression to the property (alt+click).
You need to understand the script and configure it accordingly too.
Here are some insights.
The script expects that your layers are named n1, n2, n3…
Good luck.
Script
————
// docs: https://forums.creativecow.net/thread/227/33228
var prefixLength = 1; // a layer is named
var startVariationFactor = 1; // the layerNumber will first be multiplied by this startVariationFactor…
var startVariationDelta = 30; // …then modulo-ed to this startVariationDelta…
// … then if the layer number is odd, the variation will be subtracted from the keyframe’s base value,
// or added if the layer number is even.
var endVariationFactor = 1; // the number of the layer will first be multiplied by this endVariationFactor…
var endVariationDelta = 30; // …then moduloed to this endVariationDelta…
// … then if the layerNumber modulo 3 is equal to 0, then the sign of the variation will be the same
// as the one of the start variation, and if not, it will be of the reverse sign
var useRemote = false; // default=false, set to true when you want to debug and apply this script on a remote text layer which displays the debug var…
// set the variables below ONLY IF you are debugging and you apply this script to a text layer
var layerName = “n1”;
var effectName = “CC Light Burst 2.5”;
var effectName = “Glow”;
var effectParamId = “Ray Length”;
var effectParamId = “Glow Intensity”;
/**
* SCRIPT
* ———————————————-
* You shouldn’t have to edit below this line…
*/
// define fxProp
if(true === useRemote){
theLayer = thisComp.layer(layerName);
fxProp = theLayer.effect(effectName).param(effectParamId);
}
else{
layerName = thisLayer.name;
fxProp = thisProperty;
}
var theLayer = thisComp.layer(layerName);
var layerNumber = parseInt(layerName.substr(prefixLength));
// getting the frame number of the 2 keyframes
var fxStartFrame = theLayer.timeToFrames(fxProp.key(1).time);
var fxEndFrame = theLayer.timeToFrames(fxProp.key(2).time);
// getting the 2 keyframes’ values
var fxStartValue = fxProp.key(1);
var fxEndValue = fxProp.key(2);
var debug = “”;
debug += “Raw: ” + fxStartFrame + ” => ” + fxStartValue[0] + “; ” + fxEndFrame + ” => ” + fxEndValue[0];
// creating the variation values
var startVariationValue = (layerNumber * startVariationFactor) % startVariationDelta;
var isNegative = (1 === layerNumber % 2);
debug += “\nisNegative: ” + isNegative;
debug += “\nstartVariationValue: ” + startVariationValue;
var endVariationValue = (layerNumber * endVariationFactor) % endVariationDelta;
var isSameSign = (0 === layerNumber % 3);
debug += “\nendVariationValue: ” + endVariationValue;
debug += “\nsameVariationSign: ” + isSameSign;
// update the values using variation
if(isNegative){
fxStartValue -= startVariationValue;
}
else{
fxStartValue += startVariationValue;
}
if(isSameSign){
if(isNegative){
fxEndValue -= endVariationValue;
}
else{
fxEndValue += endVariationValue;
}
}
else{
if(isNegative){
fxEndValue += endVariationValue;
}
else{
fxEndValue -= endVariationValue;
}
}
debug += “\nProcessed: ” + fxStartFrame + ” => ” + fxStartValue + “; ” + fxEndFrame + ” => ” + fxEndValue;
// now get the current frame
var curFrame = thisLayer.timeToFrames(time);
debug += “\ncurFrame: ” + curFrame;
// prepare the linear interpolation values
var nbSteps = fxEndFrame – fxStartFrame; // assert this is >0
debug += “\nnbSteps: ” + nbSteps;
var valueRange = (fxEndValue – fxStartValue);
debug += “\nvalueRange: ” + valueRange;
var stepIncrement = (fxEndValue – fxStartValue) / nbSteps;
debug += “\nstepIncrement: ” + stepIncrement;
// apply to the current frame
var newValue = (curFrame – fxStartFrame) * stepIncrement + fxStartValue;
debug += “\ncurValue: ” + newValue;
var ret = newValue;
if(true === useRemote){
ret = debug;
}
ret