Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Attach depth of field control to slider to expression

  • Attach depth of field control to slider to expression

  • Pawel Milewski

    October 8, 2021 at 12:58 pm

    Hi

    Anyone knows how to attach depth of field control to slider in expression which generates automatically when “Link Focus Distance to Layer” is pressed. I want to have more control in depth of field.

    Expression goes like this:

    var usingLegacyEngine = !!$.version;

    try{

    thisLayer( “ADBE Transform Group” )( “ADBE Anchor Point” ).value;

    }catch(err){

    var quote = String.fromCharCode(34);

    if ( usingLegacyEngine ) {

    $.error = “” + quote + “Camera 1″ + quote + ” cannot be a One-Node camera”;

    } else {

    throw “” + quote + “Camera 1″ + quote + ” cannot be a One-Node camera”;

    }

    }

    var targetLayer = thisComp.layer(“Camera Target and Controller”);

    try{

    targetLayer.transform.position[2]

    }catch(err){

    var quote = String.fromCharCode(34);

    if ( usingLegacyEngine ) {

    $.error = “” + quote + “Camera Target” + quote + ” cannot be a 2D layer. The Focus Distance of ” + quote + “Camera 1″ + quote + ” can only be set to follow 3D layers.”;

    } else {

    throw “” + quote + “Camera Target” + quote + ” cannot be a 2D layer. The Focus Distance of ” + quote + “Camera 1″ + quote + ” can only be set to follow 3D layers.”;

    }

    }

    var cameraPosition = [transform.position[0] * thisComp.pixelAspect, transform.position[1], transform.position[2]];

    var cameraPoi = [transform.pointOfInterest[0] * thisComp.pixelAspect, transform.pointOfInterest[1], transform.pointOfInterest[2]];

    if ( thisLayer.hasParent ){

    cameraPosition = thisLayer.parent.toWorld( cameraPosition );

    cameraPoi = thisLayer.parent.toWorld( cameraPoi );

    }

    var targetPosition = [targetLayer.transform.position[0] * thisComp.pixelAspect, targetLayer.transform.position[1], targetLayer.transform.position[2]];

    if ( targetLayer.hasParent ){

    targetPosition = targetLayer.parent.toWorld( targetLayer.transform.position );

    }

    var cameraVector = sub( cameraPoi, cameraPosition );

    if( length( cameraVector ) != 0 ) {

    cameraVector = normalize( cameraVector );

    }

    var targetVector = sub( targetPosition, cameraPosition );

    dot( targetVector, cameraVector );

    Thanks in advance

Viewing 1 of 1 posts

Log in to reply.

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