From d5fafcecbdee3b7b44f90da7b0fc31c7b24d75fe Mon Sep 17 00:00:00 2001 From: Michael PLATINGS Date: Wed, 14 Apr 2010 16:43:50 +0000 Subject: [PATCH] Updated the plugin to be compatible with version 2011.2 of the FBX SDK --- src/osgPlugins/fbx/ReaderWriterFBX.cpp | 18 ++--- src/osgPlugins/fbx/ReaderWriterFBX.h | 1 + src/osgPlugins/fbx/WriterNodeVisitor.cpp | 27 +------ src/osgPlugins/fbx/fbxRAnimation.cpp | 90 +++++++++++++---------- src/osgPlugins/fbx/fbxRAnimation.h | 3 +- src/osgPlugins/fbx/fbxRCamera.h | 2 +- src/osgPlugins/fbx/fbxRLight.h | 2 +- src/osgPlugins/fbx/fbxRMesh.cpp | 91 ++++++++++++++---------- src/osgPlugins/fbx/fbxRMesh.h | 5 +- src/osgPlugins/fbx/fbxRNode.cpp | 10 +-- src/osgPlugins/fbx/fbxRNode.h | 5 +- 11 files changed, 134 insertions(+), 120 deletions(-) diff --git a/src/osgPlugins/fbx/ReaderWriterFBX.cpp b/src/osgPlugins/fbx/ReaderWriterFBX.cpp index a484eeee8..9c816fd9c 100644 --- a/src/osgPlugins/fbx/ReaderWriterFBX.cpp +++ b/src/osgPlugins/fbx/ReaderWriterFBX.cpp @@ -92,7 +92,6 @@ public: ~CleanUpFbx() { - KFbxIOSettings::IOSettingsRef().FreeIOSettings(); m_pSdkManager->Destroy(); } }; @@ -214,6 +213,8 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, CleanUpFbx cleanUpFbx(pSdkManager); + pSdkManager->SetIOSettings(KFbxIOSettings::Create(pSdkManager, IOSROOT)); + KFbxScene* pScene = KFbxScene::Create(pSdkManager, ""); // The FBX SDK interprets the filename as UTF-8 @@ -223,14 +224,9 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, std::string utf8filename(osgDB::convertStringFromCurrentCodePageToUTF8(filename)); #endif - int fileFormat; - if (!pSdkManager->GetIOPluginRegistry()->DetectFileFormat(utf8filename.c_str(), fileFormat)) - { - return ReadResult::FILE_NOT_HANDLED; - } KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager, ""); - if (!lImporter->Initialize(utf8filename.c_str(), fileFormat)) + if (!lImporter->Initialize(utf8filename.c_str(), -1, pSdkManager->GetIOSettings())) { return std::string(lImporter->GetLastErrorString()); } @@ -291,7 +287,7 @@ ReaderWriterFBX::readNode(const std::string& filenameInit, std::map nodeMap; BindMatrixMap boneBindMatrices; std::map skeletonMap; - ReadResult res = readFbxNode(*pSdkManager, pNode, pAnimationManager, + ReadResult res = readFbxNode(*pSdkManager, *pScene, pNode, pAnimationManager, bIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, boneBindMatrices, fbxSkeletons, skeletonMap, *localOptions); @@ -407,6 +403,8 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode( CleanUpFbx cleanUpFbx(pSdkManager); + pSdkManager->SetIOSettings(KFbxIOSettings::Create(pSdkManager, IOSROOT)); + bool useFbxRoot = false; if (options) { @@ -416,9 +414,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode( { if (opt == "Embedded") { - IOSREF.SetBoolProp(EXP_FBX_EMBEDDED, true); - if (KFbxIOSettings::IOSettingsRef().IsIOSettingsAllocated()) - KFbxIOSettings::IOSettingsRef().AllocateIOSettings(*pSdkManager); + pSdkManager->GetIOSettings()->SetBoolProp(EXP_FBX_EMBEDDED, true); } else if (opt == "UseFbxRoot") { diff --git a/src/osgPlugins/fbx/ReaderWriterFBX.h b/src/osgPlugins/fbx/ReaderWriterFBX.h index aee1d8eaf..add68c84d 100644 --- a/src/osgPlugins/fbx/ReaderWriterFBX.h +++ b/src/osgPlugins/fbx/ReaderWriterFBX.h @@ -6,6 +6,7 @@ /////////////////////////////////////////////////////////////////////////// // OSG reader plugin for the ".fbx" format. // See http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=6837478 +// This plugin requires the FBX SDK version 2011.2 class ReaderWriterFBX : public osgDB::ReaderWriter { diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.cpp b/src/osgPlugins/fbx/WriterNodeVisitor.cpp index 08c80001a..8eb99632d 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.cpp +++ b/src/osgPlugins/fbx/WriterNodeVisitor.cpp @@ -513,7 +513,7 @@ WriterNodeVisitor::setLayerTextureAndMaterial(KFbxMesh* mesh) } } mesh->GetLayer(0)->SetMaterials(lMaterialLayer); - mesh->GetLayer(0)->SetDiffuseTextures(lTextureDiffuseLayer); + mesh->GetLayer(0)->SetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES, lTextureDiffuseLayer); } void @@ -654,7 +654,7 @@ void WriterNodeVisitor::buildFaces(const osg::Geode& geo, lLayer = mesh->GetLayer(0); } setLayerTextureAndMaterial(mesh); - lLayer->GetDiffuseTextures()->GetIndexArray().SetCount(listTriangles.size()); + lLayer->GetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES)->GetIndexArray().SetCount(listTriangles.size()); lLayer->GetMaterials()->GetIndexArray().SetCount(listTriangles.size()); unsigned int i = 0; @@ -667,7 +667,7 @@ void WriterNodeVisitor::buildFaces(const osg::Geode& geo, else { mesh->BeginPolygon(i); - lLayer->GetDiffuseTextures()->GetIndexArray().SetAt(i, it->first.material); + lLayer->GetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES)->GetIndexArray().SetAt(i, it->first.material); lLayer->GetMaterials()->GetIndexArray().SetAt(i, it->first.material); } addPolygon(mesh, index_vert, it->first, it->second); @@ -721,13 +721,6 @@ void WriterNodeVisitor::apply(osg::Geode& node) KFbxNode* nodeFBX = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str()); _curFbxNode->AddChild(nodeFBX); _curFbxNode = nodeFBX; - if (false) - { - KFbxProperty lProperty = KFbxProperty::Create(_curFbxNode, "nameGeode", DTString, "label2"); - std::ostringstream oss; - oss << node.getName().c_str() << ".metaData"; - lProperty.Set(new KString(oss.str().c_str()), eSTRING); - } unsigned int count = node.getNumDrawables(); ListTriangle listTriangles; bool texcoords = false; @@ -760,13 +753,6 @@ void WriterNodeVisitor::apply(osg::Group& node) KFbxNode* nodeFBX = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str()); _curFbxNode->AddChild(nodeFBX); _curFbxNode = nodeFBX; - if (false) - { - KFbxProperty lProperty = KFbxProperty::Create(_curFbxNode, "nameGeode", DTString, "label2"); - std::ostringstream oss; - oss << node.getName().c_str() << ".metaData"; - lProperty.Set(new KString(oss.str().c_str()), eSTRING); - } traverse(node); _curFbxNode = parent; } @@ -776,13 +762,6 @@ void WriterNodeVisitor::apply(osg::MatrixTransform& node) KFbxNode* parent = _curFbxNode; _curFbxNode = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str()); parent->AddChild(_curFbxNode); - if (false) - { - KFbxProperty lProperty = KFbxProperty::Create(_curFbxNode, "nameGeode", DTString, "label2"); - std::ostringstream oss; - oss << node.getName().c_str() << ".metaData"; - lProperty.Set(new KString(oss.str().c_str()), eSTRING); - } const osg::Matrix& matrix = node.getMatrix(); osg::Vec3d pos, scl; diff --git a/src/osgPlugins/fbx/fbxRAnimation.cpp b/src/osgPlugins/fbx/fbxRAnimation.cpp index d7a46686c..17189fc52 100644 --- a/src/osgPlugins/fbx/fbxRAnimation.cpp +++ b/src/osgPlugins/fbx/fbxRAnimation.cpp @@ -22,10 +22,11 @@ osg::Quat makeQuat(const osg::Vec3& radians, ERotationOrder fbxRotOrder) return makeQuat(degrees, fbxRotOrder); } -void readKeys(KFCurve* curveX, KFCurve* curveY, KFCurve* curveZ, +void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curveZ, + const fbxDouble3& defaultValue, std::vector >& keyFrameCntr, float scalar = 1.0f) { - KFCurve* curves[3] = {curveX, curveY, curveZ}; + KFbxAnimCurve* curves[3] = {curveX, curveY, curveZ}; typedef std::set TimeSet; typedef std::map TimeFloatMap; @@ -34,19 +35,19 @@ void readKeys(KFCurve* curveX, KFCurve* curveY, KFCurve* curveZ, for (int nCurve = 0; nCurve < 3; ++nCurve) { - KFCurve* pCurve = curves[nCurve]; + KFbxAnimCurve* pCurve = curves[nCurve]; - int nKeys = pCurve->KeyGetCount(); + int nKeys = pCurve ? pCurve->KeyGetCount() : 0; if (!nKeys) { times.insert(0.0); - curveTimeMap[nCurve][0.0] = static_cast(pCurve->GetValue()) * scalar; + curveTimeMap[nCurve][0.0] = defaultValue[nCurve] * scalar; } for (int i = 0; i < nKeys; ++i) { - KFCurveKey key = pCurve->KeyGet(i); + KFbxAnimCurveKey key = pCurve->KeyGet(i); double fTime = key.GetTime().GetSecondDouble(); times.insert(fTime); curveTimeMap[nCurve][fTime] = static_cast(key.GetValue()) * scalar; @@ -69,8 +70,10 @@ void readKeys(KFCurve* curveX, KFCurve* curveY, KFCurve* curveZ, } } -osgAnimation::Channel* readFbxChannels(KFCurve* curveX, KFCurve* curveY, - KFCurve* curveZ, const char* targetName, const char* channelName) +osgAnimation::Channel* readFbxChannels(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, + KFbxAnimCurve* curveZ, + const fbxDouble3& defaultValue, + const char* targetName, const char* channelName) { if (!(curveX && curveX->KeyGetCount()) && !(curveY && curveY->KeyGetCount()) && @@ -85,27 +88,29 @@ osgAnimation::Channel* readFbxChannels(KFCurve* curveX, KFCurve* curveY, pChannel->setTargetName(targetName); pChannel->setName(channelName); - readKeys(curveX, curveY, curveZ, *pKeyFrameCntr); + readKeys(curveX, curveY, curveZ, defaultValue, *pKeyFrameCntr); return pChannel; } osgAnimation::Channel* readFbxChannels( - KFbxTypedProperty& fbxProp, const char* pTakeName, + KFbxTypedProperty& fbxProp, KFbxAnimLayer* pAnimLayer, const char* targetName, const char* channelName) { if (!fbxProp.IsValid()) return 0; return readFbxChannels( - fbxProp.GetKFCurve("X", pTakeName), - fbxProp.GetKFCurve("Y", pTakeName), - fbxProp.GetKFCurve("Z", pTakeName), + fbxProp.GetCurve(pAnimLayer, "X"), + fbxProp.GetCurve(pAnimLayer, "Y"), + fbxProp.GetCurve(pAnimLayer, "Z"), + fbxProp.Get(), targetName, channelName); } osgAnimation::Channel* readFbxChannelsQuat( - KFCurve* curveX, KFCurve* curveY, KFCurve* curveZ, const char* targetName, - ERotationOrder rotOrder) + KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curveZ, + const fbxDouble3& defaultValue, + const char* targetName, ERotationOrder rotOrder) { if (!(curveX && curveX->KeyGetCount()) && !(curveY && curveY->KeyGetCount()) && @@ -119,7 +124,7 @@ osgAnimation::Channel* readFbxChannelsQuat( pChannel->setName("quaternion"); typedef std::vector > KeyFrameCntr; KeyFrameCntr eulerFrameCntr; - readKeys(curveX, curveY, curveZ, eulerFrameCntr, static_cast(osg::PI / 180.0)); + readKeys(curveX, curveY, curveZ, defaultValue, eulerFrameCntr, static_cast(osg::PI / 180.0)); osgAnimation::QuatSphericalLinearSampler::KeyframeContainerType& quatFrameCntr = *pChannel->getOrCreateSampler()->getOrCreateKeyframeContainer(); @@ -178,14 +183,9 @@ osgAnimation::Animation* addChannels( } osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode, - const char* pTakeName, const char* targetName, + KFbxAnimLayer* pAnimLayer, const char* pTakeName, const char* targetName, osg::ref_ptr& pAnimManager) { - if (!pTakeName) - { - return 0; - } - ERotationOrder rotOrder = pNode->RotationOrder.IsValid() ? pNode->RotationOrder.Get() : eEULER_XYZ; osgAnimation::Channel* pTranslationChannel = 0; @@ -196,40 +196,56 @@ osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode, fbxDouble3 fbxBaseValue = pNode->LclRotation.Get(); pRotationChannel = readFbxChannelsQuat( - pNode->LclRotation.GetKFCurve(KFCURVENODE_R_X, pTakeName), - pNode->LclRotation.GetKFCurve(KFCURVENODE_R_Y, pTakeName), - pNode->LclRotation.GetKFCurve(KFCURVENODE_R_Z, pTakeName), + pNode->LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_X), + pNode->LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_Y), + pNode->LclRotation.GetCurve(pAnimLayer, KFCURVENODE_R_Z), + pNode->LclRotation.Get(), targetName, rotOrder); } if (pNode->LclTranslation.IsValid()) { pTranslationChannel = readFbxChannels( - pNode->LclTranslation.GetKFCurve(KFCURVENODE_T_X, pTakeName), - pNode->LclTranslation.GetKFCurve(KFCURVENODE_T_Y, pTakeName), - pNode->LclTranslation.GetKFCurve(KFCURVENODE_T_Z, pTakeName), + pNode->LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_X), + pNode->LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_Y), + pNode->LclTranslation.GetCurve(pAnimLayer, KFCURVENODE_T_Z), + pNode->LclTranslation.Get(), targetName, "translate"); } osgAnimation::Channel* pScaleChannel = readFbxChannels( - pNode->LclScaling, pTakeName, targetName, "scale"); + pNode->LclScaling, pAnimLayer, targetName, "scale"); return addChannels(pTranslationChannel, pRotationChannel, pScaleChannel, pAnimManager, pTakeName); } std::string readFbxAnimation(KFbxNode* pNode, + KFbxScene& fbxScene, osg::ref_ptr& pAnimManager, const char* targetName) { std::string result; - for (int i = 1; i < pNode->GetTakeNodeCount(); ++i) - { - const char* pTakeName = pNode->GetTakeNodeName(i); - if (osgAnimation::Animation* pAnimation = readFbxAnimation( - pNode, pTakeName, targetName, pAnimManager)) - { - result = targetName; - } + for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i) + { + KFbxAnimStack* pAnimStack = KFbxCast(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i)); + + int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer)); + + const char* pTakeName = pAnimStack->GetName(); + + if (!pTakeName || !*pTakeName) + continue; + + for (int j = 0; j < nbAnimLayers; j++) + { + KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j); + + if (osgAnimation::Animation* pAnimation = readFbxAnimation( + pNode, pAnimLayer, pTakeName, targetName, pAnimManager)) + { + result = targetName; + } + } } return result; } diff --git a/src/osgPlugins/fbx/fbxRAnimation.h b/src/osgPlugins/fbx/fbxRAnimation.h index 60dae7f4a..f44c85bed 100644 --- a/src/osgPlugins/fbx/fbxRAnimation.h +++ b/src/osgPlugins/fbx/fbxRAnimation.h @@ -4,7 +4,8 @@ #include std::string readFbxAnimation( - FBXFILESDK_NAMESPACE::KFbxNode*, + KFbxNode*, + KFbxScene& fbxScene, osg::ref_ptr&, const char* targetName); diff --git a/src/osgPlugins/fbx/fbxRCamera.h b/src/osgPlugins/fbx/fbxRCamera.h index 09c65946f..ea9a1a6b6 100644 --- a/src/osgPlugins/fbx/fbxRCamera.h +++ b/src/osgPlugins/fbx/fbxRCamera.h @@ -5,6 +5,6 @@ #include osgDB::ReaderWriter::ReadResult readFbxCamera( - FBXFILESDK_NAMESPACE::KFbxNode* pNode); + KFbxNode* pNode); #endif diff --git a/src/osgPlugins/fbx/fbxRLight.h b/src/osgPlugins/fbx/fbxRLight.h index 96872cb96..ff74d0134 100644 --- a/src/osgPlugins/fbx/fbxRLight.h +++ b/src/osgPlugins/fbx/fbxRLight.h @@ -5,6 +5,6 @@ #include osgDB::ReaderWriter::ReadResult readFbxLight( - FBXFILESDK_NAMESPACE::KFbxNode* pNode, int& nLightCount); + KFbxNode* pNode, int& nLightCount); #endif diff --git a/src/osgPlugins/fbx/fbxRMesh.cpp b/src/osgPlugins/fbx/fbxRMesh.cpp index f2ada28f2..d57a6a1a5 100644 --- a/src/osgPlugins/fbx/fbxRMesh.cpp +++ b/src/osgPlugins/fbx/fbxRMesh.cpp @@ -239,42 +239,57 @@ void addChannel( pAnimation->addChannel(pChannel); } -void readAnimation(KFbxNode* pNode, const std::string& targetName, +void readAnimation(KFbxNode* pNode, KFbxScene& fbxScene, const std::string& targetName, osg::ref_ptr& pAnimationManager, KFbxMesh* pMesh, int nShape) { - for (int i = 1; i < pNode->GetTakeNodeCount(); ++i) + for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i) + { + KFbxAnimStack* pAnimStack = KFbxCast(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i)); + + int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer)); + + const char* pTakeName = pAnimStack->GetName(); + + if (!pTakeName || !*pTakeName) + continue; + + for (int j = 0; j < nbAnimLayers; j++) + { + KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j); + + KFbxAnimCurve* pCurve = pMesh->GetShapeChannel(nShape, pAnimLayer); + if (!pCurve) + { + continue; + } + + int nKeys = pCurve->KeyGetCount(); + if (!nKeys) + { + continue; + } + + osgAnimation::FloatLinearChannel* pChannel = new osgAnimation::FloatLinearChannel; + std::vector >& keyFrameCntr = *pChannel->getOrCreateSampler()->getOrCreateKeyframeContainer(); + + for (int k = 0; k < nKeys; ++k) + { + KFbxAnimCurveKey key = pCurve->KeyGet(k); + double fTime = key.GetTime().GetSecondDouble(); + float fValue = static_cast(key.GetValue() * 0.01); + keyFrameCntr.push_back(osgAnimation::FloatKeyframe(fTime,fValue)); + } + + pChannel->setTargetName(targetName); + std::stringstream ss; + ss << nShape; + pChannel->setName(ss.str()); + addChannel(pChannel, pAnimationManager, pTakeName); + } + } + { - const char* pTakeName = pNode->GetTakeNodeName(i); - - KFCurve* pCurve = pMesh->GetShapeChannel(nShape, false, pTakeName); - if (!pCurve) - { - continue; - } - - int nKeys = pCurve->KeyGetCount(); - if (!nKeys) - { - continue; - } - - osgAnimation::FloatLinearChannel* pChannel = new osgAnimation::FloatLinearChannel; - std::vector >& keyFrameCntr = *pChannel->getOrCreateSampler()->getOrCreateKeyframeContainer(); - - for (int k = 0; k < nKeys; ++k) - { - KFCurveKey key = pCurve->KeyGet(k); - double fTime = key.GetTime().GetSecondDouble(); - float fValue = static_cast(key.GetValue() * 0.01); - keyFrameCntr.push_back(osgAnimation::FloatKeyframe(fTime,fValue)); - } - - pChannel->setTargetName(targetName); - std::stringstream ss; - ss << nShape; - pChannel->setName(ss.str()); - addChannel(pChannel, pAnimationManager, pTakeName); } } @@ -334,6 +349,7 @@ void addColorArrayElement(osg::Array& a, const KFbxColor& c) } osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, + KFbxScene& fbxScene, KFbxNode* pNode, KFbxMesh* fbxMesh, osg::ref_ptr& pAnimationManager, std::vector& stateSetList, @@ -455,7 +471,7 @@ osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, } } - for (int i = 0; i < pGeode->getNumDrawables(); ++i) + for (unsigned i = 0; i < pGeode->getNumDrawables(); ++i) { osg::Geometry* pGeometry = pGeode->getDrawable(i)->asGeometry(); if (pGeode->getNumDrawables() > 1) @@ -480,7 +496,7 @@ osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, osg::ref_ptr > GeometryRigGeometryMap; GeometryRigGeometryMap old2newGeometryMap; - for (int i = 0; i < pGeode->getNumDrawables(); ++i) + for (unsigned i = 0; i < pGeode->getNumDrawables(); ++i) { osg::Geometry* pGeometry = pGeode->getDrawable(i)->asGeometry(); @@ -545,7 +561,7 @@ osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, } else if (geomType == GEOMETRY_MORPH) { - for (int i = 0; i < pGeode->getNumDrawables(); ++i) + for (unsigned i = 0; i < pGeode->getNumDrawables(); ++i) { osg::Geometry* pGeometry = pGeode->getDrawable(i)->asGeometry(); @@ -579,7 +595,7 @@ osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, pMorphTarget->setName(fbxMesh->GetShapeName(j)); morph.addMorphTarget(pMorphTarget, 0.0f); - readAnimation(pNode, morph.getName(), pAnimationManager, fbxMesh, j); + readAnimation(pNode, fbxScene, morph.getName(), pAnimationManager, fbxMesh, j); } } @@ -686,6 +702,7 @@ osgDB::ReaderWriter::ReadResult readMesh(KFbxSdkManager& pSdkManager, } osgDB::ReaderWriter::ReadResult readFbxMesh(KFbxSdkManager& pSdkManager, + KFbxScene& fbxScene, KFbxNode* pNode, osg::ref_ptr& pAnimationManager, std::vector& stateSetList, @@ -701,6 +718,6 @@ osgDB::ReaderWriter::ReadResult readFbxMesh(KFbxSdkManager& pSdkManager, return osgDB::ReaderWriter::ReadResult::ERROR_IN_READING_FILE; } - return readMesh(pSdkManager, pNode, lMesh, pAnimationManager, stateSetList, + return readMesh(pSdkManager, fbxScene, pNode, lMesh, pAnimationManager, stateSetList, pNode->GetName(), boneBindMatrices, fbxSkeletons, skeletonMap, options); } diff --git a/src/osgPlugins/fbx/fbxRMesh.h b/src/osgPlugins/fbx/fbxRMesh.h index 18d589cae..3601f4651 100644 --- a/src/osgPlugins/fbx/fbxRMesh.h +++ b/src/osgPlugins/fbx/fbxRMesh.h @@ -6,8 +6,9 @@ #include #include "fbxRNode.h" osgDB::ReaderWriter::ReadResult readFbxMesh( - FBXFILESDK_NAMESPACE::KFbxSdkManager& pSdkManager, - FBXFILESDK_NAMESPACE::KFbxNode* pNode, + KFbxSdkManager& pSdkManager, + KFbxScene& fbxScene, + KFbxNode* pNode, osg::ref_ptr& pAnimationManager, std::vector&, BindMatrixMap& boneBindMatrices, diff --git a/src/osgPlugins/fbx/fbxRNode.cpp b/src/osgPlugins/fbx/fbxRNode.cpp index 79bd77b6d..20b3d4e0c 100644 --- a/src/osgPlugins/fbx/fbxRNode.cpp +++ b/src/osgPlugins/fbx/fbxRNode.cpp @@ -318,7 +318,9 @@ osg::Group* createGroupNode(KFbxSdkManager& pSdkManager, KFbxNode* pNode, } osgDB::ReaderWriter::ReadResult readFbxNode( - KFbxSdkManager& pSdkManager, KFbxNode* pNode, + KFbxSdkManager& pSdkManager, + KFbxScene& fbxScene, + KFbxNode* pNode, osg::ref_ptr& pAnimationManager, bool& bIsBone, int& nLightCount, FbxMaterialToOsgStateSet& fbxMaterialToOsgStateSet, @@ -381,7 +383,7 @@ osgDB::ReaderWriter::ReadResult readFbxNode( bool bChildIsBone = false; osgDB::ReaderWriter::ReadResult childResult = readFbxNode( - pSdkManager, pChildNode, pAnimationManager, + pSdkManager, fbxScene, pChildNode, pAnimationManager, bChildIsBone, nLightCount, fbxMaterialToOsgStateSet, nodeMap, boneBindMatrices, fbxSkeletons, skeletonMap, options); if (childResult.error()) @@ -402,7 +404,7 @@ osgDB::ReaderWriter::ReadResult readFbxNode( } } - std::string animName = readFbxAnimation(pNode, pAnimationManager, pNode->GetName()); + std::string animName = readFbxAnimation(pNode, fbxScene, pAnimationManager, pNode->GetName()); osg::Matrix localMatrix; makeLocalMatrix(pNode, localMatrix); @@ -430,7 +432,7 @@ osgDB::ReaderWriter::ReadResult readFbxNode( case KFbxNodeAttribute::eMESH: { size_t bindMatrixCount = boneBindMatrices.size(); - osgDB::ReaderWriter::ReadResult meshRes = readFbxMesh(pSdkManager, + osgDB::ReaderWriter::ReadResult meshRes = readFbxMesh(pSdkManager, fbxScene, pNode, pAnimationManager, stateSetList, boneBindMatrices, fbxSkeletons, skeletonMap, options); if (meshRes.error()) diff --git a/src/osgPlugins/fbx/fbxRNode.h b/src/osgPlugins/fbx/fbxRNode.h index dd9ddb580..6eb3e1538 100644 --- a/src/osgPlugins/fbx/fbxRNode.h +++ b/src/osgPlugins/fbx/fbxRNode.h @@ -15,8 +15,9 @@ osgAnimation::Skeleton* getSkeleton(KFbxNode*, std::map&); osgDB::ReaderWriter::ReadResult readFbxNode( - FBXFILESDK_NAMESPACE::KFbxSdkManager& pSdkManager, - FBXFILESDK_NAMESPACE::KFbxNode* pNode, + KFbxSdkManager& pSdkManager, + KFbxScene& fbxScene, + KFbxNode* pNode, osg::ref_ptr& pAnimationManager, bool& bIsBone, int& nLightCount,