Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions help with Dan’s “auto focus” expression… but more complicated

  • help with Dan’s “auto focus” expression… but more complicated

    Posted by Scott Geersen on August 20, 2007 at 2:50 am

    Hi Dan,
    I’ve been playing with your auto focus expression as I wanted to add some depth of field to my invigorator objects.
    the way you explained it was great and i had it working in no time.

    I’ve set it up slightly different to your original example. I have a null parented to my camera, and this null can slide back and forth along the z axis, and drives my focus distance, so i can pull focus midway through a shot. i imagine it like a trombone, with the camera as the mouthpiece and my focus null as the sliding hand-piece.

    so what i’m doing is calculating the projected distance (if i’m using the correct terminology?) from my invigorator null, to this focal-depth null, to give me my blur amount. if they occupy the same plane, it’s in focus. if my object moves towards or away, it goes out of focus, or if i animate my focus null to pull focus from background to foreground, it works too. all is good.

    problem: when i spin my invigorator null around so it tumbles through space, the z’s are not always pointing at each other, so i’m getting fluctuating distance.

    i’m confusing myself trying to work out to which layer my expression should apply. i’ve got this expression on my tumbling invigorator null:

    target = thisComp.layer(“CameraFocus(Z)”);
    v1 = target.toWorld(target.anchorPoint) – toWorld([0,0,0]);
    v2 = toWorldVec([0,0,1]);
    dot(v1,v2)

    but i suspect needs to be the other way around, with the expression on my focus null, not my invigorator null. but since i have a lot of objects, it made sense to apply the distance expression to each object’s null, rather than trying to contain all the expressions on the focus null.

    how would you go about setting something like this up?
    is there a way to use the dot function to generate auto-focus when one of your layers in tumbling through space with animated x, y, AND Z rotations?

    thanks,
    scott.

    Dan Ebberts replied 18 years, 9 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    August 20, 2007 at 2:25 pm

    The expression has to be applied to the camera’s focus distance, so you’ll need to add some code to manage defining the current target layer. If you have CS3, I think I’d do it with marker comments, where the comment would have the name of the current target layer. If you want to try that and need help with the code, just let us know.

    The orientation of the target object shouldn’t matter.

    Dan

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