Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects expressions: XYZ coord to angle?

  • expressions: XYZ coord to angle?

    Posted by John Hammond on December 1, 2008 at 12:43 pm

    Hi All,

    Just a quick question to see if this kind if thing is possible. I am working on a project in After Effects where I have some paintballs being fired at a surface and bursting. I have applied the ‘color emboss’ effect to the ‘slime’ on the wall, which makes it look more like a shiny fluid.

    I am using a 3d light in the scene, and it’s position will be animated.

    I am wondering if there is a way -maybe using expressions, to make the XY(Z) position of my light, control the ‘light direction’ parameter of my emboss effect (it’s in degrees). I think this subtle touch will really bind the scene together.

    I’m thinking that I need some way to convert an XY(Z) coordinate to an angle.. which can then drive my ‘color emboss light direction’.

    Any suggestions / pointers would be greatly appreciated.

    Thanks,
    John

    John Hammond replied 17 years, 5 months ago 2 Members · 4 Replies
  • 4 Replies
  • Darby Edelen

    December 1, 2008 at 7:18 pm

    [John Hammond] “I’m thinking that I need some way to convert an XY(Z) coordinate to an angle.. which can then drive my ‘color emboss light direction’.”

    This can be done. However, each of your blobs will need to be a separate layer to properly achieve the effect (and when I say properly achieve I mean properly fake).

    Here’s an expression that should help:


    l = thisComp.layer("Light");
    p1 = l.toComp(l.toWorld([0,0,0]));
    p2 = toComp(l.anchorPoint);
    v = normalize(p2 - p1);
    radiansToDegrees(Math.atan2(v[1],v[0]));

    Note that I haven’t tested this expression (I’m rendering) so there may be issues. You may need to add an offset of degrees to the result:

    radiansToDegrees(Math.atan2(v[1],v[0])) + 90;

    For example.

    Darby Edelen

  • John Hammond

    December 2, 2008 at 11:09 am

    Thanks Darby,

    I tried this code out at home last night and it worked pretty great!

    At first AE told me “class ‘light’ has no property or method named anchorPoint’ expression disabled”. The light didn’t have an anchor point property so I created a null layer as a child to it, and changed the expression to reference ‘null’. – At least I think this is what’s going on.

    This seems to work great!
    I’d be lying if I said I understood everything that’s going on – I’ve got a basic idea but I don’t understand all the maths.

    Is it something like.. take the difference between the world XYZ 0,0,0 and the null’s anchor value, normalize as in make into numbers between 0 and 1. I wont pretend I understand the last line, but somehow turn this into degrees.

    How come my null’s anchor point always stays at 0,0,0, yet it is driving the expression? It would seem logical that the null’s position x,y,z would drive it, as I can see those numbers change in the timeline when I scrub my animation.

    Thanks a lot this has given me a great insight, I have a long way to go in expressions yet!

    John

  • Darby Edelen

    December 2, 2008 at 7:09 pm

    I made a mistake in the expression, it should have read:

    l = thisComp.layer("Light");
    p1 = l.toComp(l.toWorld([0,0,0]));
    p2 = toComp(anchorPoint); //replaced l.anchorPoint with anchorPoint
    v = normalize(p2 - p1);
    radiansToDegrees(Math.atan2(v[1],v[0]));

    The normalize() call is actually unnecessary, I just like to do it for some strange reason 🙂

    The above code creates a vector that is the difference between the location of your layer’s anchorPoint in composition space and the location of your light in composition space. For example, in an NTSC DV composition the comp space ranges from [0,0] in the upper left to [720,480] in the lower right, the toComp() method projects a point in world space (a 3D location for a 3D layer) into this composition space.

    Once we have the vector we just need to find the angle of the vector by feeding it’s y and x components into the atan2() function and convert from radiansToDegrees().

    Darby Edelen

  • John Hammond

    December 3, 2008 at 5:42 pm

    That’s great,

    Thanks for your help. Hopefully one day I’ll be able write an expression like that out of my own head!

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