Changeset 11262
- Timestamp:
- 03/19/10 21:12:19 (3 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/fbx
- Files:
-
- 5 modified
-
ReaderWriterFBX.cpp (modified) (4 diffs)
-
fbxRMesh.cpp (modified) (6 diffs)
-
fbxRMesh.h (modified) (1 diff)
-
fbxRNode.cpp (modified) (6 diffs)
-
fbxRNode.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/fbx/ReaderWriterFBX.cpp
r11252 r11262 98 98 }; 99 99 100 //Some files don't correctly mark their skeleton nodes, so this function infers 101 //them from the nodes that skin deformers linked to. 102 void 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 100 124 void resolveBindMatrices( 101 125 osg::Node& root, … … 142 166 143 167 osgAnimation::RigGeometry* pRigGeometry = it->first.second; 144 168 145 169 osgAnimation::VertexInfluenceMap* vertexInfluences = pRigGeometry->getInfluenceMap(); 146 170 … … 262 286 FbxMaterialToOsgStateSet fbxMaterialToOsgStateSet(filePath, localOptions.get()); 263 287 288 std::set<const KFbxNode*> fbxSkeletons; 289 findLinkedFbxSkeletonNodes(pNode, fbxSkeletons); 290 264 291 std::map<KFbxNode*, osg::Node*> nodeMap; 265 292 BindMatrixMap boneBindMatrices; … … 267 294 ReadResult res = readFbxNode(*pSdkManager, pNode, pAnimationManager, 268 295 bIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, 269 boneBindMatrices, skeletonMap, localOptions.get());296 boneBindMatrices, fbxSkeletons, skeletonMap, localOptions.get()); 270 297 271 298 if (res.success()) -
OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRMesh.cpp
r11154 r11262 293 293 const char* szName, 294 294 BindMatrixMap& boneBindMatrices, 295 const std::set<const KFbxNode*>& fbxSkeletons, 295 296 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 296 297 { … … 300 301 pGeode->setName(szName); 301 302 302 const KFbxLayer* pFbxLayer = 0;303 const KFbxLayer* pFbxLayer = fbxMesh->GetLayer(0); 303 304 const KFbxLayerElementNormal* pFbxNormals = 0; 304 305 const KFbxLayerElementUV* pFbxUVs = 0; … … 308 309 const KFbxVector4* pFbxVertices = fbxMesh->GetControlPoints(); 309 310 310 if (pFbxLayer = fbxMesh->GetLayer(0))311 if (pFbxLayer) 311 312 { 312 313 pFbxNormals = pFbxLayer->GetNormals(); … … 615 616 if (pSkin->GetClusterCount()) 616 617 { 617 osgAnimation::Skeleton* pSkeleton = getSkeleton(pSkin->GetCluster(0)->GetLink(), skeletonMap); 618 osgAnimation::Skeleton* pSkeleton = getSkeleton( 619 pSkin->GetCluster(0)->GetLink(), fbxSkeletons, skeletonMap); 618 620 pSkeleton->addChild(pResult); 619 621 return osgDB::ReaderWriter::ReadResult::FILE_LOADED; … … 629 631 std::vector<StateSetContent>& stateSetList, 630 632 BindMatrixMap& boneBindMatrices, 633 const std::set<const KFbxNode*>& fbxSkeletons, 631 634 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 632 635 { … … 639 642 640 643 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 12 12 std::vector<StateSetContent>&, 13 13 BindMatrixMap& boneBindMatrices, 14 const std::set<const KFbxNode*>& fbxSkeletons, 14 15 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap); 15 16 -
OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRNode.cpp
r11153 r11262 325 325 std::map<KFbxNode*, osg::Node*>& nodeMap, 326 326 BindMatrixMap& boneBindMatrices, 327 const std::set<const KFbxNode*>& fbxSkeletons, 327 328 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap, 328 329 const osgDB::Options* options) … … 349 350 bIsBone = true; 350 351 } 352 } 353 354 if (!bIsBone && fbxSkeletons.find(pNode) != fbxSkeletons.end()) 355 { 356 bIsBone = true; 351 357 } 352 358 … … 378 384 pSdkManager, pChildNode, pAnimationManager, 379 385 bChildIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, 380 boneBindMatrices, skeletonMap, options);386 boneBindMatrices, fbxSkeletons, skeletonMap, options); 381 387 if (childResult.error()) 382 388 { … … 426 432 size_t bindMatrixCount = boneBindMatrices.size(); 427 433 osgDB::ReaderWriter::ReadResult meshRes = readFbxMesh(pSdkManager, 428 pNode, pAnimationManager, stateSetList, boneBindMatrices, skeletonMap); 434 pNode, pAnimationManager, stateSetList, boneBindMatrices, 435 fbxSkeletons, skeletonMap); 429 436 if (meshRes.error()) 430 437 { … … 491 498 if (bCreateSkeleton) 492 499 { 493 osgAnimation::Skeleton* osgSkeleton = getSkeleton(pNode, skeletonMap);500 osgAnimation::Skeleton* osgSkeleton = getSkeleton(pNode, fbxSkeletons, skeletonMap); 494 501 osgSkeleton->setDefaultUpdateCallback(); 495 502 pAddChildrenTo->addChild(osgSkeleton); … … 511 518 512 519 osgAnimation::Skeleton* getSkeleton(KFbxNode* fbxNode, 520 const std::set<const KFbxNode*>& fbxSkeletons, 513 521 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap) 514 522 { 515 523 //Find the first non-skeleton ancestor of the node. 516 524 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())) 519 528 { 520 529 fbxNode = fbxNode->GetParent(); -
OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxRNode.h
r11153 r11262 11 11 typedef std::map<std::pair<KFbxNode*, osgAnimation::RigGeometry*>, osg::Matrix> BindMatrixMap; 12 12 13 osgAnimation::Skeleton* getSkeleton(KFbxNode*, std::map<KFbxNode*, osgAnimation::Skeleton*>&); 13 osgAnimation::Skeleton* getSkeleton(KFbxNode*, 14 const std::set<const KFbxNode*>& fbxSkeletons, 15 std::map<KFbxNode*, osgAnimation::Skeleton*>&); 14 16 15 17 osgDB::ReaderWriter::ReadResult readFbxNode( … … 22 24 std::map<KFbxNode*, osg::Node*>& nodeMap, 23 25 BindMatrixMap& boneBindMatrices, 26 const std::set<const KFbxNode*>& fbxSkeletons, 24 27 std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap, 25 28 const osgDB::Options* options = NULL);
