|
Parsing the animation data should be pretty straightforward from what you have done so far.
This code gets each of the animation stacks
void FBXLoader::AddAnimation(KFbxScene* pScene) {
KFbxNode* rootNode = pScene->GetRootNode();
for (int i = 0; i < pScene->GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); i++)
{
KFbxAnimStack* lAnimStack = KFbxCast<KFbxAnimStack>(pScene->GetSrcObject(FBX_TYPE(KFbxAnimStack), i));
pScene->GetEvaluator()->SetContext(lAnimStack);
std::string name = lAnimStack->GetName();
AddAnimationRecursive(lAnimStack, rootNode, m_pRootFrame);
}
}
The for each of the stack, go through the layers:
void FBXLoader::AddAnimationRecursive(KFbxAnimStack* pAnimStack, KFbxNode* pNode, FBXFrame * pFrame) {
int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer));
std::string takeName = pAnimStack->GetName();
assert(m_takeNameToAnimationSetMap.find(takeName) != m_takeNameToAnimationSetMap.end());
FBXAnimationSet *pAnimationSet = m_takeNameToAnimationSetMap.find(takeName)->second.get();
for (int layerNo = 0; layerNo < nbAnimLayers; layerNo++)
{
KFbxAnimLayer* lAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), layerNo);
AddAnimationRecursive(lAnimLayer, pNode, takeName, pAnimationSet, pFrame);
}
}
Then for each layer, process each node:
void FBXLoader::AddAnimationRecursive(KFbxAnimLayer* pAnimLayer, KFbxNode* pNode, std::string &takeName,
FBXAnimationSet *pAnimationSet,
FBXFrame * pFrame) {
AddAnimation(pAnimLayer, pNode, takeName, pAnimationSet, pFrame);
int childCount = pNode->GetChildCount();
FBXFrame * pChildFrame = (FBXFrame *)pFrame->pFrameFirstChild;
for (int i = 0; i < childCount; i++)
{
assert(pChildFrame);
AddAnimationRecursive(pAnimLayer, pNode->GetChild(i), takeName, pAnimationSet, pChildFrame);
pChildFrame = (FBXFrame *)pChildFrame->pFrameSibling;
}
}
from the nodes, you get the curves:
KFbxAnimCurve *pCurveTX = pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_T_X);
I just updated the source code to a viewer that has all this code in it:
http://code.google.com/p/fbxviewer/
Author: Doug Rogers
|