Home Technical Talk

exporting looping animations

kwyjibo
polycounter lvl 7
Offline / Send Message
kwyjibo polycounter lvl 7
What is best practice when exporting looping animations for use in a realtime 3d game engine?
for example: looping walk cycle (frame 0 and frame 100 are identical)
1.  set start frame to 0, end frame to 100, export
or
2. set start frame to 0, end frame to 99, export

Option 1: duplicate frame data but curves placed end on end will be continuous
Option 2: no duplicate frame data.

In maya (for example) while animating, it makes sense to set the playback range one frame less to avoid duplicate frame being played while previewing the animation, but when exporting animations for realtime 3d engines do you want to export a full continuous curve?

Replies

  • kwyjibo
    Options
    Offline / Send Message
    kwyjibo polycounter lvl 7
    Does anyone have an answer to this?
  • musashidan
    Options
    Offline / Send Message
    musashidan high dynamic range
    Yes, omit the last frame on export as it's a duplicate frame and will cause a skip. Also, for looping anims it's a good idea to set out curve out-of-ranges to infinite and flatten the tangents at the beginning frame from the curve editor.
  • kwyjibo
    Options
    Offline / Send Message
    kwyjibo polycounter lvl 7
    Thanks for the reply.

    totally not the answer i was hoping for as now I have a bunch of re-exporting to do. My animations are all full length, and our outsourcer's are all one frame short. Although I can't notice any skipping in engine...

    I have done this for pre-rendered sprites before because you obviously don't want duplicate sprites in a sequence. But in a 3d game engine where fps is not fixed, isn't the game basically sampling values from the curve rather than playing specific frames? eg. allowing for example slow motion playback without loss of smoothness or playback at 60fps despite animating in 30fps. So if I make an animation in which frame 0 and 100 are identical, the length of the animation curves on the timeline is 100 frames. If I export 0-100, the length of the curve is 100 but if I only export 0-99, then the length of the curve is only 99. The portion of the curves that exist between frames 99 and 100 are lost and cannot be sampled, leading me to think this would cause the playback time to be 1 frame shorter and also not smooth (for example causing the first foot contact on a walk cycle to appear heavier). This incompleteness of the curve data would seem especially serious if the frame rate was set low while animating. Maybe my understanding of how realtime engines handle animation is entirely mistaken. :|

  • Mark Dygert
    Options
    Offline / Send Message
    You have a key set at 100 so the curve is correct but you export it at a Key Per Frame 0-99 which basically bakes the curve. Really the frame is fairly inconsequential.

    What will register as a pop is if your curves don't loop properly. In maya you turn on pre and post infinity curves and they should flow seamlessing together.

    https://kakes3d.wordpress.com/2010/07/28/looping-and-copying-keyframes-in-maya/



  • kwyjibo
    Options
    Offline / Send Message
    kwyjibo polycounter lvl 7
    thanks for the reply.

    I trust with both of your experience that you are correct. But do you know what's going on the engine to make this correct? I can't wrap my head around how this could be correct when a portion of the full curve is clearly missing from the data (and i guess cannot be interpolated). Imagine an extreme case, where you've animated a six frame walk cycle (for example for prerendered sprites) but now you want to reuse that in a realtime engine running 60fps. Frames are as follows:
    0: left foot forward, right foot back
    1: left step,
    2: legs pass, 
    3: right foot forward,  left foot back
    4: right step,
    5: legs pass again,
    6: left foot forward. right foot back (same as 0)

    If you export frames 0-5, left foot forward to back motion takes 3 frames (3-0), right foot forward to back motion is incomplete and only takes 2 frames (5-3). How does this work? How does the engine interpolate the motion between frames 5-6?
  • Eric Chadwick
    Options
    Offline / Send Message
    Engines assume looping. They treat the animation as a chunk to be duplicated next to itself, as many times as needed. The pre- and post- curves are created by interpolating between one end of the imported sequence and the other end.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Just got back from vacation, but wanted to make an example for this question. I don't mean contradict musashidan and Mark, but it depends on the game engine you are working with.

    For Unity you do want to keep the duplicate frame at the end. The example below is a one second animation slowed down to 10 seconds in Unity. Notice the orange box has a hitch. @kwyjibo your instinct is correct. The last frame is only used for interpolation. It's tricky to understand because 0 - 24 is 25 frames. So it should be longer than one second. But remember frame 24 has transform key data, but no time duration. So it's really 0 - 23.999.



    In Unity's Animation panel, the blue box is 1 second and the orange box box is 0.96 seconds. So if you require precision timings, keep the frame.

    Another tip with Unity is that after you turn on Loop Time, and your animation is missing the last frame, you can also turn on Loop Pose and it will add it in for you.

    If you are using Unreal I still recommend keeping the frame. Most game engines these days allow you to crop the time segment so it will still cause no harm.
  • adeptussteve
    Options
    Offline / Send Message
    Same in UE4, you need the first and last frames to be the same in order for a clean loop. Reason is, as opposed to stuff like maya, ue4 doesnt treat animation frames stepped. It smoothly interpolates even inbetween steps (you animate at 24fps, but the game plays at 60 or 120 fps so its really vital that the engine interpolates between keyframes)
  • musashidan
    Options
    Offline / Send Message
    musashidan high dynamic range
    Same in UE4, you need the first and last frames to be the same in order for a clean loop. Reason is, as opposed to stuff like maya, ue4 doesnt treat animation frames stepped. It smoothly interpolates even inbetween steps (you animate at 24fps, but the game plays at 60 or 120 fps so its really vital that the engine interpolates between keyframes)
    Yes, that's correct but, you can do this automatically by activating 'Add looping interpolation'(this was added in 4.4) which will add a dupe frame within UE. This way you can keep your anim without the dupe in your 3D package and still have it interpolate smoothly in UE.
  • Mark Dygert
    Options
    Offline / Send Message
    Yea it really doesn't matter either way you decide to go, every game engine has a way of dealing with or without it. The important thing is to pick a path, stick to it and be as consistent as possible, there will always be one off cases but if you aren't consistent, it can turn into a nightmare pretty quick.

    To add to what Monster was saying, a frame is, the sum of it's parts. It is all of the information between the last frame and the next. It's easy to think of it as a single tick mark on a timeline but it's not. 

    It's like a ruler, a cm isn't just as wide as the thin black line under the 1, it's all of the space/time between 0 and 1.

    When you shave off a frame it's not just a tiny sliver, its a chunk of time. Not only do you lose that one pose, but you lose the info that gets it from the last pose to the missing pose.

    But yea it really doesn't matter, its an issue has been dealt with long ago, you just need to pick a direction and flip the right settings in the engine.
  • kwyjibo
    Options
    Offline / Send Message
    kwyjibo polycounter lvl 7
    For the time being i'll keep the duplicate frames. Thanks for all the replies.
Sign In or Register to comment.