Animating a Node
 
 
 
Note

This section is loosely based on the CubeCreator tutorial program, located in <yourFBXSDKpath>\examples\UI Examples\CubeCreator. For more information on creating a camera, see Cameras.

Unless you are using blended animation, setting up the data structures required for animation is very straightforward. You’ll need one animation stack; one animation layer; and one animation curve node for every animated property.

Let’s say that you need to animate a camera. More specifically, you want to animate the local translation property of a camera’s KFbxNode object:

KFbxScene* myScene;        // An initialized and valid scene object
KFbxNode* myCameraNode;    // An initialized and valid node object
 
// Set the default local translation values (X, Y, Z) for the camera
myCameraNode.LclTranslation.Set(fbxDouble3(1.1, 2.2, 3.3))

Although this example deals with the translation of a camera, you can animate any FBX property of any FBX object, providing that the property is animatable (see eFbxPropertyFlags::eANIMATABLE).

You always need at least one stack and one layer

Begin by creating one animation stack:

// Define an animation stack
KFbxAnimStack* myAnimStack = KFbxAnimStack::Create(pScene, "My stack");

You need to define only one animation layer:

// Create the base layer (this is mandatory)
KFbxAnimLayer* myAnimBaseLayer = KFbxAnimLayer::Create(pScene, "Layer0");

Add this layer to the animation stack:

myAnimStack->AddMember(myAnimBaseLayer);

Curve nodes connect animation data to the animated property

CubeCreator creates one animation curve node for each axis along which the camera moves. You need one animation curve node to connect the translation data to the camera node’s LclTranslation property:

// Get the camera’s curve node for local translation.
// The second parameter to GetCurveNode() is "true" to ensure
// that if the curve node does not exist, it will automatically be created.
KFbxAnimCurveNode* myAnimCurveNode = pCamera->LclTranslation.GetCurveNode(pAnimLayer, true);

Notes on animation curve nodes:

myAnimCurveNode is all set up to connect animation curves to the local translation property of myCameraNode. All that is missing are the animation curves.

Curve nodes are containers for animation curves

Here, we create the animation curve for translation on the X-axis:

KFbxAnimCurve* myTranXCurve = NULL;   // Curve for local translation on X-axis
KTime myTime;                         // For the start and stop keys.
int myKeyIndex = 0;                // Index for the keys that define the curve
 
// Get the animation curve for local translation of the camera.
// true: If the curve does not exist yet, create it.
myTranXCurve = myCameraNode->LclTranslation.GetCurve<KFbxAnimCurve>
                                  (myAnimLayer, KFCURVENODE_T_X, true);

Here, we define the curve’s starting and ending keyframes:

// First the start keyframe
myAnimCurve->KeyModifyBegin();
myTime.SetSecondDouble(0.0);             // Starting time
myKeyIndex = myAnimCurve->KeyAdd(lTime); // Add the start key; returns 0
 
myAnimCurve->KeySet(lKeyIndex,           // Set the zero’th key
                    lTime,               // Starting time
                    0.0,                 // Starting X value
KFbxAnimCurveDef::eINTERPOLATION_LINEAR);// Straight line between 2 points
 
// Then the stop keyframe
lTime.SetSecondDouble(20.0);
lKeyIndex = lCurve->KeyAdd(lTime);
lCurve->KeySet(lKeyIndex, lTime, 500.0, KFbxAnimCurveDef::eINTERPOLATION_LINEAR);
lCurve->KeyModifyEnd();

So if you were to run this animation, the camera would take 20 seconds to move 500 units along the X-axis.

Sample programs that demonstrate animation:

See Also