Andy’s Easy Ease Controls
Andy’s Easy Ease Controls
Monday, June 23, 2008
Not an actual plugin but a quick tutorial (with working code) how to add Ease In and Ease Out controls to any of the existing plugins, or to your own code, I posted this for a user over at the COW and thought it was worth reposting here too...
As you know, if you’ve listened to my ramblings before, any of the built-in FxScript plugins can be opened up and modified in the built-in authoring environment that is supplied with FCP. That environment is called FxBuilder, and to launch it you just have to open up the plugin you want to modify. In this example we’ll open up the Cube Spin transition...
First up, open your Effects tab and navigate through the bins to Effects > Video Transitions > 3D Simulation
Now right click (control-click) the Cube Spin transition and choose Open in Editor... from the context menu
The FxBuilder environment will launch, adding an FxBuilder menu item and displaying the FxBuilder window (with the selected effects script open in the FxBuilder Text Entry tab).
Lets take a look at the script of the Cube Spin effect:
Right there at the top in the first few lines is the code which identifies the plugin ie give's it it's Id, defines it's type (what kind of effect it is), it's name (as appears in the effects bin) and it's group (where it appears in the effects bin folder structure)
We’ll want to start this hack by changing the name of the effect, or else we’ll end up with 2 identically named effects which will be difficult to tell apart. OK. So lets give it a new Id and a new name
eg scrtiptid “Cube Spin” becomes scriptid “Andy’s Easy Cube Spin”
and transition "Cube Spin" becomes transition “Andy’s Easy Cube Spin”
OK then. A few more lines down and you'll see the definition for the "input" commands. These create an effect's user controls, and you’re going to need to add two extra input commands, one each for your Ease In and Ease Out controls:
input easeIn, "Easy In", Slider, 0, -1, 1;
input easeOut, "Easy Out", Slider, 0, -1, 1;
Now scan through the text of the rest of the script and you'll see that some of the lines of code address a variable called Ratio. Ratio is predefined variable used in FxScripts that represents how far through an effect you are, where Ratio=0 at the beginning of the effect, and Ratio=1 at the end of the effect. This is the crux of the biscuit right here. Its the variable that dictates the progression of an effect and its what we’ll have to modify in order to vary that progression, to slow things down or speed things up.
First we’ll need to create a new variable to hold the modified Ratio value
float myRatio;
Nows the clever bit. We’ll need to use bit of maths magic to give it the new value that represents the original Ratio value as modified by our Ease controls ... I'm no maths guru and you don’t need to be either to mess with this kind of stuff. You’ve probably heard of bezier curves, know what they are and how and when to use them? Well thats exactly what we are modeling here. Our Ease In and Ease Out controls are the bezier handles for transforming our usual linear progression between the start and end of the effect, into an acceleration/deceleration curve. With that in mind, I just went to Google and searched for the equation that defines a bezier curve. Hey presto!
myRatio = 1.5*(1-easeIn)*power((1-Ratio),2)*Ratio + 1.5*(1+easeOut)*power(Ratio,2)*(1-Ratio) + power(Ratio,3);
OK. With that bit of magic in the mix, as Ratio proceeds regularly from 0 to 1, our modified value myRatio will also progress from 0 to 1 but will speed up or slow down depending on our Ease In and Ease Out control values. Give that man a cigar!
Finally, you need to actually use this new value instead of the old one ... go through the script and replace all the occurrences of the variable Ratio with our new variable myRatio
eg rotate3D(target3d1, centerofspin, angleofspin*Ratio, 0, 0);
becomes rotate3D(target3d1, centerofspin, angleofspin*myRatio, 0, 0);
etc
Thats it. We’re done. Now go to the FxBuilder plugin window and choose Create Plugin, save it with a suitable name to your user’s plugins folder (~/Library/Preferences/Final Cut Pro User Data/Pligins) ... quit and relaunch FCP. The new effect should be right there with the name we gave it at the start.. Try it out, play with the controls ... groovy huh?
You can use the exact same method (and those 3 lines of code in itatlics above) to hack Ease controls into any of the built-in FxScript plugins ... go crazy :-)
Good luck
Andy
Update: For those damn lazy buggers out there you an download the pre-compiled effect here: Andy's Easy Cube Spin.zip ... but thats just lazy!
UPDATED 26/08/09:
Revamped the Cube Spin plug ... hey, if its worth doing its worth doing well.
_