Show
Ignore:
Timestamp:
03/19/10 21:12:19 (3 years ago)
Author:
mplatings
Message:

Workaround for files exported from SoftImage? that don't tag skeleton nodes correctly.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/fbx/ReaderWriterFBX.cpp

    r11252 r11262  
    9898}; 
    9999 
     100//Some files don't correctly mark their skeleton nodes, so this function infers 
     101//them from the nodes that skin deformers linked to. 
     102void findLinkedFbxSkeletonNodes(KFbxNode* pNode, std::set<const KFbxNode*>& fbxSkeletons) 
     103{ 
     104    if (const KFbxGeometry* pMesh = dynamic_cast<const KFbxGeometry*>(pNode->GetNodeAttribute())) 
     105    { 
     106        for (int i = 0; i < pMesh->GetDeformerCount(KFbxDeformer::eSKIN); ++i) 
     107        { 
     108            const KFbxSkin* pSkin = (const KFbxSkin*)pMesh->GetDeformer(i, KFbxDeformer::eSKIN); 
     109 
     110            for (int j = 0; j < pSkin->GetClusterCount(); ++j) 
     111            { 
     112                const KFbxNode* pSkeleton = pSkin->GetCluster(j)->GetLink(); 
     113                fbxSkeletons.insert(pSkeleton); 
     114            } 
     115        } 
     116    } 
     117 
     118    for (int i = 0; i < pNode->GetChildCount(); ++i) 
     119    { 
     120        findLinkedFbxSkeletonNodes(pNode->GetChild(i), fbxSkeletons); 
     121    } 
     122} 
     123 
    100124void resolveBindMatrices( 
    101125    osg::Node& root, 
     
    142166 
    143167                    osgAnimation::RigGeometry* pRigGeometry = it->first.second; 
    144                      
     168 
    145169                    osgAnimation::VertexInfluenceMap* vertexInfluences = pRigGeometry->getInfluenceMap(); 
    146170 
     
    262286            FbxMaterialToOsgStateSet fbxMaterialToOsgStateSet(filePath, localOptions.get()); 
    263287 
     288            std::set<const KFbxNode*> fbxSkeletons; 
     289            findLinkedFbxSkeletonNodes(pNode, fbxSkeletons); 
     290 
    264291            std::map<KFbxNode*, osg::Node*> nodeMap; 
    265292            BindMatrixMap boneBindMatrices; 
     
    267294            ReadResult res = readFbxNode(*pSdkManager, pNode, pAnimationManager, 
    268295                bIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, 
    269                 boneBindMatrices, skeletonMap, localOptions.get()); 
     296                boneBindMatrices, fbxSkeletons, skeletonMap, localOptions.get()); 
    270297 
    271298            if (res.success())