Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to get the rotation data of a 3D auto-orientation layer

  • Yoondo

    April 6, 2005 at 1:06 am

    You need to turn off the auto orientation in order to gain control over the rotation
    property of the layer.

  • Dan Ebberts

    April 6, 2005 at 2:32 am

    It’s not trivial. If “Layer 1” is your auto-oriented layer, this expression should give the orientation values (apply it to another layer’s orientation property):

    
    L = thisComp.layer("Layer 1"); 
    s = L.scale/100; 
    u = L.toWorldVec([s[0],0,0]);  
    v = L.toWorldVec([0,s[1],0]);  
    w = L.toWorldVec([0,0,s[2]]); 
    sinb = clamp(w[0],-1,1);  
     b = Math.asin(sinb/thisComp.pixelAspect);  
    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

  • Gthief

    April 6, 2005 at 2:53 am

    thanks Dan, i’m not good in writing expression, can you tell me how it work?

  • Dan Ebberts

    April 6, 2005 at 3:56 am

    It’s all 3D vector math and rotation matrix transforms. Easier to use than to explain. 🙂

    Dan

  • Gthief

    April 6, 2005 at 8:30 pm

    🙂 ok, thanks again.

  • Nicholas Weber

    September 21, 2010 at 6:21 pm

    Hello Dan,
    First I’d like to start off by thanking you for all the help that you’ve given people both directly and indirectly.

    So here is my basic issue.

    I have this code attached to a second layer and I am rotating the camera around my main layer only on the x axis (the horizontal axis, left right). When that value reaches 90 degrees, the other two values (Y and Z) return values of 180 degrees and the X value reverses it direction. So basically the camera should be returning a constant x value, increasing from 0 to whatever, but when it hits 90 it starts decreasing, then goes from 0 to 360 (which is ok) but continues to decrease until it reaches 270, then the Y and Z values jump to 0, and the X value begins counting up again, past 360 to 0, then up to 90, where it switches directions again. I have this code as part of a larger project and need to be able to return the full range of numbers so I can drive my animation. Any help on how to do this would be greatly appreciated!

  • Dan Ebberts

    September 21, 2010 at 10:16 pm

    If you’re only rotating around the x axis, you should be able to get that angle by adding a Slider Control to layer pointing at the camera and apply this expression:

    v = toWorldVec([0,0,1]);
    radiansToDegrees(Math.atan2(v[1],v[2]))

    That should give you a value that ranges from 0 to 180 in one direction and 0 to -180 in the other.

    Dan

  • Nicholas Weber

    September 23, 2010 at 12:11 am

    Dan,

    Thank you for the quick reply. Unfortunately I’m not only animating the X axis. This is a small part of a larger project I’m creating, and I was trying to figure out why I was getting inconsistent numbers. The expression you gave me works, but only to a degree and I’m not talented enough to try and figure out how to make it work for my larger project.

    For those trying to figure out another work around, this might work for you. It’s not as involved, but might fix your issue. It works only to a degree. Instead of trying to figure out the rotation of a layer auto oriented towards a camera, link your camera to a null that is placed at the anchor point for the layer. Then animate the null’s rotation to move the camera around, and you will know what the layers orientation is when pointing at the camera based on the null’s rotation. There are obvious draw backs to this solution, including limited camera animation, and only being able to find the orientation of one object in the scene. This was something that I tried, and had limited success with, and again, won’t help with the larger animation..;

  • Jim Lefevre

    October 2, 2014 at 6:58 am

    Once again the amazing Mr Ebberts gives the thing he does best. Skill, clarity and generosity.

    Up until 5 minutes ago I’d been bashing my head against this (returning rotation values from an auto orient layer).

    I really want to learn more about Sin, Cos and radians, they seem so ingrained in so many solutions to these tricky things.

    Many many thanks,

    Jim

    – oh the script worked perfectly by the way!

    http://www.jimlefevre.com

  • Reuben Lara

    October 17, 2020 at 10:13 pm

    I have a 2D layer position set to get its world coordinates from a 3D layer’s (“Layer 1” in the example above) auto-oriented path animation. It tracks perfectly, but now I’d like it to also inherit rotation values. Since the the 2D layer doesn’t have an “orientation” property, how can I translate “Layer 1″s orientation into a 2D rotation? Or is that even possible? I’ve used your “Case Study: 2D Auto Orientation” expression to go from 2D to 2D, but I can’t figure out how to combine it with this scenario. Thanks!

Page 1 of 2

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