Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Expanding mask script in a 3D comp (space transform issues)

  • Expanding mask script in a 3D comp (space transform issues)

    Posted by Theo Burtis on April 8, 2021 at 4:40 pm

    Hi there,

    I’m working on motion graphics for a documentary that’s going need to a lot of expanding masks.

    I thought I’d try and save a little time by writing a script that would create mask paths based on the position value of a null.

    Surely someone has written exactly this script before, and I’d see the answer right in front of me if I understood the space transform functions a little better.

    If y’all don’t mind taking a look, I’d be much obliged,

    Thank you very much!

    -Theo B.

    //this mask expands right to left

    //this section translates the start position from the controller’s layer space to the mask’s layer space.

    var Start_Time = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Start_Time”)(“Slider”);
    var controllerSpace_Position = thisComp.layer(“Write-on_Controller-RectangularMask”).transform.position;
    var compSpace_Position = thisComp.layer(“Write-on_Controller-RectangularMask”).toComp([controllerSpace_Position[0],controllerSpace_Position[1],controllerSpace_Position[2]]);

    //this section defines start and end positions for the expanding mask based on controller’s position.

    var layerSpace_StartPosition = thisLayer.fromComp(compSpace_Position, Start_Time);
    var layerSpace_EndPosition = thisLayer.fromComp(compSpace_Position);

    //this section seperates the start and end variables into X and Y values.

    var StartPoint_Xpos = layerSpace_StartPosition[0];
    var StartPoint_Ypos = layerSpace_StartPosition[1];
    var EndPoint_Xpos = layerSpace_EndPosition[0];
    var EndPoint_Ypos = layerSpace_EndPosition[1];

    //this section creates mask verticies using the above X and Y values.

    var maskDiameter = (thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Mask_Width”)(“Slider”))/2;

    var top_right = [StartPoint_Xpos,(StartPoint_Ypos – maskDiameter)];
    var bottom_right = [StartPoint_Xpos,(StartPoint_Ypos + maskDiameter)];
    var bottom_left = [EndPoint_Xpos,(EndPoint_Ypos + maskDiameter)];
    var top_left = [EndPoint_Xpos,(EndPoint_Ypos – maskDiameter)];
    var maskVerticies = [top_left,top_right,bottom_right, bottom_left];
    createPath(maskVerticies, inTangents = [], outTangents(), isClosed = true);

    Theo Burtis replied 5 years, 5 months ago 1 Member · 2 Replies
  • 2 Replies
  • Theo Burtis

    April 9, 2021 at 5:00 pm

    Update:

    This version is a lot closer and cleaner, but the start point is still in the wrong place:

    //This mask expands left to right from a point designated by a slider effect in a separate null object layer.

    var StartPosition_Slider = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Start_Point”)(“3D Point”)
    var StartPosition_CompSpace = thisLayer.toComp(StartPosition_Slider);
    var StartPosition = thisLayer.fromComp(StartPosition_CompSpace);
    //space transform from slider position in null object space to to mask layer space.

    var Start_Time = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Start_Time”)(“Slider”)
    var End_Time = Start_Time + (thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Duration”)(“Slider”));
    var maskWidth = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Mask_Width”)(“Slider”);
    var maskLength = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Mask_Length”)(“Slider”);
    var Expansion = ease(time, Start_Time, End_Time , 0, maskLength);
    //defines mask expansion parameters.

    var topRight = [StartPosition[0],(StartPosition[1] – (maskWidth/2))]
    var bottomRight = [StartPosition[0],(StartPosition[1] + (maskWidth/2))]
    var bottomLeft = [StartPosition[0] – Expansion ,(StartPosition[1] + (maskWidth/2))]
    var topLeft = [StartPosition[0] – Expansion ,(StartPosition[1] – (maskWidth/2))]
    var maskVertices = [topRight,bottomRight,bottomLeft,topLeft]
    //defines mask vertices based on expansion parameters.

    createPath(maskVertices, [], [], isCLosed = true);

    Despite all the tutorials I’ve watched I still don’t quite understand what combination of toComp and fromComp I need to make this work. If you’ve got any ideas I’m all ears!

    Thx,

    -Theo B.

  • Theo Burtis

    April 11, 2021 at 2:45 am

    Solved:

    //This mask expands left to right from a point designated by a slider effect in a seperate null object layer.

    var StartPosition_Slider = thisComp.layer(“Write-on_Controller-RectangularMask”).transform.position
    var StartPosition_CompSpace = thisComp.layer(“Write-on_Controller-RectangularMask”).toComp(StartPosition_Slider);
    var StartPosition = thisLayer.fromComp(StartPosition_CompSpace);
    //space transform from slider position in null object space to to mask layer space.

    var Start_Time = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Start_Time”)(“Slider”)
    var End_Time = Start_Time + (thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Duration”)(“Slider”));
    var maskWidth = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Mask_Width”)(“Slider”);
    var maskLength = thisComp.layer(“Write-on_Controller-RectangularMask”).effect(“Mask_Length”)(“Slider”);
    var Expansion = ease(time, Start_Time, End_Time , 0, maskLength);
    //defines mask expansion parameters.

    var topRight = [StartPosition[0],(StartPosition[1] – (maskWidth/2))]
    var bottomRight = [StartPosition[0],(StartPosition[1] + (maskWidth/2))]
    var bottomLeft = [StartPosition[0] – Expansion ,(StartPosition[1] + (maskWidth/2))]
    var topLeft = [StartPosition[0] – Expansion ,(StartPosition[1] – (maskWidth/2))]
    var maskVertices = [topRight,bottomRight,bottomLeft,topLeft]
    //defines mask vertices based on expansion parameters.

    createPath(maskVertices, [], [], isClosed = true);

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