Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions 3D Position to Angle

  • 3D Position to Angle

    Posted by Nils Hammers on March 8, 2024 at 11:29 am

    Hey,
    What would be the way to convert one 3D layer’s pos to angle for an effect within another 3D layer?
    I tried using :

    L = thisComp.layer(“Light_POS”) ;
    a = fromWorld(L.toWorld(L.anchorPoint)) ;
    lookAt([0,0], a)
    ;

    Yet I get Array 3 result for a and lookAt, which I can’t feed into angle.

    Brie Clayton
    replied 2 years, 2 months ago
    4 Members · 8 Replies
  • 8 Replies
  • Yoan Boisjoli

    March 8, 2024 at 2:49 pm

    Based on your expression, it looks like you’re attempting to calculate the angle directly, but you’re facing issues with the 3D array result. You need to convert this 3D rotation into a 2D angle. Here’s a more direct approach:

    L = thisComp.layer(“Light_POS”);

    a = fromWorld(L.toWorld(L.anchorPoint));

    look = lookAt([0,0,0], a);

    // Extracting the Z rotation for 2D use

    angle = look[2];

    This will give you the z-component of the rotation, which is typically what you need for a 2D rotation effect in After Effects. If you need a different angle (like a pitch or roll for a specific effect), you would use the corresponding component of the array (look[0] for pitch or look[1] for roll).

    If you’re trying to use this angle for a specific property that requires a different format or range (for example, some effects might use radians instead of degrees, or you might be looking to adjust the angle range), please provide more details about the effect you’re targeting. This would allow for a more tailored solution.

  • Nils Hammers

    March 8, 2024 at 3:24 pm

    Yeah, it made no errors, thank you! 😉
    However, the result was not the expected behavior – the angle is changing, however, unpredictably slow, then suddenly to the opposite direction, even the Light_POS had barely moved.
    Haven’t figured out what is what, yet at the moment look[1] works better than look[2] and look[0].
    Will proceed the next week.

  • Yoan Boisjoli

    March 8, 2024 at 3:32 pm

    This might be due to how After Effects interpolates angles, especially if the Light_POS layer’s movement is primarily along one axis. If look[1] (pitch) works better than look[2] (yaw), it suggests the movement’s impact on rotation is more predictable along that axis.

    To address sudden directional changes, consider using a smoothing expression like smooth() on the resulting angle, and if necessary, refine your setup or calculation logic to better align with the specific dynamics of your scene.

  • Dan Ebberts

    March 9, 2024 at 1:15 am

    What 2D effect are you using? It might help to post a diagram of exactly what you’re trying to do.

  • Nils Hammers

    March 9, 2024 at 4:34 pm

    Hey Dan,

    I am not behind my workstation, can tell you just from the memory.
    I am trying to simulate rim light and shadow on tree leaves, using the Emboss effect, some sort of toon shading.
    The comp consists of 3D layers only.

    — There’s a root null, to which some fifty leaf copies are parented (+ bunch of expressions, including for Orientation and RotXYZ to auto orient to center and simulate gravity and wind, randomize, curvature). Each leaf has Emboss, which has angle property.
    — Then there is that Light_POS null, toward which I was trying to aim every leaf’s Emboss effect. Can’t use real light as it would impact the shading, there is no switch for Accept Lights in Advanced 3D render engine.
    Perhaps there are better ways to simulate such kind of shading. If any alternative comes into mind, please spill the beans. 🙂 I was considering using Particular, however, here I need quite large, slightly bent leaves the character interacts with, so I went for the aforementioned setup.

    Thanks, best,
    NH

    P.s. If description wasn’t helpful, can post some screenshots on Monday.

  • Dan Ebberts

    March 9, 2024 at 5:25 pm

    Really hard to say without seeing it, but I suspect it will end up looking something like this:

    L = thisComp.layer(“Light_POS”);

    p1 = L.toWorld(L.anchorPoint);

    p2 = toWorld(anchorPoint);

    v = p1 – p2;

    v2 = fromWorldVec(v);

    -radiansToDegrees(Math.atan2(v2[1],v2[0]))

  • Nils Hammers

    March 11, 2024 at 2:23 pm

    Thank you Dan,
    Your expression works like a charm, except it just needed some minor adjustment for the result:

    L = thisComp.layer(“Light_POS”) ;
    p1 = L.toWorld(L.anchorPoint) ;
    p2 = toWorld(anchorPoint) ;
    v = p1 – p2 ;
    v2 = fromWorldVec(v) ;
    +radiansToDegrees(Math.atan2(v2[1],v2[0])) -90 ;

    Thankyouthankythankyouthankyou Dan!
    This particular case is solved. 🎆

  • Brie Clayton

    March 11, 2024 at 2:29 pm

    Thank you for your solution, Dan!

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