-
end trim to reveal motion path dinamically created
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!