Apr 15, 2010

Loop with offset in nuke

Hi, I just needed to do a loop with offset, on an animation curve. That means that the cycle is continuously increasing or decreasing, depending the value of the first and last key of the loop. In maya, it is called cycle with offset. Unfortunately in nuke there is no option to do that from the menu. I solved this with a custom expression. For this I used 2 custom integer knobs on the node, called "LoopStart", "LoopEnd" (case sensitive!), marking the start and end key of the cycle. Later I will make an option built in the menu, but until that, here is the expression:

curve((((frame-LoopStart)%(LoopEnd-LoopStart))+LoopStart) ) + (floor(((frame-LoopStart)/(LoopEnd-LoopStart))) * (curve(LoopEnd)-(curve(LoopStart))))

How to apply that:
make animation you want to loop. With right click on the node/manage user knobs, make 2 integer knobs called LoopStart and LoopEnd. Set these to the frame of the first and last key of the loop. And then add this expression to the animated knob and that's it.
I made an additional option, because I needed to offset these animations in time many times, so making an extra knob called "TimeOffset", the expressions look like this:
curve((((frame-LoopStart- TimeOffset)%(LoopEnd-LoopStart))+LoopStart) ) + (floor(((frame-LoopStart-TimeOffset)/(LoopEnd-LoopStart))) * (curve(LoopEnd)-(curve(LoopStart))))

This is useful when the readnode is timeoffseted (with a separate node), so link the TimeOffset KNOB, to the timoffset NODE, so you have to adjust it only in 1 place.
With this, I did a lot of medusas floating upwards, each animating differently, but from only one readnode, many timeoffset nodes, and transformgeo nodes.
Hope this will be useful for somebody :)

9 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello!
    I try repeat but can't understand where I should write your expressions.
    Maybe you can add some printscreen?

    ReplyDelete
    Replies
    1. right click on the properties window of the node and add expression in the place u have the animation ,
      just needed this today and saved me lot of time , thanksss!

      Delete
  3. first one returns error - need to replace Startt with Start

    ReplyDelete
  4. Thanks! Was just what I needed to make a analog clock in Nuke.

    ReplyDelete
  5. Hi, which expression? Maybe check that the variables name are set correctly... But getting a nan there is strange.

    ReplyDelete
  6. [UPPING 2yr old thread]
    Gabor, thank you very much for this, really helped me nail a setup for a show.

    Now, do you know of any way to add a Min and Max value control into this ? I'd love to have a floating point slider to control the Y position of the keyframe once is created. You know what I mean !? Just in case we have a shot that requires tweaks to the animation curve, to make things easier in a big team.

    Thanks again !!!

    ReplyDelete