Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions World Orientation of Child Object Expression Bug

  • World Orientation of Child Object Expression Bug

    Posted by Keenan Parry on February 9, 2020 at 2:17 am

    Hey all! Back again. In 2009, Dan Ebberts was kind enough to share an expression that retrieved the global orientation of a layer regardless if it was parented or not. The post I got it from is here:
    https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=13049&univpostid=13049&pview=t

    This expression is a little over my head but it became essential to a rather complex template I have been working on. I recently discovered a bug in this expression that has been throwing me for a loop. It has worked so perfectly for so long(literal years) , that I only recently had a project that introduced the specific circumstances that produce a bug. I’m at a point where I need to find a solution to this or my template starts breaking apart. I attempted to research how vectors work in After Effects but even when I tried a slight rewrite myself, I was getting the same exact problem.

    It’s a bit hard to to describe, so I made a demo project file for anyone that wants to take a crack at fixing this. I labeled everything and tried to be as clear as possible with how the bug presents itself vs the expected behavior.
    https://www.dropbox.com/s/01t8napcrm483sr/Global_Orientation_Bug_Demo.aep?dl=0

    Basically what happens is when the parent layer get close to or hits specific values, it causes the child orientation to invert. I’ve narrowed it down to these four combinations that causes wrong behavior:
    270, 270, 0
    90, 270, 0
    0, 270, 270
    0, 270, 90

    This will make a lot more sense if you download the demo file-I tried to be as straightforward as I could, it’s very easy to see the problem once it’s happening in front of you. I deeply appreciate anyone willing to take a crack at this. I realize this is a bit difficult so I understand that any time invested helping me out is very generous.

    And Dan, if you read this- you’ve helped me far more times than is possible to count and I cannot explain how helpful that expression has been to me as is. Trying to fix this/find alternatives has been breaking my brain all week- so going to see what the creative cow community thinks. Thanks all!

    //World Orientation Output
    C = thisComp.layer("PARENT");
    u = normalize(C.toWorldVec([1,0,0]));
    v = normalize(C.toWorldVec([0,1,0]));
    w = normalize(C.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)]

    Keenan Parry replied 6 years, 5 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 9, 2020 at 7:31 am

    Based on the angles that are causing the issue, I’d guess that it’s gimbal lock, which is tough to deal with. One fairly drastic solution that I’ve used is to switch to quaternions, but that’s a lot of work (and code) to implement, but it does eliminate the problem. Sorry, I wish I had better news.

    Dan

  • Keenan Parry

    February 9, 2020 at 8:03 am

    Yikes, I think you’re right. How insane it is to consider going down this path further? I am ultimately curious to see the solution in practice but it’s starting to look grim based on my initial research.

  • Keenan Parry

    February 9, 2020 at 8:08 am

    Ah, I’m starting to see the problem. May have to abandon this idea. Thanks for help Dan.

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