Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Fit path boundaries by scaling when comp layer is parented

  • Fit path boundaries by scaling when comp layer is parented

    Posted by Tomas Bumbulevičius on March 30, 2022 at 9:17 pm

    Hey guys! I am thinking about approach to figure out scaling, that shape layer in a comp would be filled in the other comp’s boundaries.

    Imagine a shape path, which is in a comp X [100×100] which takes unrestricted amount of space [250×250] (can be literally anything, [50×50] or [500×500], but I can’t resize it to fit inside this comp)

    Then this pre-comp is added in bigger comp Y (lets say [1000×1000]) with continuous rasterization applied (to reveal path off-boundaries) and being scaled by other controller (centered!), which is parented to slider (jeez, haha!). Is there a way to figure out scaling value, in order to fit comp X within comp Y?

    I thought of:
    1. Taking comp X size and shape layer top left/bottom right coordinates.
    2. Re-calculate its size based on the scaling in other comp.

    Its kind of inception of a loophole. What I am missing here is a way to calculate size scaling compensation when multiple re-parenting happens through linkage and expressions. Any ideas? Thanks a ton!

    Tomas Bumbulevičius replied 4 years, 1 month ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    March 31, 2022 at 12:44 am

    It’s hard to picture exactly how you have things set up, but if you have “Shape Layer 1” in a precomp named “shape”, a scale expression like this on the precomp layer “shape” in the main comp, it should fit the shape to the main comp’s size:

    L = comp("shape").layer("Shape Layer 1");

    r = L.sourceRectAtTime(time,false);

    ul = L.toComp([r.left,r.top]);

    lr = L.toComp([r.left+r.width,r.top+r.height]);

    w = lr[0] - ul[0];

    h = lr[1] - ul[1];

    if (thisComp.width/thisComp.height > w/h)

    s = thisComp.height/h

    else

    s = thisComp.width/w;

    [s,s]*100

    Sorry if that’s no help at all…

  • Tomas Bumbulevičius

    March 31, 2022 at 8:45 am

    Hey Dan, thanks a lot for sharing! The way you described it gave me a thought to clarify it properly. But just in case, I tested your described approach and it indeed works – thus – thumbs up for that already! It fits.

    I need to scale not the “shape” comp itself, but adjust the controller/null in the comp, that it would set/accommodate scale in the main composition, based on shape’s size in pre-comp.

    Through logic tree, it would look like the following:

    Inside comp Y:

    “controller” null – which scale animates in time from value K to L
    “shape” aka comp X based on my definition – parented to controller.
    “Shape Layer 1” – path layer inside “shape” comp aka compX.

    Essentially, I want to modify scale end-value “L”, to fit the shape’s path size in the precomp when scaling down. What it will do is to allow changing shape in the pre-comp, while making sure scaling happens up to the proper zooming level, fitting whole size of the shape (or even adding some padding). Unfortunately, I can’t modify “shape” scaling directly, because it is linked by other logic. Do you think it can be possible, or at least how to compensate the parenting when comparing scaling levels? Thanks a ton for any hint!

  • Dan Ebberts

    March 31, 2022 at 5:42 pm

    I’m still not sure I have it pictured exactly correctly yet, but this variation, applied to the controller null’s scale, should fit the shape to the “main” comp:

    L = thisComp.layer("Shape Layer 1");

    r = L.sourceRectAtTime(time,false);

    ul = L.toComp([r.left,r.top]);

    lr = L.toComp([r.left+r.width,r.top+r.height]);

    w = lr[0] - ul[0];

    h = lr[1] - ul[1];

    if (comp("main").width/comp("main").height > w/h)

    s = comp("main").height/h

    else

    s = comp("main").width/w;

    [s,s]*100

  • Tomas Bumbulevičius

    April 6, 2022 at 9:14 am

    Hey Dan, thanks a lot for modified version of this! While I haven’t managed to make it work still, will try to break it down and see what could be the reason for it. Going to update here if figure it out, yet the setup I have is quite complex and unique for single-purpose I guess.

  • Tomas Bumbulevičius

    April 13, 2022 at 4:32 am

    Here is an example of what I am making, to have a visual sense and clarity:
    https://www.instagram.com/tv/CcNHOmBFS67

    The goal was to make sure “zoom out” goes far enough that a whole path map is visible, but because of multiple parenting inside the master comp, I yet to find the solution.

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