FBX SDK Programmer's Guide > Animation >

# Extracting the Animation Data from a FBX File

You can extract and query the animation data from a scene (FBX file) without loading the entire FBX file.

A scene (FbxScene) can contain one or more animation stacks (FbxAnimStack). The animation stack is the highest-level container for the animation data and contains one or more animation layers (FbxAnimLayer). An animation layer contains one or more animation curve nodes (FbxAnimCurveNode). An animation curve node is the connection point between the animation curves (FbxAnimCurve) and the FBX properties (FbxProperty) of a FBX object (FbxObject).

Perform the following steps to extract the animation data from a scene:

1. Extract the animation stacks using a pointer to an instance of the FbxScene (pScene).

       int numStacks = pScene->GetSrcObjectCount(FBX_TYPE(FbxAnimStack)); i++)

2. Retrieve the nth animation stack.

       FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(pScene->GetSrcObject(FBX_TYPE(FbxAnimStack), n)

3. Retrieve the number of animation layers in an animation stack.

       int numAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(FbxAnimLayer));

4. Retrieve the nth animation layer from the animation stack.

       FbxAnimLayer* lAnimLayer = lAnimStack->GetMember(FBX_TYPE(FbxAnimLayer), n);

   After retrieving an animation layer, you can access the animation curves for the properties of nodes and node attribute.

5. Retrieve the animation curves.
   - Given a node (lNode) and an animation layer (lAnimLayer), you can retrieve the animation curves for node properties such as the local translation as shown in the following example.

         FbxAnimCurve* lAnimCurve = lNode->LclTranslation.GetCurve(lAnimLayer, FBXSDK_CURVENODE_COMPONENT_X);

   - Given a node (lNode) and a layer (lAnimLayer), you can retrieve the animation curves for node attribute properties such as the red color component as shown in the following example.

         FbxNodeAttribute* lNodeAttribute = lNode->GetNodeAttribute();
         FbxAnimCurve* lAnimCurve = lNodeAttribute->Color.GetCurve<FbxAnimCurve>(pAnimLayer, FBXSDK_CURVENODE_COLOR_RED);

You can also use the animation curve nodes to access the animation data for the properties. The following steps show how to access the animation curves for a specific property on the first (0th) channel.

1. Check whether the property is valid.

       if (lProperty.IsValid) ...

2. Retrieve the curve node using the animation layer.

       FbxAnimCurveNode* lCurveNode = lProperty.GetCurveNode(pAnimLayer);

   If the property is not animated the curve node is NULL.

       if (lCurveNode != NULL) ...

3. Step through the curves in the curve node.

       for( int c = 0; c < lCurveNode->GetCurveCount(0U); c++ ) {
                                       FbxAnimCurve* lAnimCurve = lCurveNode->GetCurve(0U, c);
                                       if (lAnimCurve != NULL) {
                                                       // ...
                                       }
                       }

See the FbxAnimCurveNode class reference for more information on animation curve nodes and channels.

For a more detailed example of importing animation data using the FBX SDK, see the example ImportScene/DisplayAnimation.cxx.

#### See Also

- Importing a Scene
- Animation classes and their interrelationships
- Migrating to the new data structures for animation