Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / Getting animation data
  RSS 2.0 ATOM  

Getting animation data
Rate this thread
 
49027
 
Permlink of this thread  
avatar
  • xytor
  • Posted: 02 November 2010 12:51 PM
  • Total Posts: 12
  • Joined: 02 November 2010 07:46 PM

Hi, I am a new FBX user and I simply want to get data relevant to animation from an fbx file.
This is just:
1)a list of weights for each vertex of the mesh from each bone
2)a transformation matrix for each bone from each keyframe.

I will then use this information to modify each vertex of the mesh based on the current frame and weight.

however, the fbx sdk is very complicated and very poorly documented. Can anybody point me in the right direction?

Edit: Here are the things I have already done:
1)Import the fbx file, and get the heirarchy of bones (simply walk through the scene nodes looking for anything named “LimbNode")
2)Get the name of the animation stack in the fbx file. However, now that I have the name, I have no idea what to do with it to extract information from it.



Replies: 1
/userdata/avatar/3yvwf23us_doug100x100.png

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(KFbxScenepScene)
{

 KFbxNode
rootNode pScene->GetRootNode();

  for (
int i 0pScene->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(lAnimStackrootNodem_pRootFrame);
  
}
}

The for each of the stack, go through the layers:

void FBXLoader::AddAnimationRecursive(KFbxAnimStackpAnimStackKFbxNodepNodeFBXFrame 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 0layerNo nbAnimLayerslayerNo++)
  
{
    KFbxAnimLayer
lAnimLayer pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), layerNo);


    
AddAnimationRecursive(lAnimLayerpNodetakeNamepAnimationSetpFrame);
  
}
}

Then for each layer, process each node:

void FBXLoader::AddAnimationRecursive(KFbxAnimLayerpAnimLayerKFbxNodepNodestd::string &takeName
                                      
FBXAnimationSet *pAnimationSet
                                      
FBXFrame pFrame)
{
 AddAnimation
(pAnimLayerpNodetakeNamepAnimationSetpFrame);

 
int childCount pNode->GetChildCount();

 
FBXFrame pChildFrame = (FBXFrame *)pFrame->pFrameFirstChild;
 for (
int i 0childCounti++)
 
{
 assert
(pChildFrame);
 
AddAnimationRecursive(pAnimLayerpNode->GetChild(i), takeNamepAnimationSetpChildFrame);
 
pChildFrame = (FBXFrame *)pChildFrame->pFrameSibling;
 
}
}

from the nodes, you get the curves:

KFbxAnimCurve *pCurveTX pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayerKFCURVENODE_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

Replied: 02 November 2010 04:12 PM  
avatar

Hi xytor,
The information you are asking for is stored and organized in KFbxCluster.
Each cluster is corresponding to one bone, and including the indices and weights of vertices that this bone affect. See the following code snippet:

KFbxSkinlSkin = (KFbxSkin *)pMesh->GetDeformer(0KFbxDeformer::eSKIN);
 
int lClusterCount lSkin->GetClusterCount();
 for (
int j=0j<lClusterCount; ++j)
 
{
 KFbxCluster
lCluster =lSkin->GetCluster(j);
 
KFbxNodelBone lCluster->GetLink();

 
int lAffectedVertexCount lCluster->GetControlPointIndicesCount();
 for (
int k 0lAffectedVertexCount; ++k
 
{            
 int lAffectedVertexIndex 
lCluster->GetControlPointIndices()[k];
 
double lWeight lCluster->GetControlPointWeights()[k];
 
}
 }

To get the transformation matrix of each bone at certain moment pTime:

KFbxAnimEvaluatorlEvaluator pMesh->GetScene()->GetEvaluator();
lEvaluator->GetNodeGlobalTransform(lBonepTime);


Jiayang Xu
Maya Data Platform
Autodesk

Replies: 0
avatar
  • xytor
  • Posted: 03 November 2010 07:25 AM

Great! What’s the point of doing what Doug suggested when what Jiayang suggested is so much easier?

Also, a small problem, the constructor for KTime accepts a value in extremely small units. What is the conversion between those and milliseconds?



Replies: 1
/userdata/avatar/3yvwf23us_doug100x100.png

You need both.  What Jiayang posted is the vertex weights (how much a bone influences a vertex).  What I posted is how the skeleton is animated.

Author: Doug Rogers

Replied: 03 November 2010 07:31 AM  
avatar
  • xytor
  • Posted: 03 November 2010 08:23 AM

Well, he posted the transformation matrices of the bones at a specific time. I was thinking of just interpolating those from set intervals (along with the bone heirarchy), and using that to animate the mesh.



Replies: 0
avatar

It seems Jiayang Xu and Doug use two different ways to get the transformation of a bone:
- Jiayang Xu uses the evaluator and get the transforms from it:

KFbxAnimEvaluatorlEvaluator pMesh->GetScene()->GetEvaluator();
lEvaluator->GetNodeGlobalTransform(lBonepTime);

- Doug directly uses animation curves, and I guess he is reconstructing the global transform matrix from there

KFbxAnimCurve *pCurveTX pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayerKFCURVENODE_T_X);

Now here is the question: i actually uses the evaluator also to get my transformations, but is there any good reason to directly use the animation curves isntead of the evaluator ? Is there any case where the evaluator may miss something while the animation curves wont ?



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

I think it depends on which kind of transform data you want to extract from FBX file.
Evaluator is kind of a utitily function, because what it does internally is also to get all animation curves on each transform attributes and compose them together to get the whole transformation matrix.

Author: Jiayang Xu

Replied: 04 November 2010 01:54 AM