Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions expression to link focus distance…?

  • expression to link focus distance…?

    Posted by Doug Nash on January 14, 2008 at 4:41 am

    Hey all:

    I’ve spent some timing searching through a bunch of “depth of field” related posts, but I haven’t had much luck with what I’m specifically looking to accomplish.

    I’m looking to link the 3D camera’s “focus distance” to the exact distance between the camera’s “position” and “point of interest”. That way, whatever 3D layer I point the camera’s point of interest at, will automatically be in focus.

    Does this make sense? It seems like a feature which should be built in to the camera, and I’ve always wondered if I’m just missing something terribly obvious…?

    Thanks to anyone who can help!!!

    Ben Watkins replied 11 years, 7 months ago 6 Members · 11 Replies
  • 11 Replies
  • Darby Edelen

    January 14, 2008 at 5:21 am

    This should work just fine:

    p1 = activeCamera.position;
    p2 = activeCamera.pointOfInterest;

    length(p1, p2);

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Doug Nash

    January 14, 2008 at 6:08 am

    Thank you so much for posting that. But would you mind giving me a little further help? I don’t entirely understand how to use that expression. I copied it, verbatim, and pasted it in the expression channel in “focus distance” in the AE camera, but it brings up a “property” warning.

    Would you mind guiding me through the proper steps of implementing this expression?

    I really appreciate it.

  • Darby Edelen

    January 14, 2008 at 6:43 am

    My mistake, I think this should work:

    p1 = activeCamera.transform.position;
    p2 = activeCamera.pointOfInterest;

    length(p1, p2);

    It’s hard checking code when I don’t have AE on this computer =)

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Doug Nash

    January 14, 2008 at 3:17 pm

    Great. Thanks. I’ll try this new code. But, where do I paste this expression? Is it in the “focus distance” channel?

  • Darby Edelen

    January 14, 2008 at 5:58 pm

    Yes, the expression returns the distance, or length(), between two points. In this case the points are the active camera’s position and it’s point of interest. You actually should the activeCamera portion of the expression since you’re applying this expression to a camera’s focus property (it will use the position and point of interest of the camera you apply it to):

    p1 = position;
    p2 = pointOfInterest;

    length(p1, p2);

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Doug Nash

    January 14, 2008 at 8:21 pm

    Thanks! That works, and is exactly what I was hoping for. That is such an elegantly simple script.

  • Chris Jeffries

    October 15, 2009 at 7:27 pm

    Just wanted to say thanks for the help also – was just what the doctor ordered! 😀

  • Olivier Parent

    February 23, 2011 at 9:39 am

    Hello,
    I am working on AEP CS5. The script doesn’t work…
    Help !!!
    Thanks a lot !

  • Kevin Dooley

    August 22, 2011 at 11:30 pm

    This worked very well. I modified it some slightly so that I could use a null object’s position…

    Also, I’m in CS 5.

    p1 = thisComp.layer("Focus Pull").transform.position;
    p2 = position;

    length(p1, p2);

    Kevin Dooley
    Video Director
    Lake Pointe Church

  • Kevin Dooley

    August 23, 2011 at 9:16 pm

    I lied… Well, I didn’t realize when I posted… This doesn’t really work. I ended up using the code below from Dan Ebberts’s website.

    https://motionscript.com/design-guide/auto-focus.html

    target = thisComp.layer("Focus Pull");
    v1 = target.toWorld(target.anchorPoint) - toWorld([0,0,0]);
    v2 = toWorldVec([0,0,1]);
    dot(v1,v2)

    Kevin Dooley
    Video Director
    Lake Pointe Church

Page 1 of 2

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