title: How to import fbx key frame animation into my own game engine?
body: <p>I am building a small game engine and using fbx sdk to ipmort fbx mesh and animation, which means I want to store animation in my own class. Now, there are two ways to achieve this:</p>
  
  <ol>
  <li>The first way is to store key frames only. If I store key frames only, I will have the <em>raw</em> animation data within the fbx file, and I can manipulate or adjust the animation whenever I want.</li>
  <li>The second way is to sample frames at a fixed rate. Instead of storing key frames, I obtain some of the frames that I need from the fbx file and store them. This way, I may lost the <em>raw</em> animation data, because when I sample frames, the chosen frames may not be the key frames, resulting in minor loss of details.</li>
  </ol>
  
  <p>From my perspective, the first way is the best way but most of the tutorails on the Internet are using the second way. For example, <a href="https://www.gamedev.net/resources/_/technical/graphics-programming-and-theory/how-to-work-with-fbx-sdk-r3582" rel="nofollow noreferrer">here</a>. Below is a snippet of it:</p>
  
  <pre><code>for (FbxLongLong i = start.GetFrameCount(FbxTime::eFrames24); i &lt;= end.GetFrameCount(FbxTime::eFrames24); ++i)
  {
      FbxTime currTime;
      currTime.SetFrame(i, FbxTime::eFrames24);
      *currAnim = new Keyframe();
      (*currAnim)-&gt;mFrameNum = i;
      FbxAMatrix currentTransformOffset = inNode-&gt;EvaluateGlobalTransform(currTime) * geometryTransform;
      (*currAnim)-&gt;mGlobalTransform = currentTransformOffset.Inverse() * currCluster-&gt;GetLink()-&gt;EvaluateGlobalTransform(currTime);
      currAnim = &amp;((*currAnim)-&gt;mNext);
  }
  </code></pre>
  
  <p>Notice that the function <em>EvaluateGlobalTransform(..)</em> is an fbxsdk function and it seems the only safe interface between us and an fbx animation on which we can rely. Also it seems the second way(use <em>EvaluateGlobalTransform</em> to sample at a specific rate) is the standard and commonly accepted way to do the job. And <a href="https://www.gamedev.net/topic/658450-fbx-and-skinned-animation/" rel="nofollow noreferrer">there</a> is an explation says:</p>
  
  <blockquote>
    <p>"The FBX SDK gives you a number of ways to get the data you might
    want. Unfortunately due to different DCC tools (Max/Maya/etc) you may
    not be able to get exactly the data you want. For instance, let's say
    you find the root bone and it has translation on it in the animation.
    You can access the transform in a number of ways. You can use the
    LclTransform property and ask for the FbxAMatrix at various times. Or
    you can call the evaluation functions with a time to get the matrix.
    Or you can use the evaluator's EvaluateNode function to evaluate the
    node at a time. And finally, the most complicated version is you can
    get the curve nodes from the properties and look at the curve's keys.</p>
    
    <p>Given all those options, you might think getting the curves would be
    the way to go. Unfortunately Maya, for instance, bakes the animation
    data to a set of keys which have nothing to do with the keys actually
    setup in Maya. The reason for this is that the curves Maya uses are
    not the same as those FBX supports. So, even if you get the curves
    directly, they may have hundreds of keys in them since they might have
    been baked.</p>
    
    <p>What this means is that basically unless Max has curves supported by
    FBX, it may be baking them and you won't have a way to find what the
    original two <em>poses</em> in your terms were. Generally you will iterate
    through time and sample the scene at a fixed rate. Yup, it kinda sucks
    and generally you'll want to simplify the data after sampling."</p>
  </blockquote>
  
  <p><strong>To sum up:</strong></p>
  
  <ol>
  <li><p>The first way:</p>
  
  <p>pros: easy to manipulate and adjust, accurate detail, less memory comsuption(if you generate your vertex transformation matrix on the fly)</p>
  
  <p>cons:difficult to get these key frames, not applicable to some fbx files</p></li>
  <li><p>The second way:</p>
  
  <p>pros:easy to get chosen frames, adaptable to all fbx files</p>
  
  <p>cons:difficult to change the animation, large memory comsuption, inaccurate details</p></li>
  </ol>
  
  <p><strong>So, my questions are:</strong></p>
  
  <ol>
  <li>Is the second way <em>really</em> is the common way to do this? </li>
  <li>Which way do the famous game engines, like Unreal and Unity, use?</li>
  <li>If I want to use the first way even though it may not work under some circumstances, how can I get only key frames from an fbx file(i.e. not using EvaluateGlobalTransform but working with FbxAnimStack, FbxAnimLayer, FbxAnimCurveNode, FbxAnimCurve, FbxAnimCurveKey)?</li>
  </ol>