Skip to main content
Amit Zach
Participant
August 13, 2024
Answered

Is there a loop expression for "full cycles" only?

  • August 13, 2024
  • 2 replies
  • 499 views

Hey, I'm making an animation bank.
As it is a bank and I will use it for various projects, I want the assets to be as editable as possible.
Each assets consists three comps - start, body (loop), and ending, so I could alter the length of the asset as I please.
the body comp is a single, cycle type, loop, which the loop expression is configured on its Time Remap value.
I know that you can limit the cycles based on a timestamp, but is there an expression that makes the loop go only in full cycles depends on the layer length?

 

for example: a layer is 5:00 sec in length, the looped keyframes are 2:00 sec in total.

In that scenario the loop will have 2.5 cycles, but I want the expression to recgonize that after 2 loops it won't be able to complete a third cycle so it will freeze on the last frame

for clarifications I use LoopOut exxpression on all of those said layers.

Thank you!

This topic has been closed for replies.
Correct answer Amit Zach

Thank you so much Dan!
 I have changed (thisComp.duration - key(1).time) to (thisLayer.outPoint - thisLayer.inPoint) so the loop will end based on the layer duration and not the whole comp which is located in.
So the full expression is:

loopDur = key(numKeys).time - key(1).time;
numLoops = Math.floor((thisLayer.outPoint - thisLayer.inPoint)/loopDur);
if (time < key(1).time + numLoops*loopDur)
  loopOut()
else
  key(numKeys).value;

Thank you so much!

2 replies

Dan Ebberts
Community Expert
Community Expert
August 13, 2024

Try this time remapping expression:

loopDur = key(numKeys).time - key(1).time;
numLoops = Math.floor((thisComp.duration - key(1).time)/loopDur);
if (time < key(1).time + numLoops*loopDur)
  loopOut()
else
  key(numKeys).value;
Amit Zach
Amit ZachAuthorCorrect answer
Participant
August 15, 2024

Thank you so much Dan!
 I have changed (thisComp.duration - key(1).time) to (thisLayer.outPoint - thisLayer.inPoint) so the loop will end based on the layer duration and not the whole comp which is located in.
So the full expression is:

loopDur = key(numKeys).time - key(1).time;
numLoops = Math.floor((thisLayer.outPoint - thisLayer.inPoint)/loopDur);
if (time < key(1).time + numLoops*loopDur)
  loopOut()
else
  key(numKeys).value;

Thank you so much!

Mylenium
Legend
August 13, 2024

Not with this method. You would have to use valueAtTime() and write your own loop code.

 

Mylenium