• 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
mv348

Rounding keyframe transformations

8 posts in this topic

I have successfully implemented an exporter to load FBX models and export to my own custom format. The downside is there are a lot of redundant key-frame transformations. Rather, I end up with transformations that were the same before the conversion, but after the conversion (due to round-off error and various technical reasons) become almost the same.
 
So I want to create some optimization functions to reduce the number of key-frames stored in memory. (Note, it doesn't matter so much if this optimizer is fast since it is only an exporter, it isn't executed during the game)
 
The general idea is that if two transformations, are 'close enough' together, then they should be replaced with the same transformation.
 
For example, the two vectors A =(100,0,0) and B=(100,0.00002, 7.0e-18) are essentially the same and therefore we should delete B from memory and put A in place of B. (or a pointer to A in place of B, you get the idea)   
 
So my question is how does one determine if two elements (say two vectors) can be treated as identical?
 
My idea goes something like this: When comparing two vectors A and B, take the norm (or length) of A and multiply by some fixed small value (call it epsilon) then if all entries in A and B differ by less than Norm(A)*epsilon then they are considered identical. 
 
For my setup it appears that an epsilon of 10^(-5) is as small as I can go to avoid round-off error creating redundant key-frames. Though I suppose I could go lower, and just let a few extra key-frames sneak in. Shouldn't be that big of a deal.
 
What do you think of this approach?
 
And what of quaternions? In this case I have the luxury that all vectors have the same norm. So should I just check to see if all elements differ by less than some fixed epsilon?
 
Thanks,
-MV
0

Share this post


Link to post
Share on other sites

This can be a bit tricky. You can't just say "two vectors are almost the same so they should be deleted" because if you apply this same rule to all your vectors one after the other, then you will end up with no vectors!...cause they will all be close to the one that precedes it.

 

So instead I would suggest adding each vector together, from start to end, till the angle between the last direction and the resulting direction have deviated enough to warrant a new key frame. Basically, if the last vector plus the new vector point in the same direction, then merge the points.

0

Share this post


Link to post
Share on other sites

Thanks for your response, Nyssa!

 

I understand the issue you point out but what you are proposing appears to suffer from the same issue. You say 'if they have deviated enough to warrant a new keyframe' which is exactly the same as what I am doing. The only difference (if I understand your method properly) is you are measuring the direction of (A+B) relative to A, and I am measuring the components of A vs. the components of B. The difference in direction of A from (A+B) is just as likely to be too small and incorrectly eliminate a keyframe. I think its just a question of how strict you are with the comparisons. i.e. how much is 'enough' to warrant a new keyframe.

 

Moreover, your method only takes direction into account and would incorrectly merge the vectors (1,1,1) and (2,2,2) since their sum (3,3,3) is in the same direction as (1,1,1). Unless I misunderstand your approach, that is.

0

Share this post


Link to post
Share on other sites
Moreover, your method only takes direction into account and would incorrectly merge the vectors (1,1,1) and (2,2,2) since their sum (3,3,3) is in the same direction as (1,1,1).

 

That's correct. Sorry, I shouldn't have been talking about adding vectors together. Lets say you have 4 points (1,1,1), (2,2,2), (3,3,3), (4,4,4). If you place these points on a graph then the resulting line would be straight. Therefore there is no need for points (2,2,2) and (3,3,3) so you would just keep keys (1,1,1) and (4,4,4).
 

If however we have the points (1,1,1), (2,2,2), (3,-20,3), (4,4,4) you would need to keep all the points otherwise your animations won't follow the correct paths.

 

You would always store the first keyframe and the last keyframe anyway so that your animation runs from the first position to the end position correctly. Then you would make the direction from A to B the first comparison direction. Then test the direction from A to C. If the direction is about the same as the first comparison direction then throw away B. The next test would be from A to D and so on....

 

If the direction from A to C wasn't in the same direction as A to B then you would need to keep B. Because without this point your animations wouldn't follow the correct path. The direction from B to C would become your new comparison direction and you would repeat the above test for B to D and so on... 

Edited by Nyssa
0

Share this post


Link to post
Share on other sites

Yes! This is part of what I was planning after the next step. After coming up with a suitable comparison function, the next step is to use it to A. eliminate duplicate key frames, and B. eliminate key frames that are equivalent to interpolation. I had essentially the same algorithm in mind, except I would do the following:

 

For a key-frame B at time t, between key-frames A and C: interpolate A and C and evaluate it at t. Now call Compare ( B, interpolate(A,C,t)) and eliminate B if they are close enough.

0

Share this post


Link to post
Share on other sites

That's correct. Sorry, I shouldn't have been talking about adding vectors together. Lets say you have 4 points (1,1,1), (2,2,2), (3,3,3), (4,4,4). If you place these points on a graph then the resulting line would be straight. Therefore there is no need for points (2,2,2) and (3,3,3) so you would just keep keys (1,1,1) and (4,4,4).
They would only be straight if they were timed equally far apart.

Just like having (1,1,1) and then (1,1,1) and then (10,10,10). The extra (1,1,1) is there to hold the pose for a specific time frame so the first (1,1,1) doesn't start immediately interpolating towards (10,10,10). This means the second (1,1,1) is not an unneeded duplicate. Removing it breaks the animation.
0

Share this post


Link to post
Share on other sites
They would only be straight if they were timed equally far apart.

 

That's true Daaark.

 

mv, are the errors you're talking about also occurring in a frames time stamp? If you have multiple frames with the same time stamp you could simply remove any duplicates?

0

Share this post


Link to post
Share on other sites
I have had to measure the difference between two vectors in the past, and this is a formula that works well:

relative_difference(v,w) := length(v-w)/sqrt(length(v)*length(w))

If you want to compare that quantity to a threshold, you can compute the fourth power --which doesn't involve any square roots-- and compare that to the fourth power of the threshold.
0

Share this post


Link to post
Share on other sites
Don't compare the keyframes, compare the differences between the frames (and the key can be removed if the two differences are almost the same). Comparing dot products is usually better for quats.

bool canRemoveMiddleFrame(vec3 v0, vec3 v1, vec3 v2, float diff)
{
   vec3 va = v1 - v0;
   vec3 vb = v2 - v1;
   vec3 vc = va - vb;
   return (abs(vc.x) < diff) && (abs(vc.y) < diff) && (abs(vc.z) < diff);
}
bool canRemoveMiddleFrame(quat v0, quat v1, quat v2, float diff)
{
   quat va = v1 * invert(v0);
   quat vb = v2 * invert(v1);
   float difference = dot(va, vb);
   return abs( difference - 1 )  < diff;
}
Edited by RobTheBloke
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