FORUMS: list search recent posts

Auto Scaling Expression for layers with wiggle

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Philip Bowser
Auto Scaling Expression for layers with wiggle
on Jan 7, 2014 at 8:27:51 pm

I've been straining my brain trying to come up with a solution to auto-scale a layer after a wiggle has been applied to the position and rotation properties. So that as a layer wiggles around, it will automatically scale up and down to fill up the edges of the frame that its moving away from. Similar to how the Warp Stabilizer will auto scale when reducing motion.. but I'm looking to auto-scale when ADDING motion.

I've been able to hack something together only if the position wiggles, but when I add rotation I just can't seem to find a common ratio that it needs to scale by. The trigonometry goes a little above my head on this one.

My position auto-scale expression works like this. It's probably not the best way to do it, but its the way my brain could understand things! If you have a better way please let me know!


compHeight=thisComp.height/2;
compWidth=thisComp.width/2;
layerX=transform.position[0];
layerY=transform.position[1];
xDistance=Math.abs(compWidth-layerX);
yDistance=Math.abs(compHeight-layerY);
xDistPercentage=xDistance/compWidth*100;
yDistPercentage=yDistance/compHeight*100;
autoScale=null;

if(xDistPercentage > yDistPercentage){

if(layerX < compWidth){
layerX=layerX+(xDistance*2)
}

autoScale=value/compWidth*layerX

}else{

if(layerY < compHeight){
layerY=layerY+(yDistance*2)
}

autoScale=value/compHeight*layerY
}

autoScale



Which will automatically scale the layer up like this if the layer is moved from center:


However whenever rotation is applied, it fails hard:



Does anyone know of any magic to help this out? Is there a way to determine how much the layer needs to additionally scale by based on how much rotation is applied?

Please help!!

Cheers,
Philip Bowser


Return to posts index

Steve Crook Jr
Re: Auto Scaling Expression for layers with wiggle
on Jan 8, 2014 at 2:51:58 pm

Hi! The expression(s) that you are looking for are way out of my league - I am a sometimes AE user just to get small projects done.

I do not understand how you want to use the resulting footage, but it would seem to me that you just need to make the comp large enough for all of the effects to render within the frame.

You have likely already thought of this and ruled it out, but I know that sometimes I spend days trying to solve something that I have overlooked.

Hope it helps!


Return to posts index

Philip Bowser
Re: Auto Scaling Expression for layers with wiggle
on Jan 8, 2014 at 7:18:15 pm

Hey Steve,

Thanks for your response! My mistake, I wasn't terribly clear about my actual use for this. I'm looking to build a shaky-cam/wiggle preset that will wiggle/shake my footage around. So my goal is to hopefully be able to wiggle this footage with a basic wiggle expression and have a separate expression in the scale property that will automatically determine how much the footage needs to scale up by to compensate for the layer being displaced from the edges of the frame. Assuming that the footage is the same dimensions as the comp. My stumbling block right now is knowing how much the footage needs to scale up by when rotation is applied to compensate for the corners of the frame.

I've got a project I'm working on which has shake in almost every shot! Seriously way too many shots.. Kind of ridiculous.. But I figured if I can build a tool this one time I will probably use it for every project that has any kind of shake!


Return to posts index


Dan Ebberts
Re: Auto Scaling Expression for layers with wiggle
on Jan 8, 2014 at 8:22:24 pm

So are you looking for an expression that will scale a comp-sized layer just enough to fill the comp view (where the layer may be off-center and rotated)?


Dan



Return to posts index

Philip Bowser
Re: Auto Scaling Expression for layers with wiggle
on Jan 9, 2014 at 2:06:12 am

Dan! Yes! You said that way easier than I could. I just couldn't find the right words for some reason. Yikes.

Do you have any magic up your wizard sleeves?

It'd be the greatest help. Thanks Dan!


Return to posts index

Dan Ebberts
Re: Auto Scaling Expression for layers with wiggle
on Jan 9, 2014 at 6:14:31 am

This might be close to what you're looking for:


function getScale(x,y){
s = 1;
if (y < 0){
if (x < 0){
if (-y/height > -x/width){
s = 1 - 2*y/height;
}else{
s = 1 - 2*x/width;
}
}else if (x > width){
if (-y/height > (x-width)/width){
s = 1 - 2*y/height;
}else{
s = 1 + 2*(x-width)/width;
}
}else{
s = 1 - 2*y/height;
}
}else if (y > height){
if (x < 0){
if ((y-height)/height > -x/width){
s = 1 + 2*(y-height)/height;
}else{
s = 1 - 2*x/width;
}
}else if (x > width){
if ((y-height)/height > (x-width)/width){
s = 1 + 2*(y-height)/height;
}else{
s = 1 + 2*(x-width)/width;
}
}else{
s = 1 + 2*(y-height)/height;
}
}else if (x < 0){
s = 1 - 2*x/width;
}else if (x > width){
s = 1 + 2*(x-width)/width;
}
return s
}

p = fromComp([0,0]);
ns = getScale(p[0],p[1]);
p = fromComp([thisComp.width,0]);
ns = Math.max(ns,getScale(p[0],p[1]));
p = fromComp([thisComp.width,thisComp.height]);
ns = Math.max(ns,getScale(p[0],p[1]));
p = fromComp([0,thisComp.height]);
ns = Math.max(ns,getScale(p[0],p[1]));
[ns,ns]*100


It assumes that you have scale set to 100% before you apply the expression and that the comp and the layer are square pixels.


Dan



Return to posts index


Philip Bowser
Re: Auto Scaling Expression for layers with wiggle
on Jan 9, 2014 at 6:15:50 pm

Dan! You're a wizard... How did you figure this out so fast!??

This is perfect. Thank you a bunch! I'm still trying to decode this to understand it completely...

I've combined this with your expressions to wiggle properties based on layer markers. This is going to be a huge help, can't thank you enough! Just in case you had an interest, here's the preset, now with your autoscale function built in!

6980_quake.ffx.zip

(It's a "pseudo effect" so it will show up as "Missing" in your effects bin, however all the functionality will work)

Philip. Bowser


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]