Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Smooth expression

  • Smooth expression

  • Eric Sanderson

    February 3, 2011 at 8:27 pm

    I applied some tracking info to a null and through a smooth() on the position to, smooth it out obviously. But later in my workflow ive needed to value+position pickwhip that null to another null upstream, i typed .smooth after my pickwhipped position line and got no error but also got no visible result. How can i still use my smooth function value while adding/pickwhipping to another layers position?

  • Dan Ebberts

    February 4, 2011 at 5:41 am

    smooth() is like wiggle in that its result includes the value of the property. To isolate the effect of smooth() you need to subtract value. Then you can add it to any other position -generating expression. So the isolation part looks like this:

    s = smooth(.2,5)-value;

    Then just add s to the position of the null.

    Dan

  • Jacek Skro

    December 5, 2015 at 3:22 pm

    There is possible to apply smooth to evaluated value instead of original?

    My case:
    After 3D camera tracking I have many 0<>360 jumps in Camera’s Orientation property.
    So I apply expression to orientation:

    ([transform.orientation[0]-10, transform.orientation[1]-10, transform.orientation[2]-10]);

    10 is a maximal degrees variation iny may Camera’a orientation, so now its values are between 350-360 degrees without jumps.
    I want to apply additional smooth to orientation.
    But after adding:

    smooth(width = .2, samples = 5, t = time);

    …Camera’s orientation again jumps 0<>360, and my earlier expression is ignored.

    There is a way to solve this?

  • Dan Ebberts

    December 5, 2015 at 7:47 pm

    smooth() only works on pre-expression property values. I think it’s just a simple box filter though, so you should be able to do what you’re trying to do by building your own smoother, like this:

    (valueAtTime(time – .1) – [10,10,10] +
    valueAtTime(time – .05) – [10,10,10] +
    value – [10,10,10] +
    valueAtTime(time + .05) – [10,10,10] +
    valueAtTime(time + .1) – [10,10,10])/5;

    Dan

  • Jacek Skro

    December 5, 2015 at 9:12 pm

    It is better solution than my current [dirty] workaround by Converting Expression to Keyframes and apply smooth() afterwards.

    Thanks!

  • Marian-Mina Mihai

    September 11, 2019 at 10:27 pm

    Hi. I know I’m 5 years late to the party, but maybe someone still has this issue. My solution was to:
    1. offset the value so that it stays in the 0-360 range
    2. convert expression to keyframes
    3. apply the smooth() expression
    4. convert expression to keyframes
    5. offset the value back so you get the original range, but with the smooth expression applied ()
    Hope it helps!

  • Kalleheikki Kannisto

    August 10, 2020 at 6:13 pm

    Encountered the same problem when trying to smooth 3D camera tracking orientation values, I used this expression to fix the issue. I’m guessing it breaks at the 180 degree rotation point, but at least the usual 0 to 360 flip is fixed by this.

    n = 24;// number of frames to smooth in each direction
    fps = 24;
    xRot = 0;
    yRot = 0;
    zRot = 0;
    for (i=-n; i < n+1; i++) { xRotT = (transform.orientation.valueAtTime(time+i/fps)[0]+180)%360; yRotT = (transform.orientation.valueAtTime(time+i/fps)[1]+180)%360; zRotT = (transform.orientation.valueAtTime(time+i/fps)[2]+180)%360; xRot += xRotT; yRot += yRotT; zRot += zRotT; } xRot = xRot/(n*2+1)-180; yRot = yRot/(n*2+1)-180; zRot = zRot/(n*2+1)-180; [xRot, yRot, zRot]

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Filip Vandueren

    August 11, 2020 at 12:36 pm

    Hi KK,

    interesting problem to fix for both 360-0° and 180°.

    I came up with this solution:

    n = 15;// number of frames to smooth in each direction
    fps = 25;
    rotations = [0,0,0];
    revolutions=[0,0,0]; // additional revolutions

    for (var i=-n; i < n+1; i++) {
    sample1 = valueAtTime(time+i/fps);
    sample2 = valueAtTime(time+(i-1)/fps); // previous value
    vel = sample1-sample2;

    for (var j=0; j < 3; j++) {
    // if the change since last frame is close to 360°, we're 1 revolution off
    revolutions[j]+= Math.round(vel[j]/360)*360;
    }
    // adjust for revolutions and add to sum
    rotations += (sample1-revolutions);
    }
    rotations/=(n*2+1);
    xRot =(rotations[0])%360;
    yRot =(rotations[1])%360;
    zRot =(rotations[2])%360;
    [xRot, yRot, zRot]

    It’s not great with Motion Blur though, you’d have to convert to keyframes first if that’s an issue, or use CC Force Motion Blur on an adjustment layer.

Viewing 1 - 8 of 8 posts

Log in to reply.

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