DV Info Net

DV Info Net (https://www.dvinfo.net/forum/)
-   Final Cut Suite (https://www.dvinfo.net/forum/final-cut-suite/)
-   -   Trying to hack FCP's Spinback3D plug-in, need FXBuilder help (https://www.dvinfo.net/forum/final-cut-suite/116835-trying-hack-fcps-spinback3d-plug-need-fxbuilder-help.html)

Mike Barber March 12th, 2008 10:27 AM

Trying to hack FCP's Spinback3D plug-in, need FXBuilder help
 
I come from a PHP programming background, so code is not a new concept, though I have yet to delve into FXBuilder...

FCP's Spinback3D is a 3D Simulation transition effect that rotates your outgoing clip ~90° (looks more like ~85°), swaps it for the incoming clip, and reverses the rotation... it isn't a 180° flip, which is what I want.

Sure, I can achieve this with motion keyframes, but I want to do this for several clips and the plugin just makes sense (why the built in plugin doesn't have this as an option, i do not know)

It appears to me that the section of code that governs the rotation is:

Code:

rotate3D(target3d, center3d, 0, 0, -angleofaxis);

if ratio < 0.5
        rotate3D(target3d, center3d, 0, 180*ratio, 0);
else
        rotate3D(target3d, center3d, 0, 180*(1-ratio), 0);
end if;

rotate3D(target3d, center3d, 0, 0, angleofaxis);

Nowhere in the script do I see the ratio variable being defined, so I have no clue from where its value comes!

It should be a simple task, to hack the plugin (or a copy of the plugin... I called it Flip 180) to simply do what it does, but in a full 180° turn. Anyone have any ideas?

Mike Barber March 12th, 2008 10:29 AM

Full code
 
Here is the full FXBuilder code for the Spinback3D plug-in:

Code:

scriptid "Spinback3D" //DO NOT LOCALIZE
transition "Spinback3D";
group "3D Simulation";
wipeCode(20, 100);
producesAlpha;


input angleofaxis, "Angle of Axis", angle, 0, -360, 360 detent 0;
input borderWidth, "Border", slider, 0, 0, 10 snap 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
input borderColor, "Color", color, 255, 0, 0, 0;

code

        on fabs (value _n)
                return (_n<0 ? -_n : _n);
        end;

float w, h, hprime, alpha, offsetangle, angleofview, xprime, yprime;
point source[4], target[4], poly[4], centerofview;
point3d target3d[4], center3d, eye3d;

dimensionsof(dest, w, h);

borderColor.a = 255;
angleofview = 30;

boundsOf(Dest, target);
centerOf(target, centerofview);

source = target;
poly = target;

hprime = h * aspectof(dest);

xprime = w*fabs(cos(angleofaxis)) + hprime*fabs(sin(angleofaxis));
yprime = w*fabs(sin(angleofaxis)) + hprime*fabs(cos(angleofaxis));

scale(poly, centerofview, xprime/w, yprime/h);
rotate(poly, centerofview, angleofaxis, aspectof(dest));

convert2dto3d(centerofview, center3d, 0);
convert2dto3d(centerofview, eye3d, w/(2*tan(angleofview/2)));

scale(target, centerofview, 1, aspectof(dest));
convert2DTo3D(target, target3d, 0);
rotate3D(target3d, center3d, 0, 0, -angleofaxis);

if ratio < 0.5
        rotate3D(target3d, center3d, 0, 180*ratio, 0);
else
        rotate3D(target3d, center3d, 0, 180*(1-ratio), 0);
end if;

rotate3D(target3d, center3d, 0, 0, angleofaxis);
convert3DTo2D(target3d, target, eye3d);
scale(target, centerofview, 1, 1/aspectof(dest));

if srctype1 == knone
        exposedbackground=1;
end if
if srctype2 == knone
        exposedbackground=1
end if;

channelfill(dest, 0, 0, 0, 0);
if ratio < 0.5
        blitrect(Src1, source, Dest, target);
else
        blitrect(src2, source, dest, target);
end if;

if borderwidth > 0
        framepoly(target, dest, bordercolor, borderwidth/renderRes);
end if;


Andy Mees March 12th, 2008 11:19 AM

"ratio" in FxScript pertains to how far through the effect you have progressed (0 at the start to 1 at the end)

what the script is doing then is a simple "if then" conditional switch
if less than half way through the effect then rotate the outgoing clip 180 degrees times the ratio ( so the maximum rotation at ratio of 0.5 will be 90 degrees )
otherwise do the reverse with the incoming clip


so, you need to change that code to:

rotate3D(target3d, center3d, 0, 0, -angleofaxis);

if ratio < 0.5
rotate3D(target3d, center3d, 0, 360*ratio, 0);
else
rotate3D(target3d, center3d, 0, 360*(1-ratio), 0);
end if;

rotate3D(target3d, center3d, 0, 0, angleofaxis);


that'll do what you want (but you may not like the result as the 180 degrees to the angle of view just means you're looking at a flipped image when it cuts ... might want to try changing it to 540 degrees for something more dynamic)

Mike Barber March 12th, 2008 02:34 PM

Quote:

Originally Posted by Andy Mees (Post 841247)
so, you need to change that code to:

rotate3D(target3d, center3d, 0, 0, -angleofaxis);

if ratio < 0.5
rotate3D(target3d, center3d, 0, 360*ratio, 0);
else
rotate3D(target3d, center3d, 0, 360*(1-ratio), 0);
end if;

rotate3D(target3d, center3d, 0, 0, angleofaxis);


that'll do what you want (but you may not like the result as the 180 degrees to the angle of view just means you're looking at a flipped image when it cuts ... might want to try changing it to 540 degrees for something more dynamic)

I may have not described my intended effect well enough, but your suggestion was very helpful in tracking down what change I needed to do. What I actually needed to change the code to was this:

Code:

if ratio < 0.5
        rotate3D(target3d, center3d, 0, 180*ratio, 0);
else
        rotate3D(target3d, center3d, 0, 180*(1+ratio), 0);
end if;

The change is in the else clause, from 180*(1-ratio) to 180*(1+ratio).

So, for those interested in a simple 3D flip transition, here is the code:

Code:

scriptid "Flipper" //DO NOT LOCALIZE
transition "Flipper"; // A remix of Spinback3D by Mike Barber
group "3D Simulation";
wipeCode(20, 100);
producesAlpha;


input angleofaxis, "Angle of Axis", angle, 0, -360, 360 detent 0;
input borderWidth, "Border", slider, 0, 0, 10 snap 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
input borderColor, "Color", color, 255, 0, 0, 0;

code

        on fabs (value _n)
                return (_n<0 ? -_n : _n);
        end;

float w, h, hprime, alpha, offsetangle, angleofview, xprime, yprime;
point source[4], target[4], poly[4], centerofview;
point3d target3d[4], center3d, eye3d;

dimensionsof(dest, w, h);

borderColor.a = 255;
angleofview = 30;

boundsOf(Dest, target);
centerOf(target, centerofview);

source = target;
poly = target;

hprime = h * aspectof(dest);

xprime = w*fabs(cos(angleofaxis)) + hprime*fabs(sin(angleofaxis));
yprime = w*fabs(sin(angleofaxis)) + hprime*fabs(cos(angleofaxis));

scale(poly, centerofview, xprime/w, yprime/h);
rotate(poly, centerofview, angleofaxis, aspectof(dest));

convert2dto3d(centerofview, center3d, 0);
convert2dto3d(centerofview, eye3d, w/(2*tan(angleofview/2)));

scale(target, centerofview, 1, aspectof(dest));
convert2DTo3D(target, target3d, 0);
rotate3D(target3d, center3d, 0, 0, -angleofaxis);

if ratio < 0.5
        rotate3D(target3d, center3d, 0, 180*ratio, 0);
else
        rotate3D(target3d, center3d, 0, 180*(1+ratio), 0);
end if;


rotate3D(target3d, center3d, 0, 0, angleofaxis);
convert3DTo2D(target3d, target, eye3d);
scale(target, centerofview, 1, 1/aspectof(dest));

if srctype1 == knone
        exposedbackground=1;
end if
if srctype2 == knone
        exposedbackground=1
end if;

channelfill(dest, 0, 0, 0, 0);
if ratio < 0.5
        blitrect(Src1, source, Dest, target);
else
        blitrect(src2, source, dest, target);
end if;

if borderwidth > 0
        framepoly(target, dest, bordercolor, borderwidth/renderRes);
end if;


Andy Mees March 12th, 2008 08:16 PM

cool.

lets add a couple of extra controls in there:

input spinfactor, "Spin Factor", slider, 1, 1, 10 snap 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
input doflip, "Flip", checkbox, 1

then change the code snippet to:

if ratio < 0.5
rotate3D(target3d, center3d, 0, spinfactor*180*ratio, 0);
else
if doflip
rotate3D(target3d, center3d, 0, spinfactor*180*(1+ratio), 0);
else
rotate3D(target3d, center3d, 0, spinfactor*180*(1-ratio), 0);
end if
end if;

Mike Barber March 13th, 2008 03:51 AM

Quote:

Originally Posted by Andy Mees (Post 841567)
lets add a couple of extra controls in there

Interesting...

Do you know of any good websites or books for learning FXBuilder? I would really like to dive into this stuff (not that I have any free time, but I am interested).

I'm thinking of trying to hack the Page Peel to see if I can replicate the CC Twister plugin from AfterEffects... that appears to be a much bigger task than a simple flip!

Andy Mees March 13th, 2008 08:08 AM

hands down best place to get your feet wet is by absorbing all you can over on Joe Mallers website ...
http://joemaller.com/fcp/fxscript_basics.shtml

... read all the tutorials, download all the example, explorer and debug scripts, check out all the links from his site. its easily the best resource

also check out his FxScript Reference site
http://www.fxscriptreference.org/

Open up all of Apple's scripts and have at them. Tweak the code and see how it affects the runtime ... a great way to figure out how it all works.

Matt Sandstrom's Too Much Too Soon plugs are excellent and he offers them free and unlocked so that you can see his code and so see how others might code similar effects yet using different function calls
http://www.mattias.nu/plugins/

last but certainly not least, grab the Using FxScript document off Apple's Developer website
http://developer.apple.com/documenta...ngFXScript.pdf


All times are GMT -6. The time now is 05:54 PM.

DV Info Net -- Real Names, Real People, Real Info!
1998-2024 The Digital Video Information Network