Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions expression to maintain scale on a 3d layer as if z = 0

  • expression to maintain scale on a 3d layer as if z = 0

    Posted by Scott Mcdonnell on February 16, 2009 at 1:30 pm

    Hi,

    I am looking to have an expression that adjusts the scale dependent on the z value of the layer so that the scale appears exactly as if the z value is 0.

    For example in a 1920×1080 square pixel comp with no independent camera
    the following values look right to my eye:
    z=0 : scale=100%
    z=-1000 : scale=62.5%
    z=-2000 : scale=25%
    but I cannot figure out what the formula would involve. Can anyone help or point me in the right direction? Thanks!

    Evan Viera replied 10 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Filip Vandueren

    February 16, 2009 at 4:57 pm

    Hi Scott,

    I think this should take care of it in most situations:

    add this to the scale property of your layer:


    a=toComp(anchorPoint);

    c=thisComp.activeCamera;
    b=c.fromComp(a);

    value * b[2]/c.zoom;

    You do need a camera though.

  • Scott Mcdonnell

    February 16, 2009 at 5:26 pm

    br>Hi Filip,

    Thanks for the code, that seems to still change the scale slightly as the z goes up. I found a formula for focal length which seems to work:


    focalLength = 2666.67; //could be "thisComp.activeCamera.zoom;"
    z =transform.anchorPoint[2];
    scaleFactor = focalLength/( focalLength+ z);
    [scaleFactor*100,scaleFactor*100, scaleFactor*100]

    This holds the scale exactly right but the x and y of the anchor point moves as the z value changes depending on the distance from the centre. I have played around with adjusting the anchorPoint x and y too:


    z = transform.anchorPoint[0];
    diffX = 0; diffY = 0;
    focalLength = 2666.67;
    scaleFactor = ( focalLength+ z)/focalLength;
    cx = 1920/2; cy = 1080/2;
    px = transform.position[0];
    py = transform.position[1];
    dx =(px -cx)*scaleFactor; dy =(py -cy)*scaleFactor;
    diffX = cx+dx-px; diffY = cy+dy-py;
    [transform.anchorPoint[0] + diffX, transform.anchorPoint[1] + diffY, z]

    Now it just moves when you parent it to another layer. oh well – I will keep at it!

  • Filip Vandueren

    February 16, 2009 at 9:32 pm

    I’m not following you.
    I thought you needed it to just scale so it would appear the same scale independent of z.
    If you also want to move the layer with the camera, why don’t you just parent it to the camera ?

  • Evan Viera

    September 23, 2015 at 9:59 pm

    thanks Filip, i’m having trouble getting this to evaluate for only one frame. basically i want to use the properties of the camera at the first frame only to calculate the scale. any help?

  • Evan Viera

    September 23, 2015 at 10:34 pm

    nevermind, i got it modifying this thread’s expression

    https://forums.creativecow.net/thread/227/15418

    – –

    cam = thisComp.activeCamera;
    distance = length(sub(position, cam.position.valueAtTime(0)));
    scale * distance / cam.zoom;

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy