// Find all poses in this scene. void FillPoseArray(FbxScene* pScene, FbxArray<FbxPose*>& pPoseArray) { const int lPoseCount = pScene->GetPoseCount(); for (int i=0; i < lPoseCount; ++i) { pPoseArray.Add(pScene->GetPose(i)); } }
// Add the specified node to the node array. Also, add recursively // all the parent node of the specified node to the array. void AddNodeRecursively(FbxArray<FbxNode*>& pNodeArray, FbxNode* pNode) { if (pNode) { AddNodeRecursively(pNodeArray, pNode->GetParent()); if (pNodeArray.Find(pNode) == -1) { // Node not in the list, add it pNodeArray.Add(pNode); } } }
void FBXFillMeshArrayRecursive( FbxNode* pNode, FbxArray<FbxMesh*>& pMeshArray ) { if( pNode ) { if( pNode->GetNodeAttribute() ) { if( pNode->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eMesh ) { pMeshArray.Add( pNode->GetMesh() ); } } const int lCount = pNode->GetChildCount(); for( int i = 0; i < lCount; i++ ) FBXFillMeshArrayRecursive( pNode->GetChild(i), pMeshArray ); } }
void FBXFillCameraArrayRecursive( FbxNode* pNode, FbxArray<FbxNode*>& pCameraArray) { if( pNode ) { if( pNode->GetNodeAttribute() ) { if( pNode->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eCamera ) { pCameraArray.Add( pNode ); } } const int lCount = pNode->GetChildCount(); for( int i = 0; i < lCount; i++ ) FBXFillCameraArrayRecursive( pNode->GetChild(i), pCameraArray ); } }
/** * Add a bind pose to the scene based on the FbxMesh and skinning settings of the given node */ void FFbxExporter::CreateBindPose(FbxNode* MeshRootNode) { if (!MeshRootNode) { return; } // In the bind pose, we must store all the link's global matrix at the time of the bind. // Plus, we must store all the parent(s) global matrix of a link, even if they are not // themselves deforming any model. // Create a bind pose with the link list FbxArray<FbxNode*> lClusteredFbxNodes; int i, j; if (MeshRootNode->GetNodeAttribute()) { int lSkinCount=0; int lClusterCount=0; switch (MeshRootNode->GetNodeAttribute()->GetAttributeType()) { case FbxNodeAttribute::eMesh: case FbxNodeAttribute::eNurbs: case FbxNodeAttribute::ePatch: lSkinCount = ((FbxGeometry*)MeshRootNode->GetNodeAttribute())->GetDeformerCount(FbxDeformer::eSkin); //Go through all the skins and count them //then go through each skin and get their cluster count for(i=0; i<lSkinCount; ++i) { FbxSkin *lSkin=(FbxSkin*)((FbxGeometry*)MeshRootNode->GetNodeAttribute())->GetDeformer(i, FbxDeformer::eSkin); lClusterCount+=lSkin->GetClusterCount(); } break; } //if we found some clusters we must add the node if (lClusterCount) { //Again, go through all the skins get each cluster link and add them for (i=0; i<lSkinCount; ++i) { FbxSkin *lSkin=(FbxSkin*)((FbxGeometry*)MeshRootNode->GetNodeAttribute())->GetDeformer(i, FbxDeformer::eSkin); lClusterCount=lSkin->GetClusterCount(); for (j=0; j<lClusterCount; ++j) { FbxNode* lClusterNode = lSkin->GetCluster(j)->GetLink(); AddNodeRecursively(lClusteredFbxNodes, lClusterNode); } } // Add the patch to the pose lClusteredFbxNodes.Add(MeshRootNode); } } // Now create a bind pose with the link list if (lClusteredFbxNodes.GetCount()) { // A pose must be named. Arbitrarily use the name of the patch node. FbxPose* lPose = FbxPose::Create(Scene, MeshRootNode->GetName()); // default pose type is rest pose, so we need to set the type as bind pose lPose->SetIsBindPose(true); for (i=0; i<lClusteredFbxNodes.GetCount(); i++) { FbxNode* lKFbxNode = lClusteredFbxNodes.GetAt(i); FbxMatrix lBindMatrix = lKFbxNode->EvaluateGlobalTransform(); lPose->Add(lKFbxNode, lBindMatrix); } // Add the pose to the scene Scene->AddPose(lPose); } }