Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Clamping x position on after effects

  • Meng Zhang

    April 10, 2017 at 9:12 pm

    Dan, thank you for your quick response. I agree with you, although I didn’t find a perfect solution, I managed to find out a way to detect if the position is within a mask using this attached code by M. Katz based on Nirg’s approach:

    By changing the polygon to to a layer mask, I successfully got a right result. And it is all I need for now. I just need to detect the position key frames outside the mask and delete them. I’m planning looping through the key frames and delete those that are out of range.

    I hope to take the chance to thank you for all your awesome answers in this forum. I have always been learning a lot from you. Thank you.

    function pointIsInPoly(p, polygon) {
    var isInside = false;
    var minX = polygon[0].x, maxX = polygon[0].x;
    var minY = polygon[0].y, maxY = polygon[0].y;
    for (var n = 1; n < polygon.length; n++) {
    var q = polygon[n];
    minX = Math.min(q.x, minX);
    maxX = Math.max(q.x, maxX);
    minY = Math.min(q.y, minY);
    maxY = Math.max(q.y, maxY);
    }

    if (p.x < minX || p.x > maxX || p.y < minY || p.y > maxY) {
    return false;
    }

    var i = 0, j = polygon.length - 1;
    for (i, j; i < polygon.length; j = i++) {
    if ( (polygon[i].y > p.y) != (polygon[j].y > p.y) &&
    p.x < (polygon[j].x - polygon[i].x) * (p.y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x ) {
    isInside = !isInside;
    }
    }

    return isInside;
    }

  • Dan Ebberts

    April 10, 2017 at 10:54 pm

    So this is for a script? That should work because scripting has access to mask/path vertices.

    Dan

  • Meng Zhang

    April 11, 2017 at 12:34 am

    Hey Dan,

    It is a script. My fault not making this clear. I didn’t see it is under expression discussion. Thank you again for help!

Page 2 of 2

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