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 :)