• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Oogst

Keyframe removal algorithm

6 posts in this topic

I am looking for a fast algorithm to remove keyframes based on a maximum error. So if a keyframe is near enough to what can be interpolated from the other keyframes, then that keyframe should be removed. I am using linear interpolation only, so this should be relatively simple to do.

 

For example, let's say I have these keyframes, with their times and values:

0s 10

0.4s 11.1

0.8s 12

2.0s 20

2.9s 38

3.0s 40

 

In this example I can remove the key at 2.9s, because interpolating the keys at 2.0s and 3.0s would give the exact same value. Depending on the error threshold I might also be able to delete the key at 0.4s, since removing that one gives an error of only 0.1.

 

I need an algorithm that can handle several floating point data types, like floats, 2D positions and colours (rgba, so 4D).

 

Of course I managed to come up with simple brute force algorithms for this, but I would like to use something more efficient. I add a lot of keys in real-time over time and ideally the algorithm would do a small amount of work every time a keyframe is added, instead of doing a lot of work at the end, since otherwise I would get hickups whenever I need to finish a block of keyframes.

 

I tried searching for algorithms for this, but I mostly found info about things like MPEG keyframes and tools in Blender.

 

Thanks in advance! :)

1

Share this post


Link to post
Share on other sites

Are you inserting one keyframe at a time or multiple frames at once?  It doesn't sound like it would be too expensive to do the brute force as each key is inserted, since you'd only be looking at the adjacent keyframes.

 

Other than that, nothing is really coming to mind.  The best I can offer is maybe try rejiggering the data and see if anything leaps out at you.  Perhaps convert each frame to a delta value?

0

Share this post


Link to post
Share on other sites


I need an algorithm that can handle several floating point data types, like floats, 2D positions and colours (rgba, so 4D).

It would be easier to help you if you would provide something more detailed than "interpolating keyframes" as the goal. Keyframes for what? Animation? Video? Are you interpolating colors?

0

Share this post


Link to post
Share on other sites

 


I need an algorithm that can handle several floating point data types, like floats, 2D positions and colours (rgba, so 4D).

It would be easier to help you if you would provide something more detailed than "interpolating keyframes" as the goal. Keyframes for what? Animation? Video? Are you interpolating colors?

 

I am interpolating various different things with the same algorithm. Colours, positions, angles, but also things like cooldowns and health. However, this doesn't matter for the algorithm: they are just numbers being linearly interpolated, and the numbers can be 1D, 2D, 3D or 4D.

 

 

Are you inserting one keyframe at a time or multiple frames at once?  It doesn't sound like it would be too expensive to do the brute force as each key is inserted, since you'd only be looking at the adjacent keyframes.

I am indeed inserting keyframes one at a time.

 

I tried the approach of checking adjacent keyframes on insert already and it turns out that it is incorrect: with certain fluent curve-like changes removing the previous key if the new one allows it removes the curve entirely and can give (theoretically) infinite error. So I need to store lists of potentially removable keyframes and check that every frame, but that last can grow as long as the entire list of keyframes in certain cases, meaning that inserting is suddenly O(n).

Edited by Oogst
0

Share this post


Link to post
Share on other sites

Not knowing what your "brute force" method comprises, it's likely the most efficient. If you have several data types and you're looking for a function or routine that will handle different data type inputs to do a LERP (for instance), that function, either explicitly or "under the hood," will have to make appropriate conversions itself to use a common (4D) LERP call, or simply branch to one of 4 LERPS (1D, 2D, 3D, 4D). The GPU can do that sort of thing perhaps faster than the CPU, but for just a few calcs at a time, accessing the GPU is expensive.

 

You could also write your method directly in assembly for whatever FPU you have.

0

Share this post


Link to post
Share on other sites

 

I am indeed inserting keyframes one at a time.

 

I tried the approach of checking adjacent keyframes on insert already and it turns out that it is incorrect: with certain fluent curve-like changes removing the previous key if the new one allows it removes the curve entirely and can give (theoretically) infinite error. So I need to store lists of potentially removable keyframes and check that every frame, but that last can grow as long as the entire list of keyframes in certain cases, meaning that inserting is suddenly O(n).

 

 

Can you give an example, I'm afraid I don't understand the causes of the error.  Is it that if you over simplify, you lose the curve and get a line?

0

Share this post


Link to post
Share on other sites

It is actually pretty simple.

Try to remove the given keyframe, then sample the keytrack at the given time value of the key again.

Compare that to the version where the keyframe did not get removed.

 

Now you have an error value that gets introduced. You simply compare that error value in a way corresponding to the type of data it represents.

For a Vector3 you can just compare the distance, for a Quaternion you can do some special check etc.

 

If the error is below the threshold remove the keyframe permanently, otherwise keep it.

Iterate over all kefyrames this way. The first and last keyframe will most likely be special cases that you always need to keep.

 

Hope that helps smile.png

 

Edit: Ah I didn't see you need to add lot of keyframes in realtime. You could adapt this algorithm to that though, by checking if you can remove some of the last added keyframes. Not the last one, but say the one before, maybe batching it if you add multiple at the same time. Or already do this check while adding keyframes, it shouldn't be too hard, the principle idea stays the same :)

Edited by Buckshag
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0