Changeset 11262

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

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

Location:
OpenSceneGraph/trunk/src/osgPlugins/fbx
Files:
5 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()) 
  • OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRMesh.cpp

    r11154 r11262  
    293293    const char* szName, 
    294294    BindMatrixMap& boneBindMatrices, 
     295    const std::set<const KFbxNode*>& fbxSkeletons, 
    295296    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 
    296297{ 
     
    300301    pGeode->setName(szName); 
    301302 
    302     const KFbxLayer* pFbxLayer = 0; 
     303    const KFbxLayer* pFbxLayer = fbxMesh->GetLayer(0); 
    303304    const KFbxLayerElementNormal* pFbxNormals = 0; 
    304305    const KFbxLayerElementUV* pFbxUVs = 0; 
     
    308309    const KFbxVector4* pFbxVertices = fbxMesh->GetControlPoints(); 
    309310 
    310     if (pFbxLayer = fbxMesh->GetLayer(0)) 
     311    if (pFbxLayer) 
    311312    { 
    312313        pFbxNormals = pFbxLayer->GetNormals(); 
     
    615616        if (pSkin->GetClusterCount()) 
    616617        { 
    617             osgAnimation::Skeleton* pSkeleton = getSkeleton(pSkin->GetCluster(0)->GetLink(), skeletonMap); 
     618            osgAnimation::Skeleton* pSkeleton = getSkeleton( 
     619                pSkin->GetCluster(0)->GetLink(), fbxSkeletons, skeletonMap); 
    618620            pSkeleton->addChild(pResult); 
    619621            return osgDB::ReaderWriter::ReadResult::FILE_LOADED; 
     
    629631    std::vector<StateSetContent>& stateSetList, 
    630632    BindMatrixMap& boneBindMatrices, 
     633    const std::set<const KFbxNode*>& fbxSkeletons, 
    631634    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 
    632635{ 
     
    639642 
    640643    return readMesh(pSdkManager, pNode, lMesh, pAnimationManager, stateSetList, 
    641         pNode->GetName(), boneBindMatrices, skeletonMap); 
    642 } 
     644        pNode->GetName(), boneBindMatrices, fbxSkeletons, skeletonMap); 
     645} 
  • OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRMesh.h

    r11153 r11262  
    1212    std::vector<StateSetContent>&, 
    1313    BindMatrixMap& boneBindMatrices, 
     14    const std::set<const KFbxNode*>& fbxSkeletons, 
    1415    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap); 
    1516 
  • OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRNode.cpp

    r11153 r11262  
    325325    std::map<KFbxNode*, osg::Node*>& nodeMap, 
    326326    BindMatrixMap& boneBindMatrices, 
     327    const std::set<const KFbxNode*>& fbxSkeletons, 
    327328    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap, 
    328329    const osgDB::Options* options) 
     
    349350            bIsBone = true; 
    350351        } 
     352    } 
     353 
     354    if (!bIsBone && fbxSkeletons.find(pNode) != fbxSkeletons.end()) 
     355    { 
     356        bIsBone = true; 
    351357    } 
    352358 
     
    378384            pSdkManager, pChildNode, pAnimationManager, 
    379385            bChildIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, 
    380             boneBindMatrices, skeletonMap, options); 
     386            boneBindMatrices, fbxSkeletons, skeletonMap, options); 
    381387        if (childResult.error()) 
    382388        { 
     
    426432            size_t bindMatrixCount = boneBindMatrices.size(); 
    427433            osgDB::ReaderWriter::ReadResult meshRes = readFbxMesh(pSdkManager, 
    428                 pNode, pAnimationManager, stateSetList, boneBindMatrices, skeletonMap); 
     434                pNode, pAnimationManager, stateSetList, boneBindMatrices, 
     435                fbxSkeletons, skeletonMap); 
    429436            if (meshRes.error()) 
    430437            { 
     
    491498    if (bCreateSkeleton) 
    492499    { 
    493         osgAnimation::Skeleton* osgSkeleton = getSkeleton(pNode, skeletonMap); 
     500        osgAnimation::Skeleton* osgSkeleton = getSkeleton(pNode, fbxSkeletons, skeletonMap); 
    494501        osgSkeleton->setDefaultUpdateCallback(); 
    495502        pAddChildrenTo->addChild(osgSkeleton); 
     
    511518 
    512519osgAnimation::Skeleton* getSkeleton(KFbxNode* fbxNode, 
     520    const std::set<const KFbxNode*>& fbxSkeletons, 
    513521    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 
    514522{ 
    515523    //Find the first non-skeleton ancestor of the node. 
    516524    while (fbxNode && 
    517         fbxNode->GetNodeAttribute() && 
    518         fbxNode->GetNodeAttribute()->GetAttributeType() == KFbxNodeAttribute::eSKELETON) 
     525        ((fbxNode->GetNodeAttribute() && 
     526        fbxNode->GetNodeAttribute()->GetAttributeType() == KFbxNodeAttribute::eSKELETON) || 
     527        fbxSkeletons.find(fbxNode) != fbxSkeletons.end())) 
    519528    { 
    520529        fbxNode = fbxNode->GetParent(); 
  • OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRNode.h

    r11153 r11262  
    1111typedef std::map<std::pair<KFbxNode*, osgAnimation::RigGeometry*>, osg::Matrix> BindMatrixMap; 
    1212 
    13 osgAnimation::Skeleton* getSkeleton(KFbxNode*, std::map<KFbxNode*, osgAnimation::Skeleton*>&); 
     13osgAnimation::Skeleton* getSkeleton(KFbxNode*, 
     14    const std::set<const KFbxNode*>& fbxSkeletons, 
     15    std::map<KFbxNode*, osgAnimation::Skeleton*>&); 
    1416 
    1517osgDB::ReaderWriter::ReadResult readFbxNode( 
     
    2224    std::map<KFbxNode*, osg::Node*>& nodeMap, 
    2325    BindMatrixMap& boneBindMatrices, 
     26    const std::set<const KFbxNode*>& fbxSkeletons, 
    2427    std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap, 
    2528    const osgDB::Options* options = NULL);