Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions end trim to reveal motion path dinamically created

  • end trim to reveal motion path dinamically created

    Posted by Peter Zeet on January 7, 2019 at 5:04 pm

    hi all!
    having discovered this gem here:
    https://gist.github.com/yone80/389722e4d70981828b41ce3b3d4cefce
    which applied to the path property of a shape layer, it dinamically creates the shape of the motion path
    I want to automate this and make the main layer actually reveal this created shape layer. So I tought an easy way was to add a trim paths property to te shape layer, and then just link the end trim value to the main layer’s position keyframes time values (1st time and last keyframe time), with a linear function. BUT what I thought it was going to be easy, I’m blocked and there is no way to make t work properly.
    Any ideas?
    so: 1. there is a main layer.
    2. there is a shape layer with the awesome code Satoru Yonekura wrote, to make the shape path mimic the main layer’s motion path.
    3. I apply a trim path to the shape layer.
    4. how to link the end trim to the main layer somwhow, to make it act as a visible motion path?
    5. maybe there is no need f creating a trim effect and can be fixed inside the main expression?

    here is the code to add to the shape path: (I past it here so it’s more easy to go thru the thread. If there is any incovenience pasting it from another source, just let me know and I will delete this and let just the link. Said that, all the copyrights, greetings and hails for Satoru Yonekura)

    seg = Math.floor( Math.max(effect("Segments")("Slider"), 2) );
    starttime = effect("Start Time")("Slider");
    endtime = effect("End Time")("Slider");
    smooth = effect("Smooth")("Checkbox") > 0;

    targetlayer = thisComp.layer("Tip");

    timemin = Math.min(starttime, endtime);
    timemax = Math.max(starttime, endtime);
    cv = [];
    for(var i = 0; i < seg + 1; i++){
    f = linear(i, 0, seg, timemin, timemax);
    cv.push( fromCompToSurface( targetlayer.toComp( targetlayer.anchorPoint, f ) ) );
    }

    // quadratic curve bezier approximation.
    if(smooth){
    points = [];
    intan = [];
    outtan = [];

    for(var i = 0; i < cv.length; i++){
    if(i == 0){
    points.push(cv[i]);
    intan.push([0,0]);
    outtan.push( (cv[i+1] - cv[i]) * (2 / 3) );
    }else if(i == cv.length-1){
    points.push(cv[i]);
    intan.push( (cv[i-1] - cv[i]) * (2 / 3) );
    outtan.push([0,0]);
    }else{
    pos = cv[i] + div(cv[i+1] - cv[i], 2);
    points.push(pos);
    intan.push( (cv[i] - pos) * (2 / 3) );
    outtan.push( (cv[i+1] - pos) * (2 / 3) );
    }
    }

    createPath(points, intan, outtan, false);
    }

    if(!smooth) createPath(cv, [], [], false);

    thanks in advance!

    Peter Zeet replied 7 years, 4 months ago 1 Member · 1 Reply
  • 1 Reply
  • Peter Zeet

    January 9, 2019 at 12:44 am

    any ideas?
    I found this super old post, where maybe there is a possible way, it is about calculating the total distance of an animated motion track.
    https://forums.creativecow.net/archivethread/2/540727#540907

    I think that distance can be used to measure the movin lead layer and then substract to the position til the end somehow?
    Here is the code Dan Ebberts and Filip Vandueren came up with:

    d = 0; //distance traveled
    startPos = position.value_at_time(0);
    endPos = startPos;
    f = 0;

    precision=2; // doubled precision

    while (f <= time/(this_comp.frame_duration/precision)){
    startPos = endPos;
    endPos = position.value_at_time(f*this_comp.frame_duration);
    d += length(startPos,endPos)
    f=f+(1/precision);
    }
    d

    thanks!

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