Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Layer Space Transform question

  • Darby Edelen

    May 7, 2008 at 3:32 pm

    I think you may need two instances of toWorld(), one to convert the anchor point of the layer to its world position inside the composition and another to convert that position to a world position in the current comp… I can’t test these until I get to work but I think something like this may work:

    l = comp("myComp").layer("myLayer"); //myComp is the composition with the layer (myLayer) that we want to retrieve the anchor point of

    toWorld(l.toWorld(anchorPoint));

    This is assuming that the first call to l.toWorld(anchorPoint) will return the position of the anchor point in the nested composition, and I’m not entirely confident of that. I don’t usually use layer space transforms between comps =O

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

  • Dan Ebberts

    May 7, 2008 at 3:45 pm

    Lloyd,

    I think this is what you’re looking for:

    L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
    CL = thisComp.layer(“Pre-Comp”);
    CL.toWorld(L.toWorld(L.anchorPoint));

    Dan

  • Lloyd Alvarez

    May 7, 2008 at 3:55 pm

    Thanks! That did the trick, but I forgot to mention that I also need the rotations (and orientation) of the null. Seems toWorld only works with vectors or length 2 or 3 (at least that’s what the error message says 😉

    -Lloyd

    https://aescripts.com

  • Dan Ebberts

    May 7, 2008 at 4:22 pm

    That’s a lot tougher. I think the best you can do is to match the world orientation. Give this a try:

    L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
    CL = thisComp.layer(“Pre-Comp”);
    u = CL.toWorldVec(L.toWorldVec([1,0,0]));
    v = CL.toWorldVec(L.toWorldVec([0,1,0]));
    w = CL.toWorldVec(L.toWorldVec([0,0,1]));

    sinb = clamp(w[0],-1,1);
    b = Math.asin(sinb);
    cosb = Math.cos(b);
    if (Math.abs(cosb) > .0005){
    c = -Math.atan2(v[0],u[0]);
    a = -Math.atan2(w[1],w[2]);
    }else{
    a = Math.atan2(u[1],v[1]);
    c = 0;
    }
    [radiansToDegrees(a),radiansToDegrees(b),radiansToDegrees(c)]

    Dan

  • Lloyd Alvarez

    May 7, 2008 at 4:42 pm

    Wow Dan! That’s some serious math going on there!
    Well, I am happy to report that it works!!
    Thank again!

    -Lloyd

    https://aescripts.com

  • Darby Edelen

    May 7, 2008 at 7:36 pm

    [Dan Ebberts] “L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
    CL = thisComp.layer(“Pre-Comp”);
    CL.toWorld(L.toWorld(L.anchorPoint)); “

    Woops, heh… I had assumed when I started writing my code that the expression would be applied to the pre-comp, but when I realized that probably wouldn’t be the case I went back and revised it slightly… of course I forgot to get a reference to the pre-comp layer =O

    Darby Edelen
    Lead Designer
    Left Coast Digital
    Santa Cruz, CA

  • Jonas Espinoza

    August 27, 2008 at 10:02 pm

    L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
    CL = thisComp.layer(“Pre-Comp”);
    CL.toWorld(L.toWorld(L.anchorPoint));

    can i ask about the coding of this?

    I’m a little confused, within the parenthesis you get a 3-value for the world location of the anchor point in the pre-comp, but from that, how does that array interface/translate with the last statement “CL.toWorld”

    why couldnt you just take “CL.toWorld(L.anchorPoint)”

    if anyone gets to this, thanks

  • Dan Ebberts

    August 27, 2008 at 10:25 pm

    The inner toWorld() translates layer “FOLDING SIDE”‘s positon into comp “Pre-Comp”‘s world space. The outer toWorld() takes the inner value as being in the layer space of the layer “Pre-Comp” which is nested within the outer comp and translates it to the outer comp’s world space.

    Probably not necessary if Pre-Comp is the same size as the main comp and has not been moved or rotated from the center of the main comp.

    Dan

  • Jonas Espinoza

    August 27, 2008 at 10:45 pm

    thanks you, that helps a lot

    so in expressions language:

    Layer1.toWorld(x,y,z)

    within the () are the layer-space values being translated “toWorld”

    i guess i wrongly thought to always have the value being fed to the “toWorld” coming to the left of it

  • Kevin Schires

    August 22, 2012 at 10:38 am

    I feel quite bad/scared questionning Mr. Ebberts’s post, as I learned everything about scripting on motionscript.com. I was wondering if there should be -1 or +1 factor based on the value of b in the lign “a = Math.atan2(u[1],v[1]);”

    I slightly modified the expression but I don’t think I introduced any error, here is what I use:


    u = normalize(toWorldVec([1,0,0]));
    v = normalize(toWorldVec([0,1,0]));
    w = normalize(toWorldVec([0,0,1]));
    sinb = w[0];
    b = Math.asin(sinb);
    cosb = Math.cos(b);
    if (Math.abs(cosb) > .0005)
    {
    c = -Math.atan2(v[0],u[0]);
    a = -Math.atan2(w[1],w[2]);
    }
    else
    {
    a = ( (sinb < 0) ? -1 : 1 )*Math.atan2(u[1],v[1]);
    c = 0;
    }
    [radiansToDegrees(a), radiansToDegrees(b), radiansToDegrees(c)];

    Otherwise it seems it would return the opposite of what a should be if b is in the range 270º +/- 0.0005.

Page 1 of 2

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