ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scaling a 2d Layer in 3D Based on Distance to Camera

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Thomas Kovar
Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 6:11:04 pm

Hey Dan,

Looking for some advice. I'm creating a from-scratch lens flare using all 2d shape layers (except 1 3D controller null layer).

I have everything rigged up and working with the positions, but I cannot figure out the scale as the element is pushed back in z-space, or for that matter forward.

I've tried the script below, but it isn't working on the scale. I have the Z position of the Null layer controlled by a slider. Am I on the right track? Whenever I adjust my flare's z position the scale remains the same as the 'factor' value.

Any help would be very appreciated.

Thanks Dan!

try{
factor = 150;
C = thisComp.activeCamera;
L = thisComp.layer("Null");
d = length(C.position,L.position);
d1 = length(C.position,L.position.valueAtTime(0));
temp = d1/d*factor;
[temp, temp]
}catch(err){
no3d = thisComp.layer("Controller").effect("Scale")("Slider");
[no3d, no3d]
}


Return to posts index

Dan Ebberts
Re: Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 6:30:09 pm

I don't that expression will do anything unless you keyframe and move the null layer. It's basing everything on how much the distance between the null and the camera has changed since time=0.

Dan



Return to posts index

Thomas Kovar
Re: Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 7:22:02 pm

Thanks for clarifying that! So, is there any other method/expression to account for perspective on the scale?


Return to posts index


Dan Ebberts
Re: Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 7:42:34 pm

You need a reference point. In that expression it's where the layers are at time=0. You could instead just embed something the the code that defines the distance where the scale is 100 percent. I haven't tested it, but it would look something like this:


try{
factor = 100;
C = thisComp.activeCamera;
L = thisComp.layer("Null");
d = length(C.position,L.position);
dRef = 1000;
temp = d1/dRef*factor;
[temp, temp]
}catch(err){
no3d = thisComp.layer("Controller").effect("Scale")("Slider");
[no3d, no3d]
}


Dan



Return to posts index

Dan Ebberts
Re: Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 7:44:45 pm

Nope, that's wrong. This should be closer:


try{
factor = 100;
C = thisComp.activeCamera;
L = thisComp.layer("Null");
d = length(C.position,L.position);
dRef = 1000;
temp = dRef/d*factor;
[temp, temp]
}catch(err){
no3d = thisComp.layer("Controller").effect("Scale")("Slider");
[no3d, no3d]
}



Dan



Return to posts index

Thomas Kovar
Re: Scaling a 2d Layer in 3D Based on Distance to Camera
on Mar 22, 2017 at 8:22:58 pm

Hey Dan,

That's it. Thank you very much!


Return to posts index

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