From Laurens Voerman, "Autodesk released a new version of their FBX Software Development Kit (web page http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&id=10775847).
The API has changed quite a bit, so lots of changes had to be made in the osg readerwriter. The preious version of the FBX SDK (2013.3) already deprecated a lot of the names and functions. The code I submit now still compiles against 2013.3 (possibly needs a #define FBX_NEW_API). Not sure if that's useful, but it might ease the transition."
This commit is contained in:
parent
375e7c2d57
commit
82ecbe98da
@ -16,8 +16,10 @@ ELSEIF(MSVC80)
|
||||
SET(FBX_LIBDIR "vs2005")
|
||||
ELSEIF(MSVC90)
|
||||
SET(FBX_LIBDIR "vs2008")
|
||||
ELSEIF(MSVC10 OR MSVC_VERSION>1600)
|
||||
ELSEIF(MSVC10)
|
||||
SET(FBX_LIBDIR "vs2010")
|
||||
ELSEIF(MSVC11 OR MSVC_VERSION>1700)
|
||||
SET(FBX_LIBDIR "vs2012")
|
||||
ENDIF()
|
||||
|
||||
IF(APPLE)
|
||||
@ -31,20 +33,20 @@ ELSE()
|
||||
ENDIF()
|
||||
|
||||
IF(APPLE)
|
||||
SET(FBX_LIBNAME "fbxsdk-2012.1-static")
|
||||
SET(FBX_LIBNAME "libfbxsdk")
|
||||
ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
SET(FBX_LIBNAME "fbxsdk-2012.1-static")
|
||||
SET(FBX_LIBNAME "libfbxsdk")
|
||||
ELSE()
|
||||
SET(FBX_LIBNAME "fbxsdk-2012.1-md")
|
||||
SET(FBX_LIBNAME "libfbxsdk-md")
|
||||
ENDIF()
|
||||
|
||||
SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
|
||||
|
||||
SET( FBX_SEARCH_PATHS
|
||||
$ENV{FBX_DIR}
|
||||
$ENV{ProgramW6432}/Autodesk/FBX/FbxSdk/2012.1
|
||||
$ENV{PROGRAMFILES}/Autodesk/FBX/FbxSdk/2012.1
|
||||
/Applications/Autodesk/FBXSDK20121
|
||||
"$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2014.1"
|
||||
"$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2014.1"
|
||||
/Applications/Autodesk/FBXSDK20141
|
||||
)
|
||||
|
||||
# search for headers & debug/release libraries
|
||||
@ -53,13 +55,58 @@ FIND_PATH(FBX_INCLUDE_DIR "fbxsdk.h"
|
||||
PATH_SUFFIXES "include")
|
||||
FIND_LIBRARY( FBX_LIBRARY ${FBX_LIBNAME}
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}")
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}/release" "lib/${FBX_LIBDIR}")
|
||||
|
||||
#Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.
|
||||
|
||||
#no debug d suffix, search in debug folder only
|
||||
FIND_LIBRARY( FBX_LIBRARY_DEBUG ${FBX_LIBNAME}
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}/debug")
|
||||
FIND_LIBRARY( FBX_LIBRARY_DEBUG ${FBX_LIBNAME_DEBUG}
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}")
|
||||
|
||||
|
||||
IF(FBX_LIBRARY AND FBX_LIBRARY_DEBUG AND FBX_INCLUDE_DIR)
|
||||
SET(FBX_FOUND "YES")
|
||||
ELSE()
|
||||
SET(FBX_FOUND "NO")
|
||||
ENDIF()
|
||||
|
||||
IF(NOT FBX_FOUND)
|
||||
#try to use 2013.3 version
|
||||
IF(APPLE)
|
||||
SET(FBX_LIBNAME "fbxsdk-2013.3-static")
|
||||
ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
SET(FBX_LIBNAME "fbxsdk-2013.3-static")
|
||||
ELSE()
|
||||
SET(FBX_LIBNAME "fbxsdk-2013.3-md")
|
||||
ENDIF()
|
||||
|
||||
SET(FBX_LIBNAME_DEBUG ${FBX_LIBNAME}d)
|
||||
|
||||
SET( FBX_SEARCH_PATHS
|
||||
$ENV{FBX_DIR}
|
||||
$ENV{ProgramW6432}/Autodesk/FBX/FBX SDK/2013.3
|
||||
$ENV{PROGRAMFILES}/Autodesk/FBX/FBX SDK/2013.3
|
||||
/Applications/Autodesk/FBXSDK20141
|
||||
)
|
||||
|
||||
# search for headers & debug/release libraries
|
||||
FIND_PATH(FBX_INCLUDE_DIR "fbxsdk.h"
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "include")
|
||||
FIND_LIBRARY( FBX_LIBRARY ${FBX_LIBNAME}
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}")
|
||||
|
||||
FIND_LIBRARY( FBX_LIBRARY_DEBUG ${FBX_LIBNAME_DEBUG}
|
||||
PATHS ${FBX_SEARCH_PATHS}
|
||||
PATH_SUFFIXES "lib/${FBX_LIBDIR}")
|
||||
IF(FBX_LIBRARY AND FBX_LIBRARY_DEBUG AND FBX_INCLUDE_DIR)
|
||||
SET(FBX_FOUND "YES")
|
||||
ELSE()
|
||||
SET(FBX_FOUND "NO")
|
||||
ENDIF()
|
||||
|
||||
ENDIF()
|
||||
|
@ -89,9 +89,9 @@ bool isBasicRootNode(const osg::Node& node)
|
||||
|
||||
class CleanUpFbx
|
||||
{
|
||||
KFbxSdkManager* m_pSdkManager;
|
||||
FbxManager* m_pSdkManager;
|
||||
public:
|
||||
explicit CleanUpFbx(KFbxSdkManager* pSdkManager) : m_pSdkManager(pSdkManager)
|
||||
explicit CleanUpFbx(FbxManager* pSdkManager) : m_pSdkManager(pSdkManager)
|
||||
{}
|
||||
|
||||
~CleanUpFbx()
|
||||
@ -102,17 +102,17 @@ public:
|
||||
|
||||
//Some files don't correctly mark their skeleton nodes, so this function infers
|
||||
//them from the nodes that skin deformers linked to.
|
||||
void findLinkedFbxSkeletonNodes(KFbxNode* pNode, std::set<const KFbxNode*>& fbxSkeletons)
|
||||
void findLinkedFbxSkeletonNodes(FbxNode* pNode, std::set<const FbxNode*>& fbxSkeletons)
|
||||
{
|
||||
if (const KFbxGeometry* pMesh = KFbxCast<KFbxGeometry>(pNode->GetNodeAttribute()))
|
||||
if (const FbxGeometry* pMesh = FbxCast<FbxGeometry>(pNode->GetNodeAttribute()))
|
||||
{
|
||||
for (int i = 0; i < pMesh->GetDeformerCount(KFbxDeformer::eSKIN); ++i)
|
||||
for (int i = 0; i < pMesh->GetDeformerCount(FbxDeformer::eSkin); ++i)
|
||||
{
|
||||
const KFbxSkin* pSkin = (const KFbxSkin*)pMesh->GetDeformer(i, KFbxDeformer::eSKIN);
|
||||
const FbxSkin* pSkin = (const FbxSkin*)pMesh->GetDeformer(i, FbxDeformer::eSkin);
|
||||
|
||||
for (int j = 0; j < pSkin->GetClusterCount(); ++j)
|
||||
{
|
||||
const KFbxNode* pSkeleton = pSkin->GetCluster(j)->GetLink();
|
||||
const FbxNode* pSkeleton = pSkin->GetCluster(j)->GetLink();
|
||||
fbxSkeletons.insert(pSkeleton);
|
||||
}
|
||||
}
|
||||
@ -127,10 +127,10 @@ void findLinkedFbxSkeletonNodes(KFbxNode* pNode, std::set<const KFbxNode*>& fbxS
|
||||
void resolveBindMatrices(
|
||||
osg::Node& root,
|
||||
const BindMatrixMap& boneBindMatrices,
|
||||
const std::map<KFbxNode*, osg::Node*>& nodeMap)
|
||||
const std::map<FbxNode*, osg::Node*>& nodeMap)
|
||||
{
|
||||
std::set<std::string> nodeNames;
|
||||
for (std::map<KFbxNode*, osg::Node*>::const_iterator it = nodeMap.begin(); it != nodeMap.end(); ++it)
|
||||
for (std::map<FbxNode*, osg::Node*>::const_iterator it = nodeMap.begin(); it != nodeMap.end(); ++it)
|
||||
{
|
||||
nodeNames.insert(it->second->getName());
|
||||
}
|
||||
@ -138,8 +138,8 @@ void resolveBindMatrices(
|
||||
for (BindMatrixMap::const_iterator it = boneBindMatrices.begin();
|
||||
it != boneBindMatrices.end();)
|
||||
{
|
||||
KFbxNode* const fbxBone = it->first.first;
|
||||
std::map<KFbxNode*, osg::Node*>::const_iterator nodeIt = nodeMap.find(fbxBone);
|
||||
FbxNode* const fbxBone = it->first.first;
|
||||
std::map<FbxNode*, osg::Node*>::const_iterator nodeIt = nodeMap.find(fbxBone);
|
||||
if (nodeIt != nodeMap.end())
|
||||
{
|
||||
const osg::Matrix bindMatrix = it->second;
|
||||
@ -208,7 +208,7 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
std::string filename(osgDB::findDataFile(filenameInit, options));
|
||||
if (filename.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
KFbxSdkManager* pSdkManager = KFbxSdkManager::Create();
|
||||
FbxManager* pSdkManager = FbxManager::Create();
|
||||
|
||||
if (!pSdkManager)
|
||||
{
|
||||
@ -217,9 +217,9 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
|
||||
CleanUpFbx cleanUpFbx(pSdkManager);
|
||||
|
||||
pSdkManager->SetIOSettings(KFbxIOSettings::Create(pSdkManager, IOSROOT));
|
||||
pSdkManager->SetIOSettings(FbxIOSettings::Create(pSdkManager, IOSROOT));
|
||||
|
||||
KFbxScene* pScene = KFbxScene::Create(pSdkManager, "");
|
||||
FbxScene* pScene = FbxScene::Create(pSdkManager, "");
|
||||
|
||||
// The FBX SDK interprets the filename as UTF-8
|
||||
#ifdef OSG_USE_UTF8_FILENAME
|
||||
@ -228,11 +228,15 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
std::string utf8filename(osgDB::convertStringFromCurrentCodePageToUTF8(filename));
|
||||
#endif
|
||||
|
||||
KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager, "");
|
||||
FbxImporter* lImporter = FbxImporter::Create(pSdkManager, "");
|
||||
|
||||
if (!lImporter->Initialize(utf8filename.c_str(), -1, pSdkManager->GetIOSettings()))
|
||||
{
|
||||
#if FBXSDK_VERSION_MAJOR < 2014
|
||||
return std::string(lImporter->GetLastErrorString());
|
||||
#else
|
||||
return std::string(lImporter->GetStatus().GetErrorString());
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!lImporter->IsFBX())
|
||||
@ -240,19 +244,23 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
return ReadResult::ERROR_IN_READING_FILE;
|
||||
}
|
||||
|
||||
for (int i = 0; KFbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i); i++)
|
||||
for (int i = 0; FbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i); i++)
|
||||
{
|
||||
lTakeInfo->mSelect = true;
|
||||
}
|
||||
|
||||
if (!lImporter->Import(pScene))
|
||||
{
|
||||
#if FBXSDK_VERSION_MAJOR < 2014
|
||||
return std::string(lImporter->GetLastErrorString());
|
||||
#else
|
||||
return std::string(lImporter->GetStatus().GetErrorString());
|
||||
#endif
|
||||
}
|
||||
|
||||
//KFbxAxisSystem::OpenGL.ConvertScene(pScene); // Doesn't work as expected. Still need to transform vertices.
|
||||
//FbxAxisSystem::OpenGL.ConvertScene(pScene); // Doesn't work as expected. Still need to transform vertices.
|
||||
|
||||
if (KFbxNode* pNode = pScene->GetRootNode())
|
||||
if (FbxNode* pNode = pScene->GetRootNode())
|
||||
{
|
||||
bool useFbxRoot = false;
|
||||
bool lightmapTextures = false;
|
||||
@ -290,11 +298,11 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
std::string filePath = osgDB::getFilePath(filename);
|
||||
FbxMaterialToOsgStateSet fbxMaterialToOsgStateSet(filePath, localOptions.get(), lightmapTextures);
|
||||
|
||||
std::set<const KFbxNode*> fbxSkeletons;
|
||||
std::set<const FbxNode*> fbxSkeletons;
|
||||
findLinkedFbxSkeletonNodes(pNode, fbxSkeletons);
|
||||
|
||||
OsgFbxReader::AuthoringTool authoringTool = OsgFbxReader::UNKNOWN;
|
||||
if (KFbxDocumentInfo* pDocInfo = pScene->GetDocumentInfo())
|
||||
if (FbxDocumentInfo* pDocInfo = pScene->GetDocumentInfo())
|
||||
{
|
||||
struct ToolName
|
||||
{
|
||||
@ -307,7 +315,7 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
{"3ds Max", OsgFbxReader::AUTODESK_3DSTUDIO_MAX}
|
||||
};
|
||||
|
||||
fbxString appName = pDocInfo->LastSaved_ApplicationName.Get();
|
||||
FbxString appName = pDocInfo->LastSaved_ApplicationName.Get();
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(authoringTools) / sizeof(authoringTools[0]); ++i)
|
||||
{
|
||||
@ -344,9 +352,6 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
resolveBindMatrices(*res.getNode(), reader.boneBindMatrices, reader.nodeMap);
|
||||
|
||||
osg::Node* osgNode = res.getNode();
|
||||
for (int light = 0; light < nLightCount; ++light)
|
||||
osgNode->getOrCreateStateSet()->setMode(GL_LIGHT0 + light, osg::StateAttribute::ON);
|
||||
|
||||
osgNode->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON);
|
||||
osgNode->getOrCreateStateSet()->setMode(GL_NORMALIZE,osg::StateAttribute::ON);
|
||||
|
||||
@ -364,26 +369,26 @@ ReaderWriterFBX::readNode(const std::string& filenameInit,
|
||||
osgNode->setUpdateCallback(reader.pAnimationManager.get());
|
||||
}
|
||||
|
||||
KFbxAxisSystem fbxAxis = pScene->GetGlobalSettings().GetAxisSystem();
|
||||
FbxAxisSystem fbxAxis = pScene->GetGlobalSettings().GetAxisSystem();
|
||||
|
||||
if (fbxAxis != KFbxAxisSystem::OpenGL)
|
||||
if (fbxAxis != FbxAxisSystem::OpenGL)
|
||||
{
|
||||
int upSign;
|
||||
KFbxAxisSystem::eUpVector eUp = fbxAxis.GetUpVector(upSign);
|
||||
bool bLeftHanded = fbxAxis.GetCoorSystem() == KFbxAxisSystem::LeftHanded;
|
||||
FbxAxisSystem::EUpVector eUp = fbxAxis.GetUpVector(upSign);
|
||||
bool bLeftHanded = fbxAxis.GetCoorSystem() == FbxAxisSystem::eLeftHanded;
|
||||
float fSign = upSign < 0 ? -1.0f : 1.0f;
|
||||
float zScale = bLeftHanded ? -1.0f : 1.0f;
|
||||
|
||||
osg::Matrix mat;
|
||||
switch (eUp)
|
||||
{
|
||||
case KFbxAxisSystem::XAxis:
|
||||
case FbxAxisSystem::eXAxis:
|
||||
mat.set(0,fSign,0,0,-fSign,0,0,0,0,0,zScale,0,0,0,0,1);
|
||||
break;
|
||||
case KFbxAxisSystem::YAxis:
|
||||
case FbxAxisSystem::eYAxis:
|
||||
mat.set(1,0,0,0,0,fSign,0,0,0,0,fSign*zScale,0,0,0,0,1);
|
||||
break;
|
||||
case KFbxAxisSystem::ZAxis:
|
||||
case FbxAxisSystem::eZAxis:
|
||||
mat.set(1,0,0,0,0,0,-fSign*zScale,0,0,fSign,0,0,0,0,0,1);
|
||||
break;
|
||||
}
|
||||
@ -443,7 +448,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
|
||||
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
|
||||
localOptions->getDatabasePathList().push_front(osgDB::getFilePath(filename));
|
||||
|
||||
KFbxSdkManager* pSdkManager = KFbxSdkManager::Create();
|
||||
FbxManager* pSdkManager = FbxManager::Create();
|
||||
|
||||
if (!pSdkManager)
|
||||
{
|
||||
@ -452,7 +457,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
|
||||
|
||||
CleanUpFbx cleanUpFbx(pSdkManager);
|
||||
|
||||
pSdkManager->SetIOSettings(KFbxIOSettings::Create(pSdkManager, IOSROOT));
|
||||
pSdkManager->SetIOSettings(FbxIOSettings::Create(pSdkManager, IOSROOT));
|
||||
|
||||
bool useFbxRoot = false;
|
||||
if (options)
|
||||
@ -472,7 +477,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
|
||||
}
|
||||
}
|
||||
|
||||
KFbxScene* pScene = KFbxScene::Create(pSdkManager, "");
|
||||
FbxScene* pScene = FbxScene::Create(pSdkManager, "");
|
||||
pluginfbx::WriterNodeVisitor writerNodeVisitor(pScene, pSdkManager, filename,
|
||||
options, osgDB::getFilePath(node.getName().empty() ? filename : node.getName()));
|
||||
if (useFbxRoot && isBasicRootNode(node))
|
||||
@ -489,21 +494,21 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
|
||||
const_cast<osg::Node&>(node).accept(writerNodeVisitor);
|
||||
}
|
||||
|
||||
KFbxDocumentInfo* pDocInfo = pScene->GetDocumentInfo();
|
||||
FbxDocumentInfo* pDocInfo = pScene->GetDocumentInfo();
|
||||
bool needNewDocInfo = pDocInfo != NULL;
|
||||
if (needNewDocInfo)
|
||||
{
|
||||
pDocInfo = KFbxDocumentInfo::Create(pSdkManager, "");
|
||||
pDocInfo = FbxDocumentInfo::Create(pSdkManager, "");
|
||||
}
|
||||
pDocInfo->LastSaved_ApplicationName.Set(fbxString("OpenSceneGraph"));
|
||||
pDocInfo->LastSaved_ApplicationVersion.Set(fbxString(osgGetVersion()));
|
||||
pDocInfo->LastSaved_ApplicationName.Set(FbxString("OpenSceneGraph"));
|
||||
pDocInfo->LastSaved_ApplicationVersion.Set(FbxString(osgGetVersion()));
|
||||
if (needNewDocInfo)
|
||||
{
|
||||
pScene->SetDocumentInfo(pDocInfo);
|
||||
}
|
||||
|
||||
KFbxExporter* lExporter = KFbxExporter::Create(pSdkManager, "");
|
||||
pScene->GetGlobalSettings().SetAxisSystem(KFbxAxisSystem::eOpenGL);
|
||||
FbxExporter* lExporter = FbxExporter::Create(pSdkManager, "");
|
||||
pScene->GetGlobalSettings().SetAxisSystem(FbxAxisSystem::eOpenGL);
|
||||
|
||||
// Ensure the directory exists or else the FBX SDK will fail
|
||||
if (!osgDB::makeDirectoryForFile(filename)) {
|
||||
@ -519,11 +524,19 @@ osgDB::ReaderWriter::WriteResult ReaderWriterFBX::writeNode(
|
||||
|
||||
if (!lExporter->Initialize(utf8filename.c_str()))
|
||||
{
|
||||
#if FBXSDK_VERSION_MAJOR < 2014
|
||||
return std::string(lExporter->GetLastErrorString());
|
||||
#else
|
||||
return std::string(lExporter->GetStatus().GetErrorString());
|
||||
#endif
|
||||
}
|
||||
if (!lExporter->Export(pScene))
|
||||
{
|
||||
#if FBXSDK_VERSION_MAJOR < 2014
|
||||
return std::string(lExporter->GetLastErrorString());
|
||||
#else
|
||||
return std::string(lExporter->GetStatus().GetErrorString());
|
||||
#endif
|
||||
}
|
||||
|
||||
return WriteResult::FILE_SAVED;
|
||||
|
@ -2,14 +2,15 @@
|
||||
#define READERWRITERFBX_H
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <fbxfilesdk/fbxfilesdk_version.h>
|
||||
#include <fbxsdk/fbxsdk_def.h>
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// OSG reader plugin for the ".fbx" format.
|
||||
// See http://www.autodesk.com/fbx
|
||||
// This plugin requires the FBX SDK version 2012.1 or 2012.2
|
||||
// This plugin requires the FBX SDK version 2013.3 or 2014.1
|
||||
|
||||
#if FBXSDK_VERSION_MAJOR != 2012 || FBXSDK_VERSION_MINOR < 1
|
||||
#if FBXSDK_VERSION_MAJOR < 2013 || (FBXSDK_VERSION_MAJOR == 2013 && FBXSDK_VERSION_MINOR < 3)
|
||||
#error Wrong FBX SDK version
|
||||
#endif
|
||||
|
||||
|
@ -220,7 +220,7 @@ private:
|
||||
int _material;
|
||||
unsigned int _curNormalIndex;
|
||||
osg::Geometry::AttributeBinding _normalBinding;
|
||||
KFbxMesh* _mesh;
|
||||
FbxMesh* _mesh;
|
||||
};
|
||||
|
||||
void PrimitiveIndexWriter::drawArrays(GLenum mode,GLint first,GLsizei count)
|
||||
@ -284,7 +284,7 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor,
|
||||
const osg::StateSet* stateset,
|
||||
const osg::Material* mat,
|
||||
const osg::Texture* tex,
|
||||
KFbxSdkManager* pSdkManager,
|
||||
FbxManager* pSdkManager,
|
||||
const osgDB::ReaderWriter::Options * options,
|
||||
int index) :
|
||||
_fbxMaterial(NULL),
|
||||
@ -326,28 +326,28 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor,
|
||||
}
|
||||
}
|
||||
|
||||
_fbxMaterial = KFbxSurfacePhong::Create(pSdkManager, mat->getName().c_str());
|
||||
_fbxMaterial = FbxSurfacePhong::Create(pSdkManager, mat->getName().c_str());
|
||||
if (_fbxMaterial)
|
||||
{
|
||||
_fbxMaterial->DiffuseFactor.Set(1, true);
|
||||
_fbxMaterial->Diffuse.Set(fbxDouble3(
|
||||
_fbxMaterial->DiffuseFactor.Set(1);
|
||||
_fbxMaterial->Diffuse.Set(FbxDouble3(
|
||||
diffuse.x(),
|
||||
diffuse.y(),
|
||||
diffuse.z()));
|
||||
|
||||
_fbxMaterial->TransparencyFactor.Set(transparency);
|
||||
|
||||
_fbxMaterial->Ambient.Set(fbxDouble3(
|
||||
_fbxMaterial->Ambient.Set(FbxDouble3(
|
||||
ambient.x(),
|
||||
ambient.y(),
|
||||
ambient.z()));
|
||||
|
||||
_fbxMaterial->Emissive.Set(fbxDouble3(
|
||||
_fbxMaterial->Emissive.Set(FbxDouble3(
|
||||
emission.x(),
|
||||
emission.y(),
|
||||
emission.z()));
|
||||
|
||||
_fbxMaterial->Specular.Set(fbxDouble3(
|
||||
_fbxMaterial->Specular.Set(FbxDouble3(
|
||||
specular.x(),
|
||||
specular.y(),
|
||||
specular.z()));
|
||||
@ -362,15 +362,15 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor,
|
||||
std::string relativePath;
|
||||
externalWriter.write(*_osgImage, options, NULL, &relativePath);
|
||||
|
||||
_fbxTexture = KFbxFileTexture::Create(pSdkManager, relativePath.c_str());
|
||||
_fbxTexture = FbxFileTexture::Create(pSdkManager, relativePath.c_str());
|
||||
_fbxTexture->SetFileName(relativePath.c_str());
|
||||
// Create a FBX material if needed
|
||||
if (!_fbxMaterial)
|
||||
{
|
||||
_fbxMaterial = KFbxSurfacePhong::Create(pSdkManager, relativePath.c_str());
|
||||
_fbxMaterial = FbxSurfacePhong::Create(pSdkManager, relativePath.c_str());
|
||||
}
|
||||
// Connect texture to material's diffuse
|
||||
// Note there should be no reason KFbxSurfacePhong::Create() would return NULL, but as previous code made this secirity test, here we keep the same way.
|
||||
// Note there should be no reason FbxSurfacePhong::Create() would return NULL, but as previous code made this secirity test, here we keep the same way.
|
||||
if (_fbxMaterial)
|
||||
{
|
||||
_fbxMaterial->Diffuse.ConnectSrcObject(_fbxTexture);
|
||||
@ -416,7 +416,7 @@ unsigned int addPolygon(MapIndices & index_vert, unsigned int vertIndex, unsigne
|
||||
return itIndex->second;
|
||||
}
|
||||
|
||||
void addPolygon(KFbxMesh * mesh, MapIndices & index_vert, const Triangle & tri, unsigned int drawableNum)
|
||||
void addPolygon(FbxMesh * mesh, MapIndices & index_vert, const Triangle & tri, unsigned int drawableNum)
|
||||
{
|
||||
mesh->AddPolygon(addPolygon(index_vert, tri.t1, tri.normalIndex1, drawableNum));
|
||||
mesh->AddPolygon(addPolygon(index_vert, tri.t2, tri.normalIndex2, drawableNum));
|
||||
@ -425,15 +425,15 @@ void addPolygon(KFbxMesh * mesh, MapIndices & index_vert, const Triangle & tri,
|
||||
|
||||
|
||||
void
|
||||
WriterNodeVisitor::setLayerTextureAndMaterial(KFbxMesh* mesh)
|
||||
WriterNodeVisitor::setLayerTextureAndMaterial(FbxMesh* mesh)
|
||||
{
|
||||
KFbxLayerElementTexture* lTextureDiffuseLayer = KFbxLayerElementTexture::Create(mesh, "Diffuse");
|
||||
lTextureDiffuseLayer->SetMappingMode(KFbxLayerElement::eBY_POLYGON);
|
||||
lTextureDiffuseLayer->SetReferenceMode(KFbxLayerElement::eINDEX_TO_DIRECT);
|
||||
FbxLayerElementTexture* lTextureDiffuseLayer = FbxLayerElementTexture::Create(mesh, "Diffuse");
|
||||
lTextureDiffuseLayer->SetMappingMode(FbxLayerElement::eByPolygon);
|
||||
lTextureDiffuseLayer->SetReferenceMode(FbxLayerElement::eIndexToDirect);
|
||||
|
||||
KFbxLayerElementMaterial* lMaterialLayer = KFbxLayerElementMaterial::Create(mesh, "materialLayer");
|
||||
lMaterialLayer->SetMappingMode(KFbxLayerElement::eBY_POLYGON);
|
||||
lMaterialLayer->SetReferenceMode(KFbxLayerElement::eINDEX_TO_DIRECT);
|
||||
FbxLayerElementMaterial* lMaterialLayer = FbxLayerElementMaterial::Create(mesh, "materialLayer");
|
||||
lMaterialLayer->SetMappingMode(FbxLayerElement::eByPolygon);
|
||||
lMaterialLayer->SetReferenceMode(FbxLayerElement::eIndexToDirect);
|
||||
|
||||
lTextureDiffuseLayer->GetDirectArray().SetCount(_lastMaterialIndex);
|
||||
lMaterialLayer->mDirectArray->SetCount(_lastMaterialIndex);
|
||||
@ -442,37 +442,37 @@ WriterNodeVisitor::setLayerTextureAndMaterial(KFbxMesh* mesh)
|
||||
{
|
||||
if (it->second.getIndex() != -1)
|
||||
{
|
||||
KFbxSurfaceMaterial* lMaterial = it->second.getFbxMaterial();
|
||||
KFbxFileTexture* lTexture = it->second.getFbxTexture();
|
||||
FbxSurfaceMaterial* lMaterial = it->second.getFbxMaterial();
|
||||
FbxFileTexture* lTexture = it->second.getFbxTexture();
|
||||
lTextureDiffuseLayer->GetDirectArray().SetAt(it->second.getIndex(), lTexture);
|
||||
lMaterialLayer->mDirectArray->SetAt(it->second.getIndex(), lMaterial);
|
||||
}
|
||||
}
|
||||
mesh->GetLayer(0)->SetMaterials(lMaterialLayer);
|
||||
mesh->GetLayer(0)->SetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES, lTextureDiffuseLayer);
|
||||
mesh->GetLayer(0)->SetTextures(FbxLayerElement::eTextureDiffuse, lTextureDiffuseLayer);
|
||||
}
|
||||
|
||||
void
|
||||
WriterNodeVisitor::setControlPointAndNormalsAndUV(const osg::Geode& geo,
|
||||
MapIndices& index_vert,
|
||||
bool texcoords,
|
||||
KFbxMesh* mesh)
|
||||
FbxMesh* mesh)
|
||||
{
|
||||
mesh->InitControlPoints(index_vert.size());
|
||||
KFbxLayerElementNormal* lLayerElementNormal= KFbxLayerElementNormal::Create(mesh, "");
|
||||
FbxLayerElementNormal* lLayerElementNormal= FbxLayerElementNormal::Create(mesh, "");
|
||||
// For now, FBX writer only supports normals bound per vertices
|
||||
lLayerElementNormal->SetMappingMode(KFbxLayerElement::eBY_CONTROL_POINT);
|
||||
lLayerElementNormal->SetReferenceMode(KFbxLayerElement::eDIRECT);
|
||||
lLayerElementNormal->SetMappingMode(FbxLayerElement::eByControlPoint);
|
||||
lLayerElementNormal->SetReferenceMode(FbxLayerElement::eDirect);
|
||||
lLayerElementNormal->GetDirectArray().SetCount(index_vert.size());
|
||||
mesh->GetLayer(0)->SetNormals(lLayerElementNormal);
|
||||
KFbxLayerElementUV* lUVDiffuseLayer = KFbxLayerElementUV::Create(mesh, "DiffuseUV");
|
||||
FbxLayerElementUV* lUVDiffuseLayer = FbxLayerElementUV::Create(mesh, "DiffuseUV");
|
||||
|
||||
if (texcoords)
|
||||
{
|
||||
lUVDiffuseLayer->SetMappingMode(KFbxLayerElement::eBY_CONTROL_POINT);
|
||||
lUVDiffuseLayer->SetReferenceMode(KFbxLayerElement::eDIRECT);
|
||||
lUVDiffuseLayer->SetMappingMode(FbxLayerElement::eByControlPoint);
|
||||
lUVDiffuseLayer->SetReferenceMode(FbxLayerElement::eDirect);
|
||||
lUVDiffuseLayer->GetDirectArray().SetCount(index_vert.size());
|
||||
mesh->GetLayer(0)->SetUVs(lUVDiffuseLayer, KFbxLayerElement::eDIFFUSE_TEXTURES);
|
||||
mesh->GetLayer(0)->SetUVs(lUVDiffuseLayer, FbxLayerElement::eTextureDiffuse);
|
||||
}
|
||||
|
||||
for (MapIndices::iterator it = index_vert.begin(); it != index_vert.end(); ++it)
|
||||
@ -488,7 +488,7 @@ WriterNodeVisitor::setControlPointAndNormalsAndUV(const osg::Geode& geo,
|
||||
//OSG_NOTIFY()
|
||||
continue;
|
||||
}
|
||||
KFbxVector4 vertex;
|
||||
FbxVector4 vertex;
|
||||
if (basevecs->getType() == osg::Array::Vec3ArrayType)
|
||||
{
|
||||
const osg::Vec3 & vec = (*static_cast<const osg::Vec3Array *>(basevecs))[vertexIndex];
|
||||
@ -513,7 +513,7 @@ WriterNodeVisitor::setControlPointAndNormalsAndUV(const osg::Geode& geo,
|
||||
|
||||
if (basenormals && basenormals->getNumElements()>0)
|
||||
{
|
||||
KFbxVector4 normal;
|
||||
FbxVector4 normal;
|
||||
if (basenormals->getType() == osg::Array::Vec3ArrayType)
|
||||
{
|
||||
const osg::Vec3 & vec = (*static_cast<const osg::Vec3Array *>(basenormals))[normalIndex];
|
||||
@ -547,7 +547,7 @@ WriterNodeVisitor::setControlPointAndNormalsAndUV(const osg::Geode& geo,
|
||||
const osg::Array * basetexcoords = pGeometry->getTexCoordArray(0);
|
||||
if (basetexcoords && basetexcoords->getNumElements()>0)
|
||||
{
|
||||
KFbxVector2 texcoord;
|
||||
FbxVector2 texcoord;
|
||||
if (basetexcoords->getType() == osg::Array::Vec2ArrayType)
|
||||
{
|
||||
const osg::Vec2 & vec = (*static_cast<const osg::Vec2Array *>(basetexcoords))[vertexIndex];
|
||||
@ -577,17 +577,17 @@ void WriterNodeVisitor::buildFaces(const osg::Geode& geo,
|
||||
bool texcoords)
|
||||
{
|
||||
MapIndices index_vert;
|
||||
KFbxMesh* mesh = KFbxMesh::Create(_pSdkManager, geo.getName().c_str());
|
||||
FbxMesh* mesh = FbxMesh::Create(_pSdkManager, geo.getName().c_str());
|
||||
_curFbxNode->AddNodeAttribute(mesh);
|
||||
_curFbxNode->SetShadingMode(KFbxNode::eTEXTURE_SHADING);
|
||||
KFbxLayer* lLayer = mesh->GetLayer(0);
|
||||
_curFbxNode->SetShadingMode(FbxNode::eTextureShading);
|
||||
FbxLayer* lLayer = mesh->GetLayer(0);
|
||||
if (lLayer == NULL)
|
||||
{
|
||||
mesh->CreateLayer();
|
||||
lLayer = mesh->GetLayer(0);
|
||||
}
|
||||
setLayerTextureAndMaterial(mesh);
|
||||
lLayer->GetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES)->GetIndexArray().SetCount(listTriangles.size());
|
||||
lLayer->GetTextures(FbxLayerElement::eTextureDiffuse)->GetIndexArray().SetCount(listTriangles.size());
|
||||
lLayer->GetMaterials()->GetIndexArray().SetCount(listTriangles.size());
|
||||
|
||||
unsigned int i = 0;
|
||||
@ -600,7 +600,7 @@ void WriterNodeVisitor::buildFaces(const osg::Geode& geo,
|
||||
else
|
||||
{
|
||||
mesh->BeginPolygon(i);
|
||||
lLayer->GetTextures(KFbxLayerElement::eDIFFUSE_TEXTURES)->GetIndexArray().SetAt(i, it->first.material);
|
||||
lLayer->GetTextures(FbxLayerElement::eTextureDiffuse)->GetIndexArray().SetAt(i, it->first.material);
|
||||
lLayer->GetMaterials()->GetIndexArray().SetAt(i, it->first.material);
|
||||
}
|
||||
addPolygon(mesh, index_vert, it->first, it->second);
|
||||
@ -650,8 +650,8 @@ void WriterNodeVisitor::createListTriangle(const osg::Geometry* geo,
|
||||
|
||||
void WriterNodeVisitor::apply(osg::Geode& node)
|
||||
{
|
||||
KFbxNode* parent = _curFbxNode;
|
||||
KFbxNode* nodeFBX = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
FbxNode* parent = _curFbxNode;
|
||||
FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
_curFbxNode->AddChild(nodeFBX);
|
||||
_curFbxNode = nodeFBX;
|
||||
unsigned int count = node.getNumDrawables();
|
||||
@ -687,9 +687,9 @@ void WriterNodeVisitor::apply(osg::Geode& node)
|
||||
|
||||
void WriterNodeVisitor::apply(osg::Group& node)
|
||||
{
|
||||
KFbxNode* parent = _curFbxNode;
|
||||
FbxNode* parent = _curFbxNode;
|
||||
|
||||
KFbxNode* nodeFBX = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
FbxNode* nodeFBX = FbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
_curFbxNode->AddChild(nodeFBX);
|
||||
_curFbxNode = nodeFBX;
|
||||
traverse(node);
|
||||
@ -698,8 +698,8 @@ void WriterNodeVisitor::apply(osg::Group& node)
|
||||
|
||||
void WriterNodeVisitor::apply(osg::MatrixTransform& node)
|
||||
{
|
||||
KFbxNode* parent = _curFbxNode;
|
||||
_curFbxNode = KFbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
FbxNode* parent = _curFbxNode;
|
||||
_curFbxNode = FbxNode::Create(_pSdkManager, node.getName().empty() ? "DefaultName" : node.getName().c_str());
|
||||
parent->AddChild(_curFbxNode);
|
||||
|
||||
const osg::Matrix& matrix = node.getMatrix();
|
||||
@ -707,16 +707,16 @@ void WriterNodeVisitor::apply(osg::MatrixTransform& node)
|
||||
osg::Quat rot, so;
|
||||
|
||||
matrix.decompose(pos, rot, scl, so);
|
||||
_curFbxNode->LclTranslation.Set(fbxDouble3(pos.x(), pos.y(), pos.z()));
|
||||
_curFbxNode->LclScaling.Set(fbxDouble3(scl.x(), scl.y(), scl.z()));
|
||||
_curFbxNode->LclTranslation.Set(FbxDouble3(pos.x(), pos.y(), pos.z()));
|
||||
_curFbxNode->LclScaling.Set(FbxDouble3(scl.x(), scl.y(), scl.z()));
|
||||
|
||||
KFbxXMatrix mat;
|
||||
FbxAMatrix mat;
|
||||
|
||||
KFbxQuaternion q(rot.x(), rot.y(), rot.z(), rot.w());
|
||||
FbxQuaternion q(rot.x(), rot.y(), rot.z(), rot.w());
|
||||
mat.SetQ(q);
|
||||
KFbxVector4 vec4 = mat.GetR();
|
||||
FbxVector4 vec4 = mat.GetR();
|
||||
|
||||
_curFbxNode->LclRotation.Set(fbxDouble3(vec4[0], vec4[1], vec4[2]));
|
||||
_curFbxNode->LclRotation.Set(FbxDouble3(vec4[0], vec4[1], vec4[2]));
|
||||
|
||||
traverse(node);
|
||||
_curFbxNode = parent;
|
||||
|
@ -70,8 +70,8 @@ namespace pluginfbx
|
||||
class WriterNodeVisitor: public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
WriterNodeVisitor(KFbxScene* pScene,
|
||||
KFbxSdkManager* pSdkManager,
|
||||
WriterNodeVisitor(FbxScene* pScene,
|
||||
FbxManager* pSdkManager,
|
||||
const std::string& fileName,
|
||||
const osgDB::ReaderWriter::Options* options,
|
||||
const std::string& srcDirectory) :
|
||||
@ -144,16 +144,16 @@ class WriterNodeVisitor: public osg::NodeVisitor
|
||||
const osg::StateSet* stateset,
|
||||
const osg::Material* mat,
|
||||
const osg::Texture* tex,
|
||||
KFbxSdkManager* pSdkManager,
|
||||
FbxManager* pSdkManager,
|
||||
const osgDB::ReaderWriter::Options * options,
|
||||
int index = -1);
|
||||
|
||||
KFbxFileTexture* getFbxTexture() const
|
||||
FbxFileTexture* getFbxTexture() const
|
||||
{
|
||||
return _fbxTexture;
|
||||
}
|
||||
|
||||
KFbxSurfaceMaterial* getFbxMaterial() const
|
||||
FbxSurfaceMaterial* getFbxMaterial() const
|
||||
{
|
||||
return _fbxMaterial;
|
||||
}
|
||||
@ -174,8 +174,8 @@ class WriterNodeVisitor: public osg::NodeVisitor
|
||||
}
|
||||
|
||||
private:
|
||||
KFbxSurfacePhong* _fbxMaterial;
|
||||
KFbxFileTexture* _fbxTexture;
|
||||
FbxSurfacePhong* _fbxMaterial;
|
||||
FbxFileTexture* _fbxTexture;
|
||||
int _index;///< Index in the Map
|
||||
const osg::Image* _osgImage;
|
||||
};
|
||||
@ -203,13 +203,13 @@ class WriterNodeVisitor: public osg::NodeVisitor
|
||||
bool texcoords);
|
||||
|
||||
/// Set the layer for texture and Material in layer 0.
|
||||
void setLayerTextureAndMaterial(KFbxMesh* mesh);
|
||||
void setLayerTextureAndMaterial(FbxMesh* mesh);
|
||||
|
||||
/// Set Vertices, normals, and UVs
|
||||
void setControlPointAndNormalsAndUV(const osg::Geode& geo,
|
||||
MapIndices& index_vert,
|
||||
bool texcoords,
|
||||
KFbxMesh* fbxMesh);
|
||||
FbxMesh* fbxMesh);
|
||||
|
||||
/**
|
||||
* Create the list of faces from the geode.
|
||||
@ -230,7 +230,7 @@ class WriterNodeVisitor: public osg::NodeVisitor
|
||||
typedef std::map<osg::ref_ptr<const osg::StateSet>, Material, CompareStateSet> MaterialMap;
|
||||
|
||||
///We need this for every new Node we create.
|
||||
KFbxSdkManager* _pSdkManager;
|
||||
FbxManager* _pSdkManager;
|
||||
|
||||
///Tell us if the last apply succeed, useful to stop going through the graph.
|
||||
bool _succeedLastApply;
|
||||
@ -239,10 +239,10 @@ class WriterNodeVisitor: public osg::NodeVisitor
|
||||
std::string _directory;
|
||||
|
||||
///The Scene to save.
|
||||
KFbxScene* _pScene;
|
||||
FbxScene* _pScene;
|
||||
|
||||
///The current Fbx Node.
|
||||
KFbxNode* _curFbxNode;
|
||||
FbxNode* _curFbxNode;
|
||||
|
||||
///The Stack of different stateSet.
|
||||
StateSetStack _stateSetStack;
|
||||
|
@ -5,14 +5,14 @@
|
||||
#include <osgDB/FileNameUtils>
|
||||
|
||||
|
||||
static osg::Texture::WrapMode convertWrap(KFbxFileTexture::EWrapMode wrap)
|
||||
static osg::Texture::WrapMode convertWrap(FbxFileTexture::EWrapMode wrap)
|
||||
{
|
||||
return wrap == KFbxFileTexture::eREPEAT ?
|
||||
return wrap == FbxFileTexture::eRepeat ?
|
||||
osg::Texture2D::REPEAT : osg::Texture2D::CLAMP_TO_EDGE;
|
||||
}
|
||||
|
||||
StateSetContent
|
||||
FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat)
|
||||
{
|
||||
FbxMaterialMap::const_iterator it = _fbxMaterialMap.find(pFbxMat);
|
||||
if (it != _fbxMaterialMap.end())
|
||||
@ -25,18 +25,18 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
|
||||
result.material = pOsgMat;
|
||||
|
||||
fbxString shadingModel = pFbxMat->ShadingModel.Get();
|
||||
FbxString shadingModel = pFbxMat->ShadingModel.Get();
|
||||
|
||||
const KFbxSurfaceLambert* pFbxLambert = KFbxCast<KFbxSurfaceLambert>(pFbxMat);
|
||||
const FbxSurfaceLambert* pFbxLambert = FbxCast<FbxSurfaceLambert>(pFbxMat);
|
||||
|
||||
// diffuse map...
|
||||
const KFbxProperty lProperty = pFbxMat->FindProperty(KFbxSurfaceMaterial::sDiffuse);
|
||||
const FbxProperty lProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sDiffuse);
|
||||
if (lProperty.IsValid())
|
||||
{
|
||||
int lNbTex = lProperty.GetSrcObjectCount(KFbxFileTexture::ClassId);
|
||||
int lNbTex = lProperty.GetSrcObjectCount<FbxFileTexture>();
|
||||
for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
|
||||
{
|
||||
KFbxFileTexture* lTexture = KFbxCast<KFbxFileTexture>(lProperty.GetSrcObject(KFbxFileTexture::ClassId, lTextureIndex));
|
||||
FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
|
||||
if (lTexture)
|
||||
{
|
||||
result.diffuseTexture = fbxTextureToOsgTexture(lTexture);
|
||||
@ -51,13 +51,13 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
}
|
||||
|
||||
// opacity map...
|
||||
const KFbxProperty lOpacityProperty = pFbxMat->FindProperty(KFbxSurfaceMaterial::sTransparentColor);
|
||||
const FbxProperty lOpacityProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sTransparentColor);
|
||||
if (lOpacityProperty.IsValid())
|
||||
{
|
||||
int lNbTex = lOpacityProperty.GetSrcObjectCount(KFbxFileTexture::ClassId);
|
||||
int lNbTex = lOpacityProperty.GetSrcObjectCount<FbxFileTexture>();
|
||||
for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
|
||||
{
|
||||
KFbxFileTexture* lTexture = KFbxCast<KFbxFileTexture>(lOpacityProperty.GetSrcObject(KFbxFileTexture::ClassId, lTextureIndex));
|
||||
FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lOpacityProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
|
||||
if (lTexture)
|
||||
{
|
||||
// TODO: if texture image does NOT have an alpha channel, should it be added?
|
||||
@ -74,17 +74,17 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
}
|
||||
|
||||
// reflection map...
|
||||
const KFbxProperty lReflectionProperty = pFbxMat->FindProperty(KFbxSurfaceMaterial::sReflection);
|
||||
const FbxProperty lReflectionProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sReflection);
|
||||
if (lReflectionProperty.IsValid())
|
||||
{
|
||||
int lNbTex = lReflectionProperty.GetSrcObjectCount(KFbxFileTexture::ClassId);
|
||||
int lNbTex = lReflectionProperty.GetSrcObjectCount<FbxFileTexture>();
|
||||
for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
|
||||
{
|
||||
KFbxFileTexture* lTexture = KFbxCast<KFbxFileTexture>(lReflectionProperty.GetSrcObject(KFbxFileTexture::ClassId, lTextureIndex));
|
||||
FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lReflectionProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
|
||||
if (lTexture)
|
||||
{
|
||||
// support only spherical reflection maps...
|
||||
if (KFbxFileTexture::eUMT_ENVIRONMENT == lTexture->CurrentMappingType.Get())
|
||||
if (FbxFileTexture::eUMT_ENVIRONMENT == lTexture->CurrentMappingType.Get())
|
||||
{
|
||||
result.reflectionTexture = fbxTextureToOsgTexture(lTexture);
|
||||
result.reflectionChannel = lTexture->UVSet.Get();
|
||||
@ -97,13 +97,13 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
}
|
||||
|
||||
// emissive map...
|
||||
const KFbxProperty lEmissiveProperty = pFbxMat->FindProperty(KFbxSurfaceMaterial::sEmissive);
|
||||
const FbxProperty lEmissiveProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sEmissive);
|
||||
if (lEmissiveProperty.IsValid())
|
||||
{
|
||||
int lNbTex = lEmissiveProperty.GetSrcObjectCount(KFbxFileTexture::ClassId);
|
||||
int lNbTex = lEmissiveProperty.GetSrcObjectCount<FbxFileTexture>();
|
||||
for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++)
|
||||
{
|
||||
KFbxFileTexture* lTexture = KFbxCast<KFbxFileTexture>(lEmissiveProperty.GetSrcObject(KFbxFileTexture::ClassId, lTextureIndex));
|
||||
FbxFileTexture* lTexture = FbxCast<FbxFileTexture>(lEmissiveProperty.GetSrcObject<FbxFileTexture>(lTextureIndex));
|
||||
if (lTexture)
|
||||
{
|
||||
result.emissiveTexture = fbxTextureToOsgTexture(lTexture);
|
||||
@ -119,7 +119,7 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
|
||||
if (pFbxLambert)
|
||||
{
|
||||
fbxDouble3 color = pFbxLambert->Diffuse.Get();
|
||||
FbxDouble3 color = pFbxLambert->Diffuse.Get();
|
||||
double factor = pFbxLambert->DiffuseFactor.Get();
|
||||
pOsgMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(
|
||||
static_cast<float>(color[0] * factor),
|
||||
@ -146,7 +146,7 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
// get maps factors...
|
||||
result.diffuseFactor = pFbxLambert->DiffuseFactor.Get();
|
||||
|
||||
if (const KFbxSurfacePhong* pFbxPhong = KFbxCast<KFbxSurfacePhong>(pFbxLambert))
|
||||
if (const FbxSurfacePhong* pFbxPhong = FbxCast<FbxSurfacePhong>(pFbxLambert))
|
||||
{
|
||||
color = pFbxPhong->Specular.Get();
|
||||
factor = pFbxPhong->SpecularFactor.Get();
|
||||
@ -182,7 +182,7 @@ FbxMaterialToOsgStateSet::convert(const KFbxSurfaceMaterial* pFbxMat)
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Texture2D>
|
||||
FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const KFbxFileTexture* fbx)
|
||||
FbxMaterialToOsgStateSet::fbxTextureToOsgTexture(const FbxFileTexture* fbx)
|
||||
{
|
||||
ImageMap::iterator it = _imageMap.find(fbx->GetFileName());
|
||||
if (it != _imageMap.end())
|
||||
|
@ -67,7 +67,7 @@ struct StateSetContent
|
||||
};
|
||||
|
||||
//We use the pointers set by the importer to not duplicate materials and textures.
|
||||
typedef std::map<const KFbxSurfaceMaterial *, StateSetContent> FbxMaterialMap;
|
||||
typedef std::map<const FbxSurfaceMaterial *, StateSetContent> FbxMaterialMap;
|
||||
|
||||
//This map is used to not load the same image more than 1 time.
|
||||
typedef std::map<std::string, osg::Texture2D *> ImageMap;
|
||||
@ -75,8 +75,8 @@ typedef std::map<std::string, osg::Texture2D *> ImageMap;
|
||||
class FbxMaterialToOsgStateSet
|
||||
{
|
||||
public:
|
||||
//Convert a KfbxSurfaceMaterial to a osgMaterial and an osgTexture.
|
||||
StateSetContent convert(const KFbxSurfaceMaterial* pFbxMat);
|
||||
//Convert a FbxSurfaceMaterial to a osgMaterial and an osgTexture.
|
||||
StateSetContent convert(const FbxSurfaceMaterial* pFbxMat);
|
||||
|
||||
//dir is the directory where fbx is stored (for relative path).
|
||||
FbxMaterialToOsgStateSet(const std::string& dir, const osgDB::Options* options, bool lightmapTextures) :
|
||||
@ -88,7 +88,7 @@ public:
|
||||
private:
|
||||
//Convert a texture fbx to an osg texture.
|
||||
osg::ref_ptr<osg::Texture2D>
|
||||
fbxTextureToOsgTexture(const KFbxFileTexture* pOsgTex);
|
||||
fbxTextureToOsgTexture(const FbxFileTexture* pOsgTex);
|
||||
FbxMaterialMap _fbxMaterialMap;
|
||||
ImageMap _imageMap;
|
||||
const osgDB::Options* _options;
|
||||
|
@ -10,26 +10,24 @@
|
||||
#pragma warning( default : 4996 )
|
||||
#endif
|
||||
#include <fbxsdk.h>
|
||||
#include <fbxfilesdk/fbxfilesdk_nsuse.h>
|
||||
|
||||
#include "fbxReader.h"
|
||||
|
||||
osg::Quat makeQuat(const fbxDouble3&, ERotationOrder);
|
||||
osg::Quat makeQuat(const FbxDouble3&, EFbxRotationOrder);
|
||||
|
||||
osg::Quat makeQuat(const osg::Vec3& radians, ERotationOrder fbxRotOrder)
|
||||
osg::Quat makeQuat(const osg::Vec3& radians, EFbxRotationOrder fbxRotOrder)
|
||||
{
|
||||
fbxDouble3 degrees(
|
||||
FbxDouble3 degrees(
|
||||
osg::RadiansToDegrees(radians.x()),
|
||||
osg::RadiansToDegrees(radians.y()),
|
||||
osg::RadiansToDegrees(radians.z()));
|
||||
return makeQuat(degrees, fbxRotOrder);
|
||||
}
|
||||
|
||||
void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curveZ,
|
||||
const fbxDouble3& defaultValue,
|
||||
void readKeys(FbxAnimCurve* curveX, FbxAnimCurve* curveY, FbxAnimCurve* curveZ,
|
||||
const FbxDouble3& defaultValue,
|
||||
std::vector<osgAnimation::TemplateKeyframe<osg::Vec3> >& keyFrameCntr, float scalar = 1.0f)
|
||||
{
|
||||
KFbxAnimCurve* curves[3] = {curveX, curveY, curveZ};
|
||||
FbxAnimCurve* curves[3] = {curveX, curveY, curveZ};
|
||||
|
||||
typedef std::set<double> TimeSet;
|
||||
typedef std::map<double, float> TimeFloatMap;
|
||||
@ -38,7 +36,7 @@ void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curve
|
||||
|
||||
for (int nCurve = 0; nCurve < 3; ++nCurve)
|
||||
{
|
||||
KFbxAnimCurve* pCurve = curves[nCurve];
|
||||
FbxAnimCurve* pCurve = curves[nCurve];
|
||||
|
||||
int nKeys = pCurve ? pCurve->KeyGetCount() : 0;
|
||||
|
||||
@ -50,7 +48,7 @@ void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curve
|
||||
|
||||
for (int i = 0; i < nKeys; ++i)
|
||||
{
|
||||
KFbxAnimCurveKey key = pCurve->KeyGet(i);
|
||||
FbxAnimCurveKey key = pCurve->KeyGet(i);
|
||||
double fTime = key.GetTime().GetSecondDouble();
|
||||
times.insert(fTime);
|
||||
curveTimeMap[nCurve][fTime] = static_cast<float>(key.GetValue()) * scalar;
|
||||
@ -73,11 +71,11 @@ void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curve
|
||||
}
|
||||
}
|
||||
|
||||
void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curveZ,
|
||||
const fbxDouble3& defaultValue,
|
||||
void readKeys(FbxAnimCurve* curveX, FbxAnimCurve* curveY, FbxAnimCurve* curveZ,
|
||||
const FbxDouble3& defaultValue,
|
||||
std::vector<osgAnimation::Vec3CubicBezierKeyframe>& keyFrameCntr, float scalar = 1.0f)
|
||||
{
|
||||
KFbxAnimCurve* curves[3] = {curveX, curveY, curveZ};
|
||||
FbxAnimCurve* curves[3] = {curveX, curveY, curveZ};
|
||||
|
||||
typedef std::set<double> TimeSet;
|
||||
typedef std::map<double, osgAnimation::FloatCubicBezier> TimeValueMap;
|
||||
@ -86,7 +84,7 @@ void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curve
|
||||
|
||||
for (int nCurve = 0; nCurve < 3; ++nCurve)
|
||||
{
|
||||
KFbxAnimCurve* pCurve = curves[nCurve];
|
||||
FbxAnimCurve* pCurve = curves[nCurve];
|
||||
|
||||
int nKeys = pCurve ? pCurve->KeyGetCount() : 0;
|
||||
|
||||
@ -101,8 +99,8 @@ void readKeys(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curve
|
||||
double fTime = pCurve->KeyGetTime(i).GetSecondDouble();
|
||||
float val = pCurve->KeyGetValue(i);
|
||||
times.insert(fTime);
|
||||
KFCurveTangeantInfo leftTangent = pCurve->KeyGetLeftDerivativeInfo(i);
|
||||
KFCurveTangeantInfo rightTangent = pCurve->KeyGetRightDerivativeInfo(i);
|
||||
FbxAnimCurveTangentInfo leftTangent = pCurve->KeyGetLeftDerivativeInfo(i);
|
||||
FbxAnimCurveTangentInfo rightTangent = pCurve->KeyGetRightDerivativeInfo(i);
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
@ -176,9 +174,9 @@ void reorderControlPoints(osgAnimation::TemplateKeyframeContainer<osgAnimation::
|
||||
vkfCont.back().setValue(last);
|
||||
}
|
||||
|
||||
osgAnimation::Channel* readFbxChannels(KFbxAnimCurve* curveX, KFbxAnimCurve* curveY,
|
||||
KFbxAnimCurve* curveZ,
|
||||
const fbxDouble3& defaultValue,
|
||||
osgAnimation::Channel* readFbxChannels(FbxAnimCurve* curveX, FbxAnimCurve* curveY,
|
||||
FbxAnimCurve* curveZ,
|
||||
const FbxDouble3& defaultValue,
|
||||
const char* targetName, const char* channelName)
|
||||
{
|
||||
if (!(curveX && curveX->KeyGetCount()) &&
|
||||
@ -188,14 +186,14 @@ osgAnimation::Channel* readFbxChannels(KFbxAnimCurve* curveX, KFbxAnimCurve* cur
|
||||
return 0;
|
||||
}
|
||||
|
||||
KFbxAnimCurveDef::EInterpolationType interpolationType = KFbxAnimCurveDef::eINTERPOLATION_CONSTANT;
|
||||
FbxAnimCurveDef::EInterpolationType interpolationType = FbxAnimCurveDef::eInterpolationConstant;
|
||||
if (curveX && curveX->KeyGetCount()) interpolationType = curveX->KeyGetInterpolation(0);
|
||||
else if (curveY && curveY->KeyGetCount()) interpolationType = curveY->KeyGetInterpolation(0);
|
||||
else if (curveZ && curveZ->KeyGetCount()) interpolationType = curveZ->KeyGetInterpolation(0);
|
||||
|
||||
osgAnimation::Channel* pChannel = 0;
|
||||
|
||||
if (interpolationType == KFbxAnimCurveDef::eINTERPOLATION_CUBIC)
|
||||
if (interpolationType == FbxAnimCurveDef::eInterpolationCubic)
|
||||
{
|
||||
osgAnimation::Vec3CubicBezierKeyframeContainer* pKeyFrameCntr = new osgAnimation::Vec3CubicBezierKeyframeContainer;
|
||||
readKeys(curveX, curveY, curveZ, defaultValue, *pKeyFrameCntr);
|
||||
@ -210,7 +208,7 @@ osgAnimation::Channel* readFbxChannels(KFbxAnimCurve* curveX, KFbxAnimCurve* cur
|
||||
osgAnimation::Vec3KeyframeContainer* pKeyFrameCntr = new osgAnimation::Vec3KeyframeContainer;
|
||||
readKeys(curveX, curveY, curveZ, defaultValue, *pKeyFrameCntr);
|
||||
|
||||
if (interpolationType == KFbxAnimCurveDef::eINTERPOLATION_CONSTANT)
|
||||
if (interpolationType == FbxAnimCurveDef::eInterpolationConstant)
|
||||
{
|
||||
osgAnimation::Vec3StepChannel* pStepChannel = new osgAnimation::Vec3StepChannel;
|
||||
pStepChannel->getOrCreateSampler()->setKeyframeContainer(pKeyFrameCntr);
|
||||
@ -231,23 +229,23 @@ osgAnimation::Channel* readFbxChannels(KFbxAnimCurve* curveX, KFbxAnimCurve* cur
|
||||
}
|
||||
|
||||
osgAnimation::Channel* readFbxChannels(
|
||||
KFbxTypedProperty<fbxDouble3>& fbxProp, KFbxAnimLayer* pAnimLayer,
|
||||
FbxPropertyT<FbxDouble3>& fbxProp, FbxAnimLayer* pAnimLayer,
|
||||
const char* targetName, const char* channelName)
|
||||
{
|
||||
if (!fbxProp.IsValid()) return 0;
|
||||
|
||||
return readFbxChannels(
|
||||
fbxProp.GetCurve<KFbxAnimCurve>(pAnimLayer, "X"),
|
||||
fbxProp.GetCurve<KFbxAnimCurve>(pAnimLayer, "Y"),
|
||||
fbxProp.GetCurve<KFbxAnimCurve>(pAnimLayer, "Z"),
|
||||
fbxProp.GetCurve(pAnimLayer, "X"),
|
||||
fbxProp.GetCurve(pAnimLayer, "Y"),
|
||||
fbxProp.GetCurve(pAnimLayer, "Z"),
|
||||
fbxProp.Get(),
|
||||
targetName, channelName);
|
||||
}
|
||||
|
||||
osgAnimation::Channel* readFbxChannelsQuat(
|
||||
KFbxAnimCurve* curveX, KFbxAnimCurve* curveY, KFbxAnimCurve* curveZ,
|
||||
const fbxDouble3& defaultValue,
|
||||
const char* targetName, ERotationOrder rotOrder)
|
||||
FbxAnimCurve* curveX, FbxAnimCurve* curveY, FbxAnimCurve* curveZ,
|
||||
const FbxDouble3& defaultValue,
|
||||
const char* targetName, EFbxRotationOrder rotOrder)
|
||||
{
|
||||
if (!(curveX && curveX->KeyGetCount()) &&
|
||||
!(curveY && curveY->KeyGetCount()) &&
|
||||
@ -324,46 +322,46 @@ osgAnimation::Animation* addChannels(
|
||||
}
|
||||
|
||||
void readFbxRotationAnimation(osgAnimation::Channel* channels[3],
|
||||
KFbxNode* pNode,
|
||||
KFbxAnimLayer* pAnimLayer, const char* targetName)
|
||||
FbxNode* pNode,
|
||||
FbxAnimLayer* pAnimLayer, const char* targetName)
|
||||
{
|
||||
if (!pNode->LclRotation.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ERotationOrder rotOrder = pNode->RotationOrder.IsValid() ? pNode->RotationOrder.Get() : eEULER_XYZ;
|
||||
EFbxRotationOrder rotOrder = pNode->RotationOrder.IsValid() ? pNode->RotationOrder.Get() : eEulerXYZ;
|
||||
|
||||
if (pNode->QuaternionInterpolate.IsValid() && pNode->QuaternionInterpolate.Get())
|
||||
{
|
||||
channels[0] = readFbxChannelsQuat(
|
||||
pNode->LclRotation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_R_X),
|
||||
pNode->LclRotation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_R_Y),
|
||||
pNode->LclRotation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_R_Z),
|
||||
pNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_X),
|
||||
pNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y),
|
||||
pNode->LclRotation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z),
|
||||
pNode->LclRotation.Get(),
|
||||
targetName, rotOrder);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* curveNames[3] = {KFCURVENODE_R_X, KFCURVENODE_R_Y, KFCURVENODE_R_Z};
|
||||
const char* curveNames[3] = {FBXSDK_CURVENODE_COMPONENT_X, FBXSDK_CURVENODE_COMPONENT_Y, FBXSDK_CURVENODE_COMPONENT_Z};
|
||||
|
||||
fbxDouble3 fbxPropValue = pNode->LclRotation.Get();
|
||||
FbxDouble3 fbxPropValue = pNode->LclRotation.Get();
|
||||
fbxPropValue[0] = osg::DegreesToRadians(fbxPropValue[0]);
|
||||
fbxPropValue[1] = osg::DegreesToRadians(fbxPropValue[1]);
|
||||
fbxPropValue[2] = osg::DegreesToRadians(fbxPropValue[2]);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
KFbxAnimCurve* curve = pNode->LclRotation.GetCurve<KFbxAnimCurve>(pAnimLayer, curveNames[i]);
|
||||
FbxAnimCurve* curve = pNode->LclRotation.GetCurve(pAnimLayer, curveNames[i]);
|
||||
if (!curve)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
KFbxAnimCurveDef::EInterpolationType interpolationType = KFbxAnimCurveDef::eINTERPOLATION_CONSTANT;
|
||||
FbxAnimCurveDef::EInterpolationType interpolationType = FbxAnimCurveDef::eInterpolationConstant;
|
||||
if (curve && curve->KeyGetCount()) interpolationType = curve->KeyGetInterpolation(0);
|
||||
|
||||
if (interpolationType == KFbxAnimCurveDef::eINTERPOLATION_CUBIC)
|
||||
if (interpolationType == FbxAnimCurveDef::eInterpolationCubic)
|
||||
{
|
||||
osgAnimation::FloatCubicBezierKeyframeContainer* pKeyFrameCntr = new osgAnimation::FloatCubicBezierKeyframeContainer;
|
||||
|
||||
@ -371,10 +369,10 @@ void readFbxRotationAnimation(osgAnimation::Channel* channels[3],
|
||||
{
|
||||
double fTime = curve->KeyGetTime(j).GetSecondDouble();
|
||||
float angle = curve->KeyGetValue(j);
|
||||
//KFbxAnimCurveDef::EWeightedMode tangentWeightMode = curve->KeyGet(j).GetTangentWeightMode();
|
||||
//FbxAnimCurveDef::EWeightedMode tangentWeightMode = curve->KeyGet(j).GetTangentWeightMode();
|
||||
|
||||
KFCurveTangeantInfo leftTangent = curve->KeyGetLeftDerivativeInfo(j);
|
||||
KFCurveTangeantInfo rightTangent = curve->KeyGetRightDerivativeInfo(j);
|
||||
FbxAnimCurveTangentInfo leftTangent = curve->KeyGetLeftDerivativeInfo(j);
|
||||
FbxAnimCurveTangentInfo rightTangent = curve->KeyGetRightDerivativeInfo(j);
|
||||
if (j > 0)
|
||||
{
|
||||
leftTangent.mDerivative *= fTime - curve->KeyGetTime(j - 1).GetSecondDouble();
|
||||
@ -405,13 +403,13 @@ void readFbxRotationAnimation(osgAnimation::Channel* channels[3],
|
||||
|
||||
for (int j = 0; j < curve->KeyGetCount(); ++j)
|
||||
{
|
||||
KFbxAnimCurveKey key = curve->KeyGet(j);
|
||||
FbxAnimCurveKey key = curve->KeyGet(j);
|
||||
keys->push_back(osgAnimation::FloatKeyframe(
|
||||
key.GetTime().GetSecondDouble(),
|
||||
static_cast<float>(osg::DegreesToRadians(key.GetValue()))));
|
||||
}
|
||||
|
||||
if (interpolationType == KFbxAnimCurveDef::eINTERPOLATION_CONSTANT)
|
||||
if (interpolationType == FbxAnimCurveDef::eInterpolationConstant)
|
||||
{
|
||||
osgAnimation::FloatStepChannel* pStepChannel = new osgAnimation::FloatStepChannel();
|
||||
pStepChannel->getOrCreateSampler()->setKeyframeContainer(keys);
|
||||
@ -431,8 +429,8 @@ void readFbxRotationAnimation(osgAnimation::Channel* channels[3],
|
||||
}
|
||||
}
|
||||
|
||||
osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode,
|
||||
KFbxAnimLayer* pAnimLayer, const char* pTakeName, const char* targetName,
|
||||
osgAnimation::Animation* readFbxAnimation(FbxNode* pNode,
|
||||
FbxAnimLayer* pAnimLayer, const char* pTakeName, const char* targetName,
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerBase>& pAnimManager)
|
||||
{
|
||||
osgAnimation::Channel* pTranslationChannel = 0;
|
||||
@ -443,9 +441,9 @@ osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode,
|
||||
if (pNode->LclTranslation.IsValid())
|
||||
{
|
||||
pTranslationChannel = readFbxChannels(
|
||||
pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_T_X),
|
||||
pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_T_Y),
|
||||
pNode->LclTranslation.GetCurve<KFbxAnimCurve>(pAnimLayer, KFCURVENODE_T_Z),
|
||||
pNode->LclTranslation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_X),
|
||||
pNode->LclTranslation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y),
|
||||
pNode->LclTranslation.GetCurve(pAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z),
|
||||
pNode->LclTranslation.Get(),
|
||||
targetName, "translate");
|
||||
}
|
||||
@ -456,14 +454,14 @@ osgAnimation::Animation* readFbxAnimation(KFbxNode* pNode,
|
||||
return addChannels(pTranslationChannel, pRotationChannels, pScaleChannel, pAnimManager, pTakeName);
|
||||
}
|
||||
|
||||
std::string OsgFbxReader::readFbxAnimation(KFbxNode* pNode, const char* targetName)
|
||||
std::string OsgFbxReader::readFbxAnimation(FbxNode* pNode, const char* targetName)
|
||||
{
|
||||
std::string result;
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i)
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount<FbxAnimStack>(); ++i)
|
||||
{
|
||||
KFbxAnimStack* pAnimStack = KFbxCast<KFbxAnimStack>(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i));
|
||||
FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(fbxScene.GetSrcObject<FbxAnimStack>(i));
|
||||
|
||||
int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer));
|
||||
int nbAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
|
||||
|
||||
const char* pTakeName = pAnimStack->GetName();
|
||||
|
||||
@ -472,7 +470,7 @@ std::string OsgFbxReader::readFbxAnimation(KFbxNode* pNode, const char* targetNa
|
||||
|
||||
for (int j = 0; j < nbAnimLayers; j++)
|
||||
{
|
||||
KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j);
|
||||
FbxAnimLayer* pAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(j);
|
||||
osgAnimation::Animation* pAnimation = ::readFbxAnimation(pNode, pAnimLayer, pTakeName, targetName, pAnimationManager);
|
||||
if (pAnimation)
|
||||
{
|
||||
|
@ -11,9 +11,9 @@
|
||||
|
||||
#include "fbxReader.h"
|
||||
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxCamera(KFbxNode* pNode)
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxCamera(FbxNode* pNode)
|
||||
{
|
||||
const KFbxCamera* fbxCamera = KFbxCast<KFbxCamera>(pNode->GetNodeAttribute());
|
||||
const FbxCamera* fbxCamera = FbxCast<FbxCamera>(pNode->GetNodeAttribute());
|
||||
|
||||
if (!fbxCamera)
|
||||
{
|
||||
@ -36,14 +36,14 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxCamera(KFbxNode* pNode)
|
||||
{
|
||||
switch (fbxCamera->ApertureMode.Get())
|
||||
{
|
||||
case KFbxCamera::eHORIZONTAL:
|
||||
case FbxCamera::eHorizontal:
|
||||
osgCameraView->setFieldOfViewMode(osg::CameraView::HORIZONTAL);
|
||||
break;
|
||||
case KFbxCamera::eVERTICAL:
|
||||
case FbxCamera::eVertical:
|
||||
osgCameraView->setFieldOfViewMode(osg::CameraView::VERTICAL);
|
||||
break;
|
||||
case KFbxCamera::eHORIZONTAL_AND_VERTICAL:
|
||||
case KFbxCamera::eFOCAL_LENGTH:
|
||||
case FbxCamera::eHorizAndVert:
|
||||
case FbxCamera::eFocalLength:
|
||||
default:
|
||||
OSG_WARN << "readFbxCamera: Unsupported Camera aperture mode." << std::endl;
|
||||
break;
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
#include "fbxReader.h"
|
||||
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int& nLightCount)
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(FbxNode* pNode, int& nLightCount)
|
||||
{
|
||||
const KFbxLight* fbxLight = KFbxCast<KFbxLight>(pNode->GetNodeAttribute());
|
||||
const FbxLight* fbxLight = FbxCast<FbxLight>(pNode->GetNodeAttribute());
|
||||
|
||||
if (!fbxLight)
|
||||
{
|
||||
@ -22,24 +22,24 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
|
||||
osg::Light* osgLight = new osg::Light;
|
||||
osg::LightSource* osgLightSource = new osg::LightSource;
|
||||
|
||||
osgLight->setLightNum(nLightCount++);
|
||||
osgLightSource->setLight(osgLight);
|
||||
osgLight->setLightNum(nLightCount++);
|
||||
|
||||
KFbxLight::ELightType fbxLightType = fbxLight->LightType.IsValid() ?
|
||||
fbxLight->LightType.Get() : KFbxLight::ePOINT;
|
||||
FbxLight::EType fbxLightType = fbxLight->LightType.IsValid() ?
|
||||
fbxLight->LightType.Get() : FbxLight::ePoint;
|
||||
|
||||
osgLight->setPosition(osg::Vec4(0,0,0,fbxLightType != KFbxLight::eDIRECTIONAL));
|
||||
osgLight->setPosition(osg::Vec4(0,0,0,fbxLightType != FbxLight::eDirectional));
|
||||
|
||||
if (fbxLightType == KFbxLight::eSPOT)
|
||||
if (fbxLightType == FbxLight::eSpot)
|
||||
{
|
||||
double coneAngle = fbxLight->ConeAngle.IsValid() ? fbxLight->ConeAngle.Get() : 45.0;
|
||||
double hotSpot = fbxLight->HotSpot.IsValid() ? fbxLight->HotSpot.Get() : 45.0;
|
||||
double coneAngle = fbxLight->OuterAngle.Get();
|
||||
double hotSpot = fbxLight->InnerAngle.Get();
|
||||
const float MIN_HOTSPOT = 0.467532f;
|
||||
|
||||
osgLight->setSpotCutoff(static_cast<float>(coneAngle));
|
||||
|
||||
//Approximate the hotspot using the GL light exponent.
|
||||
//This formula maps a hotspot of 180 to exponent 0 (uniform light
|
||||
// This formula maps a hotspot of 180 to exponent 0 (uniform light
|
||||
// distribution) and a hotspot of 45 to exponent 1 (effective light
|
||||
// intensity is attenuated by the cosine of the angle between the
|
||||
// direction of the light and the direction from the light to the vertex
|
||||
@ -56,13 +56,13 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
|
||||
|
||||
switch (fbxLight->DecayType.Get())
|
||||
{
|
||||
case KFbxLight::eNONE:
|
||||
case FbxLight::eNone:
|
||||
break;
|
||||
case KFbxLight::eLINEAR:
|
||||
case FbxLight::eLinear:
|
||||
osgLight->setLinearAttenuation(fbxDecayStart);
|
||||
break;
|
||||
case KFbxLight::eQUADRATIC:
|
||||
case KFbxLight::eCUBIC:
|
||||
case FbxLight::eQuadratic:
|
||||
case FbxLight::eCubic:
|
||||
osgLight->setQuadraticAttenuation(fbxDecayStart);
|
||||
break;
|
||||
}
|
||||
@ -72,7 +72,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
|
||||
osg::Vec3f osgAmbient(0.0f, 0.0f, 0.0f);
|
||||
if (fbxLight->Color.IsValid())
|
||||
{
|
||||
fbxDouble3 fbxColor = fbxLight->Color.Get();
|
||||
FbxDouble3 fbxColor = fbxLight->Color.Get();
|
||||
osgDiffuseSpecular.set(
|
||||
static_cast<float>(fbxColor[0]),
|
||||
static_cast<float>(fbxColor[1]),
|
||||
@ -84,7 +84,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxLight(KFbxNode* pNode, int&
|
||||
}
|
||||
if (fbxLight->ShadowColor.IsValid())
|
||||
{
|
||||
fbxDouble3 fbxShadowColor = fbxLight->ShadowColor.Get();
|
||||
FbxDouble3 fbxShadowColor = fbxLight->ShadowColor.Get();
|
||||
osgAmbient.set(
|
||||
static_cast<float>(fbxShadowColor[0]),
|
||||
static_cast<float>(fbxShadowColor[1]),
|
||||
|
@ -33,7 +33,7 @@ enum GeometryType
|
||||
GEOMETRY_MORPH
|
||||
};
|
||||
|
||||
osg::Vec3d convertVec3(const KFbxVector4& v)
|
||||
osg::Vec3d convertVec3(const FbxVector4& v)
|
||||
{
|
||||
return osg::Vec3d(
|
||||
v[0],
|
||||
@ -42,16 +42,16 @@ osg::Vec3d convertVec3(const KFbxVector4& v)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool layerElementValid(const KFbxLayerElementTemplate<T>* pLayerElement)
|
||||
bool layerElementValid(const FbxLayerElementTemplate<T>* pLayerElement)
|
||||
{
|
||||
if (!pLayerElement)
|
||||
return false;
|
||||
|
||||
switch (pLayerElement->GetMappingMode())
|
||||
{
|
||||
case KFbxLayerElement::eBY_CONTROL_POINT:
|
||||
case KFbxLayerElement::eBY_POLYGON_VERTEX:
|
||||
case KFbxLayerElement::eBY_POLYGON:
|
||||
case FbxLayerElement::eByControlPoint:
|
||||
case FbxLayerElement::eByPolygonVertex:
|
||||
case FbxLayerElement::eByPolygon:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -59,8 +59,8 @@ bool layerElementValid(const KFbxLayerElementTemplate<T>* pLayerElement)
|
||||
|
||||
switch (pLayerElement->GetReferenceMode())
|
||||
{
|
||||
case KFbxLayerElement::eDIRECT:
|
||||
case KFbxLayerElement::eINDEX_TO_DIRECT:
|
||||
case FbxLayerElement::eDirect:
|
||||
case FbxLayerElement::eIndexToDirect:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
@ -70,28 +70,28 @@ bool layerElementValid(const KFbxLayerElementTemplate<T>* pLayerElement)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int getVertexIndex(const KFbxLayerElementTemplate<T>* pLayerElement,
|
||||
const KFbxMesh* fbxMesh,
|
||||
int getVertexIndex(const FbxLayerElementTemplate<T>* pLayerElement,
|
||||
const FbxMesh* fbxMesh,
|
||||
int nPolygon, int nPolyVertex, int nMeshVertex)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
switch (pLayerElement->GetMappingMode())
|
||||
{
|
||||
case KFbxLayerElement::eBY_CONTROL_POINT:
|
||||
case FbxLayerElement::eByControlPoint:
|
||||
index = fbxMesh->GetPolygonVertex(nPolygon, nPolyVertex);
|
||||
break;
|
||||
case KFbxLayerElement::eBY_POLYGON_VERTEX:
|
||||
case FbxLayerElement::eByPolygonVertex:
|
||||
index = nMeshVertex;
|
||||
break;
|
||||
case KFbxLayerElement::eBY_POLYGON:
|
||||
case FbxLayerElement::eByPolygon:
|
||||
index = nPolygon;
|
||||
break;
|
||||
default:
|
||||
OSG_WARN << "getVertexIndex: unsupported FBX mapping mode" << std::endl;
|
||||
}
|
||||
|
||||
if (pLayerElement->GetReferenceMode() == KFbxLayerElement::eDIRECT)
|
||||
if (pLayerElement->GetReferenceMode() == FbxLayerElement::eDirect)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
@ -100,16 +100,16 @@ int getVertexIndex(const KFbxLayerElementTemplate<T>* pLayerElement,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int getPolygonIndex(const KFbxLayerElementTemplate<T>* pLayerElement, int nPolygon)
|
||||
int getPolygonIndex(const FbxLayerElementTemplate<T>* pLayerElement, int nPolygon)
|
||||
{
|
||||
if (pLayerElement &&
|
||||
pLayerElement->GetMappingMode() == KFbxLayerElement::eBY_POLYGON)
|
||||
pLayerElement->GetMappingMode() == FbxLayerElement::eByPolygon)
|
||||
{
|
||||
switch (pLayerElement->GetReferenceMode())
|
||||
{
|
||||
case KFbxLayerElement::eDIRECT:
|
||||
case FbxLayerElement::eDirect:
|
||||
return nPolygon;
|
||||
case KFbxLayerElement::eINDEX_TO_DIRECT:
|
||||
case FbxLayerElement::eIndexToDirect:
|
||||
return pLayerElement->GetIndexArray().GetAt(nPolygon);
|
||||
default:
|
||||
break;
|
||||
@ -120,8 +120,8 @@ int getPolygonIndex(const KFbxLayerElementTemplate<T>* pLayerElement, int nPolyg
|
||||
}
|
||||
|
||||
template <typename FbxT>
|
||||
FbxT getElement(const KFbxLayerElementTemplate<FbxT>* pLayerElement,
|
||||
const KFbxMesh* fbxMesh,
|
||||
FbxT getElement(const FbxLayerElementTemplate<FbxT>* pLayerElement,
|
||||
const FbxMesh* fbxMesh,
|
||||
int nPolygon, int nPolyVertex, int nMeshVertex)
|
||||
{
|
||||
return pLayerElement->GetDirectArray().GetAt(getVertexIndex(
|
||||
@ -361,15 +361,15 @@ void addChannel(
|
||||
pAnimation->addChannel(pChannel);
|
||||
}
|
||||
|
||||
void readAnimation(KFbxNode* pNode, KFbxScene& fbxScene, const std::string& targetName,
|
||||
void readAnimation(FbxNode* pNode, FbxScene& fbxScene, const std::string& targetName,
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerBase>& pAnimationManager,
|
||||
KFbxMesh* pMesh, int nBlendShape, int nBlendShapeChannel, int nShape)
|
||||
FbxMesh* pMesh, int nBlendShape, int nBlendShapeChannel, int nShape)
|
||||
{
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i)
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount<FbxAnimStack>(); ++i)
|
||||
{
|
||||
KFbxAnimStack* pAnimStack = KFbxCast<KFbxAnimStack>(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i));
|
||||
FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(fbxScene.GetSrcObject<FbxAnimStack>(i));
|
||||
|
||||
int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer));
|
||||
int nbAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
|
||||
|
||||
const char* pTakeName = pAnimStack->GetName();
|
||||
|
||||
@ -378,9 +378,9 @@ void readAnimation(KFbxNode* pNode, KFbxScene& fbxScene, const std::string& targ
|
||||
|
||||
for (int j = 0; j < nbAnimLayers; j++)
|
||||
{
|
||||
KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j);
|
||||
FbxAnimLayer* pAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(j);
|
||||
|
||||
KFbxAnimCurve* pCurve = pMesh->GetShapeChannel(nBlendShape, nBlendShapeChannel, pAnimLayer, false);
|
||||
FbxAnimCurve* pCurve = pMesh->GetShapeChannel(nBlendShape, nBlendShapeChannel, pAnimLayer, false);
|
||||
|
||||
if (!pCurve)
|
||||
{
|
||||
@ -398,7 +398,7 @@ void readAnimation(KFbxNode* pNode, KFbxScene& fbxScene, const std::string& targ
|
||||
|
||||
for (int k = 0; k < nKeys; ++k)
|
||||
{
|
||||
KFbxAnimCurveKey key = pCurve->KeyGet(k);
|
||||
FbxAnimCurveKey key = pCurve->KeyGet(k);
|
||||
double fTime = key.GetTime().GetSecondDouble();
|
||||
float fValue = static_cast<float>(key.GetValue() * 0.01);
|
||||
keyFrameCntr.push_back(osgAnimation::FloatKeyframe(fTime,fValue));
|
||||
@ -415,7 +415,7 @@ void readAnimation(KFbxNode* pNode, KFbxScene& fbxScene, const std::string& targ
|
||||
|
||||
void addBindMatrix(
|
||||
BindMatrixMap& boneBindMatrices,
|
||||
KFbxNode* pBone,
|
||||
FbxNode* pBone,
|
||||
const osg::Matrix& bindMatrix,
|
||||
osgAnimation::RigGeometry* pRigGeometry)
|
||||
{
|
||||
@ -423,7 +423,7 @@ void addBindMatrix(
|
||||
BindMatrixMap::key_type(pBone, pRigGeometry), bindMatrix));
|
||||
}
|
||||
|
||||
void addVec2ArrayElement(osg::Array& a, const KFbxVector2& v)
|
||||
void addVec2ArrayElement(osg::Array& a, const FbxVector2& v)
|
||||
{
|
||||
if (a.getType() == osg::Array::Vec2dArrayType)
|
||||
{
|
||||
@ -437,7 +437,7 @@ void addVec2ArrayElement(osg::Array& a, const KFbxVector2& v)
|
||||
}
|
||||
}
|
||||
|
||||
void addVec3ArrayElement(osg::Array& a, const KFbxVector4& v)
|
||||
void addVec3ArrayElement(osg::Array& a, const FbxVector4& v)
|
||||
{
|
||||
if (a.getType() == osg::Array::Vec3dArrayType)
|
||||
{
|
||||
@ -452,7 +452,7 @@ void addVec3ArrayElement(osg::Array& a, const KFbxVector4& v)
|
||||
}
|
||||
}
|
||||
|
||||
void addColorArrayElement(osg::Array& a, const KFbxColor& c)
|
||||
void addColorArrayElement(osg::Array& a, const FbxColor& c)
|
||||
{
|
||||
if (a.getType() == osg::Array::Vec4dArrayType)
|
||||
{
|
||||
@ -475,13 +475,13 @@ std::string getUVChannelForTextureMap(std::vector<StateSetContent>& stateSetList
|
||||
// TODO: what if more than one channel for the same map type?
|
||||
for (unsigned int i = 0; i < stateSetList.size(); i++)
|
||||
{
|
||||
if (0 == strcmp(pName, KFbxSurfaceMaterial::sDiffuse))
|
||||
if (0 == strcmp(pName, FbxSurfaceMaterial::sDiffuse))
|
||||
return stateSetList[i].diffuseChannel;
|
||||
if (0 == strcmp(pName, KFbxSurfaceMaterial::sTransparentColor))
|
||||
if (0 == strcmp(pName, FbxSurfaceMaterial::sTransparentColor))
|
||||
return stateSetList[i].opacityChannel;
|
||||
if (0 == strcmp(pName, KFbxSurfaceMaterial::sReflection))
|
||||
if (0 == strcmp(pName, FbxSurfaceMaterial::sReflection))
|
||||
return stateSetList[i].reflectionChannel;
|
||||
if (0 == strcmp(pName, KFbxSurfaceMaterial::sEmissive))
|
||||
if (0 == strcmp(pName, FbxSurfaceMaterial::sEmissive))
|
||||
return stateSetList[i].emissiveChannel;
|
||||
// more here...
|
||||
}
|
||||
@ -490,17 +490,17 @@ std::string getUVChannelForTextureMap(std::vector<StateSetContent>& stateSetList
|
||||
}
|
||||
|
||||
// scans mesh layers looking for the UV element corresponding to the specified channel name...
|
||||
const KFbxLayerElementUV* getUVElementForChannel(std::string uvChannelName,
|
||||
KFbxLayerElement::ELayerElementType elementType, KFbxMesh* pFbxMesh)
|
||||
const FbxLayerElementUV* getUVElementForChannel(std::string uvChannelName,
|
||||
FbxLayerElement::EType elementType, FbxMesh* pFbxMesh)
|
||||
{
|
||||
// scan layers for specified UV channel...
|
||||
for (int cLayerIndex = 0; cLayerIndex < pFbxMesh->GetLayerCount(); cLayerIndex++)
|
||||
{
|
||||
const KFbxLayer* pFbxLayer = pFbxMesh->GetLayer(cLayerIndex);
|
||||
const FbxLayer* pFbxLayer = pFbxMesh->GetLayer(cLayerIndex);
|
||||
if (!pFbxLayer)
|
||||
continue;
|
||||
|
||||
if (const KFbxLayerElementUV* uv = pFbxLayer->GetUVs())
|
||||
if (const FbxLayerElementUV* uv = pFbxLayer->GetUVs())
|
||||
{
|
||||
if (0 == uvChannelName.compare(uv->GetName()))
|
||||
return uv;
|
||||
@ -509,11 +509,11 @@ const KFbxLayerElementUV* getUVElementForChannel(std::string uvChannelName,
|
||||
|
||||
for (int cLayerIndex = 0; cLayerIndex < pFbxMesh->GetLayerCount(); cLayerIndex++)
|
||||
{
|
||||
const KFbxLayer* pFbxLayer = pFbxMesh->GetLayer(cLayerIndex);
|
||||
const FbxLayer* pFbxLayer = pFbxMesh->GetLayer(cLayerIndex);
|
||||
if (!pFbxLayer)
|
||||
continue;
|
||||
|
||||
if (const KFbxLayerElementUV* uv = pFbxLayer->GetUVs(elementType))
|
||||
if (const FbxLayerElementUV* uv = pFbxLayer->GetUVs(elementType))
|
||||
{
|
||||
return uv;
|
||||
}
|
||||
@ -526,17 +526,17 @@ typedef std::pair<osg::Geometry*, int> GIPair;
|
||||
typedef std::multimap<int, GIPair> FbxToOsgVertexMap;
|
||||
typedef std::map<GIPair, int> OsgToFbxNormalMap;
|
||||
|
||||
void readMeshTriangle(const KFbxMesh * fbxMesh, int i /*polygonIndex*/,
|
||||
void readMeshTriangle(const FbxMesh * fbxMesh, int i /*polygonIndex*/,
|
||||
int posInPoly0, int posInPoly1, int posInPoly2,
|
||||
int meshVertex0, int meshVertex1, int meshVertex2,
|
||||
FbxToOsgVertexMap& fbxToOsgVertMap,
|
||||
OsgToFbxNormalMap& osgToFbxNormMap,
|
||||
const KFbxVector4* pFbxVertices,
|
||||
const KFbxLayerElementNormal* pFbxNormals,
|
||||
const KFbxLayerElementUV* pFbxUVs_diffuse,
|
||||
const KFbxLayerElementUV* pFbxUVs_opacity,
|
||||
const KFbxLayerElementUV* pFbxUVs_emissive,
|
||||
const KFbxLayerElementVertexColor* pFbxColors,
|
||||
const FbxVector4* pFbxVertices,
|
||||
const FbxLayerElementNormal* pFbxNormals,
|
||||
const FbxLayerElementUV* pFbxUVs_diffuse,
|
||||
const FbxLayerElementUV* pFbxUVs_opacity,
|
||||
const FbxLayerElementUV* pFbxUVs_emissive,
|
||||
const FbxLayerElementVertexColor* pFbxColors,
|
||||
osg::Geometry* pGeometry,
|
||||
osg::Array* pVertices,
|
||||
osg::Array* pNormals,
|
||||
@ -605,9 +605,9 @@ void readMeshTriangle(const KFbxMesh * fbxMesh, int i /*polygonIndex*/,
|
||||
}
|
||||
|
||||
/// Says if a quad should be split using vertices 02 (or else 13)
|
||||
bool quadSplit02(const KFbxMesh * fbxMesh, int i /*polygonIndex*/,
|
||||
bool quadSplit02(const FbxMesh * fbxMesh, int i /*polygonIndex*/,
|
||||
int posInPoly0, int posInPoly1, int posInPoly2, int posInPoly3,
|
||||
const KFbxVector4* pFbxVertices)
|
||||
const FbxVector4* pFbxVertices)
|
||||
{
|
||||
// Algorithm may be a bit dumb. If you got a faster one, feel free to change.
|
||||
// Here we test each of the 4 triangles and see if there is one in the opposite direction.
|
||||
@ -659,8 +659,8 @@ struct PolygonRef
|
||||
typedef std::vector<PolygonRef> PolygonRefList;
|
||||
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
KFbxNode* pNode,
|
||||
KFbxMesh* fbxMesh,
|
||||
FbxNode* pNode,
|
||||
FbxMesh* fbxMesh,
|
||||
std::vector<StateSetContent>& stateSetList,
|
||||
const char* szName)
|
||||
{
|
||||
@ -669,16 +669,16 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
osg::Geode* pGeode = new osg::Geode;
|
||||
pGeode->setName(szName);
|
||||
|
||||
const KFbxLayerElementNormal* pFbxNormals = 0;
|
||||
const KFbxLayerElementVertexColor* pFbxColors = 0;
|
||||
const KFbxLayerElementMaterial* pFbxMaterials = 0;
|
||||
const FbxLayerElementNormal* pFbxNormals = 0;
|
||||
const FbxLayerElementVertexColor* pFbxColors = 0;
|
||||
const FbxLayerElementMaterial* pFbxMaterials = 0;
|
||||
|
||||
const KFbxVector4* pFbxVertices = fbxMesh->GetControlPoints();
|
||||
const FbxVector4* pFbxVertices = fbxMesh->GetControlPoints();
|
||||
|
||||
// scan layers for Normals, Colors and Materials elements (this will get the first available elements)...
|
||||
for (int cLayerIndex = 0; cLayerIndex < fbxMesh->GetLayerCount(); cLayerIndex++)
|
||||
{
|
||||
const KFbxLayer* pFbxLayer = fbxMesh->GetLayer(cLayerIndex);
|
||||
const FbxLayer* pFbxLayer = fbxMesh->GetLayer(cLayerIndex);
|
||||
if (!pFbxLayer)
|
||||
continue;
|
||||
|
||||
@ -692,15 +692,15 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
}
|
||||
|
||||
// look for UV elements (diffuse, opacity, reflection, emissive, ...) and get their channels names...
|
||||
std::string diffuseChannel = getUVChannelForTextureMap(stateSetList, KFbxSurfaceMaterial::sDiffuse);
|
||||
std::string opacityChannel = getUVChannelForTextureMap(stateSetList, KFbxSurfaceMaterial::sTransparentColor);
|
||||
std::string emissiveChannel = getUVChannelForTextureMap(stateSetList, KFbxSurfaceMaterial::sEmissive);
|
||||
std::string diffuseChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sDiffuse);
|
||||
std::string opacityChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sTransparentColor);
|
||||
std::string emissiveChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sEmissive);
|
||||
// look for more UV elements here...
|
||||
|
||||
// UV elements...
|
||||
const KFbxLayerElementUV* pFbxUVs_diffuse = getUVElementForChannel(diffuseChannel, KFbxLayerElement::eDIFFUSE_TEXTURES, fbxMesh);
|
||||
const KFbxLayerElementUV* pFbxUVs_opacity = getUVElementForChannel(opacityChannel, KFbxLayerElement::eTRANSPARENT_TEXTURES, fbxMesh);
|
||||
const KFbxLayerElementUV* pFbxUVs_emissive = getUVElementForChannel(emissiveChannel, KFbxLayerElement::eEMISSIVE_TEXTURES, fbxMesh);
|
||||
const FbxLayerElementUV* pFbxUVs_diffuse = getUVElementForChannel(diffuseChannel, FbxLayerElement::eTextureDiffuse, fbxMesh);
|
||||
const FbxLayerElementUV* pFbxUVs_opacity = getUVElementForChannel(opacityChannel, FbxLayerElement::eTextureTransparency, fbxMesh);
|
||||
const FbxLayerElementUV* pFbxUVs_emissive = getUVElementForChannel(emissiveChannel, FbxLayerElement::eTextureEmissive, fbxMesh);
|
||||
// more UV elements here...
|
||||
|
||||
// check elements validity...
|
||||
@ -714,8 +714,8 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
|
||||
int nPolys = fbxMesh->GetPolygonCount();
|
||||
|
||||
int nDeformerCount = fbxMesh->GetDeformerCount(KFbxDeformer::eSKIN);
|
||||
int nDeformerBlendShapeCount = fbxMesh->GetDeformerCount(KFbxDeformer::eBLENDSHAPE);
|
||||
int nDeformerCount = fbxMesh->GetDeformerCount(FbxDeformer::eSkin);
|
||||
int nDeformerBlendShapeCount = fbxMesh->GetDeformerCount(FbxDeformer::eBlendShape);
|
||||
|
||||
GeometryType geomType = GEOMETRY_STATIC;
|
||||
|
||||
@ -941,17 +941,17 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
|
||||
for (int i = 0; i < nDeformerCount; ++i)
|
||||
{
|
||||
KFbxSkin* pSkin = (KFbxSkin*)fbxMesh->GetDeformer(i, KFbxDeformer::eSKIN);
|
||||
FbxSkin* pSkin = (FbxSkin*)fbxMesh->GetDeformer(i, FbxDeformer::eSkin);
|
||||
int nClusters = pSkin->GetClusterCount();
|
||||
for (int j = 0; j < nClusters; ++j)
|
||||
{
|
||||
KFbxCluster* pCluster = (KFbxCluster*)pSkin->GetCluster(j);
|
||||
FbxCluster* pCluster = pSkin->GetCluster(j);
|
||||
//assert(KFbxCluster::eNORMALIZE == pCluster->GetLinkMode());
|
||||
KFbxNode* pBone = pCluster->GetLink();
|
||||
FbxNode* pBone = pCluster->GetLink();
|
||||
|
||||
KFbxXMatrix transformLink;
|
||||
FbxAMatrix transformLink;
|
||||
pCluster->GetTransformLinkMatrix(transformLink);
|
||||
KFbxXMatrix transformLinkInverse = transformLink.Inverse();
|
||||
FbxAMatrix transformLinkInverse = transformLink.Inverse();
|
||||
const double* pTransformLinkInverse = transformLinkInverse;
|
||||
osg::Matrix bindMatrix(pTransformLinkInverse);
|
||||
|
||||
@ -998,12 +998,12 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
//read morph geometry
|
||||
for (int nBlendShape = 0; nBlendShape < nDeformerBlendShapeCount; ++nBlendShape)
|
||||
{
|
||||
KFbxBlendShape* pBlendShape = KFbxCast<KFbxBlendShape>(fbxMesh->GetDeformer(nBlendShape, KFbxDeformer::eBLENDSHAPE));
|
||||
FbxBlendShape* pBlendShape = FbxCast<FbxBlendShape>(fbxMesh->GetDeformer(nBlendShape, FbxDeformer::eBlendShape));
|
||||
const int nBlendShapeChannelCount = pBlendShape->GetBlendShapeChannelCount();
|
||||
|
||||
for (int nBlendShapeChannel = 0; nBlendShapeChannel < nBlendShapeChannelCount; ++nBlendShapeChannel)
|
||||
{
|
||||
KFbxBlendShapeChannel* pBlendShapeChannel = pBlendShape->GetBlendShapeChannel(nBlendShapeChannel);
|
||||
FbxBlendShapeChannel* pBlendShapeChannel = pBlendShape->GetBlendShapeChannel(nBlendShapeChannel);
|
||||
if (!pBlendShapeChannel->GetTargetShapeCount()) continue;
|
||||
|
||||
//Assume one shape
|
||||
@ -1011,10 +1011,10 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
{
|
||||
OSG_WARN << "Multiple FBX Target Shapes, only the first will be used" << std::endl;
|
||||
}
|
||||
const KFbxGeometryBase* pMorphShape = pBlendShapeChannel->GetTargetShape(0);
|
||||
const FbxGeometryBase* pMorphShape = pBlendShapeChannel->GetTargetShape(0);
|
||||
|
||||
const KFbxLayerElementNormal* pFbxShapeNormals = 0;
|
||||
if (const KFbxLayer* pFbxShapeLayer = pMorphShape->GetLayer(0))
|
||||
const FbxLayerElementNormal* pFbxShapeNormals = 0;
|
||||
if (const FbxLayer* pFbxShapeLayer = pMorphShape->GetLayer(0))
|
||||
{
|
||||
pFbxShapeNormals = pFbxShapeLayer->GetNormals();
|
||||
if (!layerElementValid(pFbxShapeNormals)) pFbxShapeNormals = 0;
|
||||
@ -1043,25 +1043,25 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
int nMorphTarget = 0;
|
||||
for (int nBlendShape = 0; nBlendShape < nDeformerBlendShapeCount; ++nBlendShape)
|
||||
{
|
||||
KFbxBlendShape* pBlendShape = KFbxCast<KFbxBlendShape>(fbxMesh->GetDeformer(nBlendShape, KFbxDeformer::eBLENDSHAPE));
|
||||
FbxBlendShape* pBlendShape = FbxCast<FbxBlendShape>(fbxMesh->GetDeformer(nBlendShape, FbxDeformer::eBlendShape));
|
||||
const int nBlendShapeChannelCount = pBlendShape->GetBlendShapeChannelCount();
|
||||
|
||||
for (int nBlendShapeChannel = 0; nBlendShapeChannel < nBlendShapeChannelCount; ++nBlendShapeChannel)
|
||||
{
|
||||
KFbxBlendShapeChannel* pBlendShapeChannel = pBlendShape->GetBlendShapeChannel(nBlendShapeChannel);
|
||||
FbxBlendShapeChannel* pBlendShapeChannel = pBlendShape->GetBlendShapeChannel(nBlendShapeChannel);
|
||||
if (!pBlendShapeChannel->GetTargetShapeCount()) continue;
|
||||
|
||||
//Assume one shape again
|
||||
const KFbxGeometryBase* pMorphShape = pBlendShapeChannel->GetTargetShape(0);
|
||||
const FbxGeometryBase* pMorphShape = pBlendShapeChannel->GetTargetShape(0);
|
||||
|
||||
const KFbxLayerElementNormal* pFbxShapeNormals = 0;
|
||||
if (const KFbxLayer* pFbxShapeLayer = pMorphShape->GetLayer(0))
|
||||
const FbxLayerElementNormal* pFbxShapeNormals = 0;
|
||||
if (const FbxLayer* pFbxShapeLayer = pMorphShape->GetLayer(0))
|
||||
{
|
||||
pFbxShapeNormals = pFbxShapeLayer->GetNormals();
|
||||
if (!layerElementValid(pFbxShapeNormals)) pFbxShapeNormals = 0;
|
||||
}
|
||||
|
||||
const KFbxVector4* pControlPoints = pMorphShape->GetControlPoints();
|
||||
const FbxVector4* pControlPoints = pMorphShape->GetControlPoints();
|
||||
int nControlPoints = pMorphShape->GetControlPointsCount();
|
||||
for (int fbxIndex = 0; fbxIndex < nControlPoints; ++fbxIndex)
|
||||
{
|
||||
@ -1111,7 +1111,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
}
|
||||
}
|
||||
|
||||
KFbxXMatrix fbxGeometricTransform;
|
||||
FbxAMatrix fbxGeometricTransform;
|
||||
fbxGeometricTransform.SetTRS(
|
||||
pNode->GeometricTranslation.Get(),
|
||||
pNode->GeometricRotation.Get(),
|
||||
@ -1121,10 +1121,10 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
|
||||
if (geomType == GEOMETRY_RIG)
|
||||
{
|
||||
KFbxSkin* pSkin = (KFbxSkin*)fbxMesh->GetDeformer(0, KFbxDeformer::eSKIN);
|
||||
FbxSkin* pSkin = (FbxSkin*)fbxMesh->GetDeformer(0, FbxDeformer::eSkin);
|
||||
if (pSkin->GetClusterCount())
|
||||
{
|
||||
KFbxXMatrix fbxTransformMatrix;
|
||||
FbxAMatrix fbxTransformMatrix;
|
||||
pSkin->GetCluster(0)->GetTransformMatrix(fbxTransformMatrix);
|
||||
const double* pTransformMatrix = fbxTransformMatrix;
|
||||
osgGeometricTransform.postMult(osg::Matrix(pTransformMatrix));
|
||||
@ -1143,7 +1143,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
if (geomType == GEOMETRY_RIG)
|
||||
{
|
||||
//Add the geometry to the skeleton ancestor of one of the bones.
|
||||
KFbxSkin* pSkin = (KFbxSkin*)fbxMesh->GetDeformer(0, KFbxDeformer::eSKIN);
|
||||
FbxSkin* pSkin = (FbxSkin*)fbxMesh->GetDeformer(0, FbxDeformer::eSkin);
|
||||
if (pSkin->GetClusterCount())
|
||||
{
|
||||
osgAnimation::Skeleton* pSkeleton = getSkeleton(
|
||||
@ -1156,10 +1156,10 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh(
|
||||
return osgDB::ReaderWriter::ReadResult(pResult);
|
||||
}
|
||||
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxMesh(KFbxNode* pNode,
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxMesh(FbxNode* pNode,
|
||||
std::vector<StateSetContent>& stateSetList)
|
||||
{
|
||||
KFbxMesh* lMesh = KFbxCast<KFbxMesh>(pNode->GetNodeAttribute());
|
||||
FbxMesh* lMesh = FbxCast<FbxMesh>(pNode->GetNodeAttribute());
|
||||
|
||||
if (!lMesh)
|
||||
{
|
||||
|
@ -29,16 +29,16 @@
|
||||
|
||||
#include "fbxReader.h"
|
||||
|
||||
bool isAnimated(KFbxProperty& prop, KFbxScene& fbxScene)
|
||||
bool isAnimated(FbxProperty& prop, FbxScene& fbxScene)
|
||||
{
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i)
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount<FbxAnimStack>(); ++i)
|
||||
{
|
||||
KFbxAnimStack* pAnimStack = KFbxCast<KFbxAnimStack>(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i));
|
||||
FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(fbxScene.GetSrcObject<FbxAnimStack>(i));
|
||||
|
||||
const int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer));
|
||||
const int nbAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
|
||||
for (int j = 0; j < nbAnimLayers; j++)
|
||||
{
|
||||
KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j);
|
||||
FbxAnimLayer* pAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(j);
|
||||
if (prop.GetCurveNode(pAnimLayer, false))
|
||||
{
|
||||
return true;
|
||||
@ -48,17 +48,17 @@ bool isAnimated(KFbxProperty& prop, KFbxScene& fbxScene)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isAnimated(KFbxProperty& prop, const char* channel, KFbxScene& fbxScene)
|
||||
bool isAnimated(FbxProperty& prop, const char* channel, FbxScene& fbxScene)
|
||||
{
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount(FBX_TYPE(KFbxAnimStack)); ++i)
|
||||
for (int i = 0; i < fbxScene.GetSrcObjectCount<FbxAnimStack>(); ++i)
|
||||
{
|
||||
KFbxAnimStack* pAnimStack = KFbxCast<KFbxAnimStack>(fbxScene.GetSrcObject(FBX_TYPE(KFbxAnimStack), i));
|
||||
FbxAnimStack* pAnimStack = FbxCast<FbxAnimStack>(fbxScene.GetSrcObject<FbxAnimStack>(i));
|
||||
|
||||
const int nbAnimLayers = pAnimStack->GetMemberCount(FBX_TYPE(KFbxAnimLayer));
|
||||
const int nbAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
|
||||
for (int j = 0; j < nbAnimLayers; j++)
|
||||
{
|
||||
KFbxAnimLayer* pAnimLayer = pAnimStack->GetMember(FBX_TYPE(KFbxAnimLayer), j);
|
||||
if (prop.GetCurve<KFbxAnimCurve>(pAnimLayer, channel, false))
|
||||
FbxAnimLayer* pAnimLayer = pAnimStack->GetMember<FbxAnimLayer>(j);
|
||||
if (prop.GetCurve(pAnimLayer, channel, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -67,7 +67,7 @@ bool isAnimated(KFbxProperty& prop, const char* channel, KFbxScene& fbxScene)
|
||||
return false;
|
||||
}
|
||||
|
||||
osg::Quat makeQuat(const fbxDouble3& degrees, ERotationOrder fbxRotOrder)
|
||||
osg::Quat makeQuat(const FbxDouble3& degrees, EFbxRotationOrder fbxRotOrder)
|
||||
{
|
||||
double radiansX = osg::DegreesToRadians(degrees[0]);
|
||||
double radiansY = osg::DegreesToRadians(degrees[1]);
|
||||
@ -75,37 +75,37 @@ osg::Quat makeQuat(const fbxDouble3& degrees, ERotationOrder fbxRotOrder)
|
||||
|
||||
switch (fbxRotOrder)
|
||||
{
|
||||
case eEULER_XYZ:
|
||||
case eEulerXYZ:
|
||||
return osg::Quat(
|
||||
radiansX, osg::Vec3d(1,0,0),
|
||||
radiansY, osg::Vec3d(0,1,0),
|
||||
radiansZ, osg::Vec3d(0,0,1));
|
||||
case eEULER_XZY:
|
||||
case eEulerXZY:
|
||||
return osg::Quat(
|
||||
radiansX, osg::Vec3d(1,0,0),
|
||||
radiansZ, osg::Vec3d(0,0,1),
|
||||
radiansY, osg::Vec3d(0,1,0));
|
||||
case eEULER_YZX:
|
||||
case eEulerYZX:
|
||||
return osg::Quat(
|
||||
radiansY, osg::Vec3d(0,1,0),
|
||||
radiansZ, osg::Vec3d(0,0,1),
|
||||
radiansX, osg::Vec3d(1,0,0));
|
||||
case eEULER_YXZ:
|
||||
case eEulerYXZ:
|
||||
return osg::Quat(
|
||||
radiansY, osg::Vec3d(0,1,0),
|
||||
radiansX, osg::Vec3d(1,0,0),
|
||||
radiansZ, osg::Vec3d(0,0,1));
|
||||
case eEULER_ZXY:
|
||||
case eEulerZXY:
|
||||
return osg::Quat(
|
||||
radiansZ, osg::Vec3d(0,0,1),
|
||||
radiansX, osg::Vec3d(1,0,0),
|
||||
radiansY, osg::Vec3d(0,1,0));
|
||||
case eEULER_ZYX:
|
||||
case eEulerZYX:
|
||||
return osg::Quat(
|
||||
radiansZ, osg::Vec3d(0,0,1),
|
||||
radiansY, osg::Vec3d(0,1,0),
|
||||
radiansX, osg::Vec3d(1,0,0));
|
||||
case eSPHERIC_XYZ:
|
||||
case eSphericXYZ:
|
||||
{
|
||||
//I don't know what eSPHERIC_XYZ means, so this is a complete guess.
|
||||
osg::Quat quat;
|
||||
@ -118,7 +118,7 @@ osg::Quat makeQuat(const fbxDouble3& degrees, ERotationOrder fbxRotOrder)
|
||||
}
|
||||
}
|
||||
|
||||
void makeLocalMatrix(const KFbxNode* pNode, osg::Matrix& m)
|
||||
void makeLocalMatrix(const FbxNode* pNode, osg::Matrix& m)
|
||||
{
|
||||
/*From http://area.autodesk.com/forum/autodesk-fbx/fbx-sdk/the-makeup-of-the-local-matrix-of-an-kfbxnode/
|
||||
|
||||
@ -143,17 +143,17 @@ void makeLocalMatrix(const KFbxNode* pNode, osg::Matrix& m)
|
||||
// values and the rotation limits should be ignored.
|
||||
bool rotationActive = pNode->RotationActive.Get();
|
||||
|
||||
ERotationOrder fbxRotOrder = rotationActive ? pNode->RotationOrder.Get() : eEULER_XYZ;
|
||||
EFbxRotationOrder fbxRotOrder = rotationActive ? pNode->RotationOrder.Get() : eEulerXYZ;
|
||||
|
||||
fbxDouble3 fbxLclPos = pNode->LclTranslation.Get();
|
||||
fbxDouble3 fbxRotOff = pNode->RotationOffset.Get();
|
||||
fbxDouble3 fbxRotPiv = pNode->RotationPivot.Get();
|
||||
fbxDouble3 fbxPreRot = pNode->PreRotation.Get();
|
||||
fbxDouble3 fbxLclRot = pNode->LclRotation.Get();
|
||||
fbxDouble3 fbxPostRot = pNode->PostRotation.Get();
|
||||
fbxDouble3 fbxSclOff = pNode->ScalingOffset.Get();
|
||||
fbxDouble3 fbxSclPiv = pNode->ScalingPivot.Get();
|
||||
fbxDouble3 fbxLclScl = pNode->LclScaling.Get();
|
||||
FbxDouble3 fbxLclPos = pNode->LclTranslation.Get();
|
||||
FbxDouble3 fbxRotOff = pNode->RotationOffset.Get();
|
||||
FbxDouble3 fbxRotPiv = pNode->RotationPivot.Get();
|
||||
FbxDouble3 fbxPreRot = pNode->PreRotation.Get();
|
||||
FbxDouble3 fbxLclRot = pNode->LclRotation.Get();
|
||||
FbxDouble3 fbxPostRot = pNode->PostRotation.Get();
|
||||
FbxDouble3 fbxSclOff = pNode->ScalingOffset.Get();
|
||||
FbxDouble3 fbxSclPiv = pNode->ScalingPivot.Get();
|
||||
FbxDouble3 fbxLclScl = pNode->LclScaling.Get();
|
||||
|
||||
m.makeTranslate(osg::Vec3d(
|
||||
fbxLclPos[0] + fbxRotOff[0] + fbxRotPiv[0],
|
||||
@ -181,12 +181,12 @@ void makeLocalMatrix(const KFbxNode* pNode, osg::Matrix& m)
|
||||
-fbxSclPiv[2]));
|
||||
}
|
||||
|
||||
void readTranslationElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
void readTranslationElement(FbxPropertyT<FbxDouble3>& prop,
|
||||
osgAnimation::UpdateMatrixTransform* pUpdate,
|
||||
osg::Matrix& staticTransform,
|
||||
KFbxScene& fbxScene)
|
||||
FbxScene& fbxScene)
|
||||
{
|
||||
fbxDouble3 fbxPropValue = prop.Get();
|
||||
FbxDouble3 fbxPropValue = prop.Get();
|
||||
osg::Vec3d val(
|
||||
fbxPropValue[0],
|
||||
fbxPropValue[1],
|
||||
@ -207,23 +207,23 @@ void readTranslationElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
}
|
||||
}
|
||||
|
||||
void getRotationOrder(ERotationOrder fbxRotOrder, int order[/*3*/])
|
||||
void getRotationOrder(EFbxRotationOrder fbxRotOrder, int order[/*3*/])
|
||||
{
|
||||
switch (fbxRotOrder)
|
||||
{
|
||||
case eEULER_XZY:
|
||||
case eEulerXZY:
|
||||
order[0] = 0; order[1] = 2; order[2] = 1;
|
||||
break;
|
||||
case eEULER_YZX:
|
||||
case eEulerYZX:
|
||||
order[0] = 1; order[1] = 2; order[2] = 0;
|
||||
break;
|
||||
case eEULER_YXZ:
|
||||
case eEulerYXZ:
|
||||
order[0] = 1; order[1] = 0; order[2] = 2;
|
||||
break;
|
||||
case eEULER_ZXY:
|
||||
case eEulerZXY:
|
||||
order[0] = 2; order[1] = 0; order[2] = 1;
|
||||
break;
|
||||
case eEULER_ZYX:
|
||||
case eEulerZYX:
|
||||
order[0] = 2; order[1] = 1; order[2] = 0;
|
||||
break;
|
||||
default:
|
||||
@ -231,12 +231,12 @@ void getRotationOrder(ERotationOrder fbxRotOrder, int order[/*3*/])
|
||||
}
|
||||
}
|
||||
|
||||
void readRotationElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
ERotationOrder fbxRotOrder,
|
||||
void readRotationElement(FbxPropertyT<FbxDouble3>& prop,
|
||||
EFbxRotationOrder fbxRotOrder,
|
||||
bool quatInterpolate,
|
||||
osgAnimation::UpdateMatrixTransform* pUpdate,
|
||||
osg::Matrix& staticTransform,
|
||||
KFbxScene& fbxScene)
|
||||
FbxScene& fbxScene)
|
||||
{
|
||||
if (isAnimated(prop, fbxScene))
|
||||
{
|
||||
@ -253,10 +253,10 @@ void readRotationElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* curveNames[3] = {KFCURVENODE_R_X, KFCURVENODE_R_Y, KFCURVENODE_R_Z};
|
||||
const char* curveNames[3] = {FBXSDK_CURVENODE_COMPONENT_X, FBXSDK_CURVENODE_COMPONENT_Y, FBXSDK_CURVENODE_COMPONENT_Z};
|
||||
osg::Vec3 axes[3] = {osg::Vec3(1,0,0), osg::Vec3(0,1,0), osg::Vec3(0,0,1)};
|
||||
|
||||
fbxDouble3 fbxPropValue = prop.Get();
|
||||
FbxDouble3 fbxPropValue = prop.Get();
|
||||
fbxPropValue[0] = osg::DegreesToRadians(fbxPropValue[0]);
|
||||
fbxPropValue[1] = osg::DegreesToRadians(fbxPropValue[1]);
|
||||
fbxPropValue[2] = osg::DegreesToRadians(fbxPropValue[2]);
|
||||
@ -291,12 +291,12 @@ void readRotationElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
}
|
||||
}
|
||||
|
||||
void readScaleElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
void readScaleElement(FbxPropertyT<FbxDouble3>& prop,
|
||||
osgAnimation::UpdateMatrixTransform* pUpdate,
|
||||
osg::Matrix& staticTransform,
|
||||
KFbxScene& fbxScene)
|
||||
FbxScene& fbxScene)
|
||||
{
|
||||
fbxDouble3 fbxPropValue = prop.Get();
|
||||
FbxDouble3 fbxPropValue = prop.Get();
|
||||
osg::Vec3d val(
|
||||
fbxPropValue[0],
|
||||
fbxPropValue[1],
|
||||
@ -317,14 +317,14 @@ void readScaleElement(KFbxTypedProperty<fbxDouble3>& prop,
|
||||
}
|
||||
}
|
||||
|
||||
void readUpdateMatrixTransform(osgAnimation::UpdateMatrixTransform* pUpdate, KFbxNode* pNode, KFbxScene& fbxScene)
|
||||
void readUpdateMatrixTransform(osgAnimation::UpdateMatrixTransform* pUpdate, FbxNode* pNode, FbxScene& fbxScene)
|
||||
{
|
||||
osg::Matrix staticTransform;
|
||||
|
||||
readTranslationElement(pNode->LclTranslation, pUpdate, staticTransform, fbxScene);
|
||||
|
||||
fbxDouble3 fbxRotOffset = pNode->RotationOffset.Get();
|
||||
fbxDouble3 fbxRotPiv = pNode->RotationPivot.Get();
|
||||
FbxDouble3 fbxRotOffset = pNode->RotationOffset.Get();
|
||||
FbxDouble3 fbxRotPiv = pNode->RotationPivot.Get();
|
||||
staticTransform.preMultTranslate(osg::Vec3d(
|
||||
fbxRotPiv[0] + fbxRotOffset[0],
|
||||
fbxRotPiv[1] + fbxRotOffset[1],
|
||||
@ -334,8 +334,8 @@ void readUpdateMatrixTransform(osgAnimation::UpdateMatrixTransform* pUpdate, KFb
|
||||
// values and the rotation limits should be ignored.
|
||||
bool rotationActive = pNode->RotationActive.Get();
|
||||
|
||||
ERotationOrder fbxRotOrder = (rotationActive && pNode->RotationOrder.IsValid()) ?
|
||||
pNode->RotationOrder.Get() : eEULER_XYZ;
|
||||
EFbxRotationOrder fbxRotOrder = (rotationActive && pNode->RotationOrder.IsValid()) ?
|
||||
pNode->RotationOrder.Get() : eEulerXYZ;
|
||||
|
||||
if (rotationActive)
|
||||
{
|
||||
@ -351,8 +351,8 @@ void readUpdateMatrixTransform(osgAnimation::UpdateMatrixTransform* pUpdate, KFb
|
||||
staticTransform.preMultRotate(makeQuat(pNode->PostRotation.Get(), fbxRotOrder));
|
||||
}
|
||||
|
||||
fbxDouble3 fbxSclOffset = pNode->ScalingOffset.Get();
|
||||
fbxDouble3 fbxSclPiv = pNode->ScalingPivot.Get();
|
||||
FbxDouble3 fbxSclOffset = pNode->ScalingOffset.Get();
|
||||
FbxDouble3 fbxSclPiv = pNode->ScalingPivot.Get();
|
||||
staticTransform.preMultTranslate(osg::Vec3d(
|
||||
fbxSclOffset[0] + fbxSclPiv[0] - fbxRotPiv[0],
|
||||
fbxSclOffset[1] + fbxSclPiv[1] - fbxRotPiv[1],
|
||||
@ -371,9 +371,9 @@ void readUpdateMatrixTransform(osgAnimation::UpdateMatrixTransform* pUpdate, KFb
|
||||
}
|
||||
}
|
||||
|
||||
osg::Group* createGroupNode(KFbxSdkManager& pSdkManager, KFbxNode* pNode,
|
||||
osg::Group* createGroupNode(FbxManager& pSdkManager, FbxNode* pNode,
|
||||
const std::string& animName, const osg::Matrix& localMatrix, bool bNeedSkeleton,
|
||||
std::map<KFbxNode*, osg::Node*>& nodeMap, KFbxScene& fbxScene)
|
||||
std::map<FbxNode*, osg::Node*>& nodeMap, FbxScene& fbxScene)
|
||||
{
|
||||
if (bNeedSkeleton)
|
||||
{
|
||||
@ -384,7 +384,7 @@ osg::Group* createGroupNode(KFbxSdkManager& pSdkManager, KFbxNode* pNode,
|
||||
readUpdateMatrixTransform(pUpdate, pNode, fbxScene);
|
||||
osgBone->setUpdateCallback(pUpdate);
|
||||
|
||||
nodeMap.insert(std::pair<KFbxNode*, osg::Node*>(pNode, osgBone));
|
||||
nodeMap.insert(std::pair<FbxNode*, osg::Node*>(pNode, osgBone));
|
||||
|
||||
return osgBone;
|
||||
}
|
||||
@ -413,21 +413,25 @@ osg::Group* createGroupNode(KFbxSdkManager& pSdkManager, KFbxNode* pNode,
|
||||
}
|
||||
|
||||
osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
KFbxNode* pNode,
|
||||
FbxNode* pNode,
|
||||
bool& bIsBone, int& nLightCount)
|
||||
{
|
||||
if (KFbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute())
|
||||
if (FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute())
|
||||
{
|
||||
KFbxNodeAttribute::EAttributeType attrType = lNodeAttribute->GetAttributeType();
|
||||
FbxNodeAttribute::EType attrType = lNodeAttribute->GetAttributeType();
|
||||
switch (attrType)
|
||||
{
|
||||
case KFbxNodeAttribute::eNURB:
|
||||
case KFbxNodeAttribute::ePATCH:
|
||||
case KFbxNodeAttribute::eNURBS_CURVE:
|
||||
case KFbxNodeAttribute::eNURBS_SURFACE:
|
||||
case FbxNodeAttribute::eNurbs:
|
||||
case FbxNodeAttribute::ePatch:
|
||||
case FbxNodeAttribute::eNurbsCurve:
|
||||
case FbxNodeAttribute::eNurbsSurface:
|
||||
{
|
||||
KFbxGeometryConverter lConverter(&pSdkManager);
|
||||
FbxGeometryConverter lConverter(&pSdkManager);
|
||||
#if FBXSDK_VERSION_MAJOR < 2014
|
||||
if (!lConverter.TriangulateInPlace(pNode))
|
||||
#else
|
||||
if (!lConverter.Triangulate(lNodeAttribute,true,false))
|
||||
#endif
|
||||
{
|
||||
OSG_WARN << "Unable to triangulate FBX NURBS " << pNode->GetName() << std::endl;
|
||||
}
|
||||
@ -441,11 +445,11 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
bIsBone = false;
|
||||
bool bCreateSkeleton = false;
|
||||
|
||||
KFbxNodeAttribute::EAttributeType lAttributeType = KFbxNodeAttribute::eUNIDENTIFIED;
|
||||
FbxNodeAttribute::EType lAttributeType = FbxNodeAttribute::eUnknown;
|
||||
if (pNode->GetNodeAttribute())
|
||||
{
|
||||
lAttributeType = pNode->GetNodeAttribute()->GetAttributeType();
|
||||
if (lAttributeType == KFbxNodeAttribute::eSKELETON)
|
||||
if (lAttributeType == FbxNodeAttribute::eSkeleton)
|
||||
{
|
||||
bIsBone = true;
|
||||
}
|
||||
@ -461,7 +465,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
|
||||
for (unsigned i = 0; i < nMaterials; ++i)
|
||||
{
|
||||
KFbxSurfaceMaterial* fbxMaterial = pNode->GetMaterial(i);
|
||||
FbxSurfaceMaterial* fbxMaterial = pNode->GetMaterial(i);
|
||||
assert(fbxMaterial);
|
||||
stateSetList.push_back(fbxMaterialToOsgStateSet.convert(fbxMaterial));
|
||||
}
|
||||
@ -471,7 +475,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
int nChildCount = pNode->GetChildCount();
|
||||
for (int i = 0; i < nChildCount; ++i)
|
||||
{
|
||||
KFbxNode* pChildNode = pNode->GetChild(i);
|
||||
FbxNode* pChildNode = pNode->GetChild(i);
|
||||
|
||||
if (pChildNode->GetParent() != pNode)
|
||||
{
|
||||
@ -512,7 +516,7 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
|
||||
switch (lAttributeType)
|
||||
{
|
||||
case KFbxNodeAttribute::eMESH:
|
||||
case FbxNodeAttribute::eMesh:
|
||||
{
|
||||
size_t bindMatrixCount = boneBindMatrices.size();
|
||||
osgDB::ReaderWriter::ReadResult meshRes = readFbxMesh(pNode, stateSetList);
|
||||
@ -543,11 +547,11 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KFbxNodeAttribute::eCAMERA:
|
||||
case KFbxNodeAttribute::eLIGHT:
|
||||
case FbxNodeAttribute::eCamera:
|
||||
case FbxNodeAttribute::eLight:
|
||||
{
|
||||
osgDB::ReaderWriter::ReadResult res =
|
||||
lAttributeType == KFbxNodeAttribute::eCAMERA ?
|
||||
lAttributeType == FbxNodeAttribute::eCamera ?
|
||||
readFbxCamera(pNode) : readFbxLight(pNode, nLightCount);
|
||||
if (res.error())
|
||||
{
|
||||
@ -601,25 +605,25 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readFbxNode(
|
||||
return osgDB::ReaderWriter::ReadResult(osgGroup.get());
|
||||
}
|
||||
|
||||
osgAnimation::Skeleton* getSkeleton(KFbxNode* fbxNode,
|
||||
const std::set<const KFbxNode*>& fbxSkeletons,
|
||||
std::map<KFbxNode*, osgAnimation::Skeleton*>& skeletonMap)
|
||||
osgAnimation::Skeleton* getSkeleton(FbxNode* fbxNode,
|
||||
const std::set<const FbxNode*>& fbxSkeletons,
|
||||
std::map<FbxNode*, osgAnimation::Skeleton*>& skeletonMap)
|
||||
{
|
||||
//Find the first non-skeleton ancestor of the node.
|
||||
while (fbxNode &&
|
||||
((fbxNode->GetNodeAttribute() &&
|
||||
fbxNode->GetNodeAttribute()->GetAttributeType() == KFbxNodeAttribute::eSKELETON) ||
|
||||
fbxNode->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eSkeleton) ||
|
||||
fbxSkeletons.find(fbxNode) != fbxSkeletons.end()))
|
||||
{
|
||||
fbxNode = fbxNode->GetParent();
|
||||
}
|
||||
|
||||
std::map<KFbxNode*, osgAnimation::Skeleton*>::const_iterator it = skeletonMap.find(fbxNode);
|
||||
std::map<FbxNode*, osgAnimation::Skeleton*>::const_iterator it = skeletonMap.find(fbxNode);
|
||||
if (it == skeletonMap.end())
|
||||
{
|
||||
osgAnimation::Skeleton* skel = new osgAnimation::Skeleton;
|
||||
skel->setDefaultUpdateCallback();
|
||||
skeletonMap.insert(std::pair<KFbxNode*, osgAnimation::Skeleton*>(fbxNode, skel));
|
||||
skeletonMap.insert(std::pair<FbxNode*, osgAnimation::Skeleton*>(fbxNode, skel));
|
||||
return skel;
|
||||
}
|
||||
else
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FBXRANIMATION_H
|
||||
#define FBXRANIMATION_H
|
||||
|
||||
#include <fbxfilesdk/fbxfilesdk_def.h>
|
||||
#include <fbxsdk.h>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include "fbxMaterialToOsgStateSet.h"
|
||||
@ -13,19 +13,19 @@ namespace osgAnimation
|
||||
class Skeleton;
|
||||
}
|
||||
|
||||
typedef std::map<std::pair<KFbxNode*, osgAnimation::RigGeometry*>, osg::Matrix> BindMatrixMap;
|
||||
typedef std::map<std::pair<FbxNode*, osgAnimation::RigGeometry*>, osg::Matrix> BindMatrixMap;
|
||||
|
||||
class OsgFbxReader
|
||||
{
|
||||
public:
|
||||
KFbxSdkManager& pSdkManager;
|
||||
KFbxScene& fbxScene;
|
||||
FbxManager& pSdkManager;
|
||||
FbxScene& fbxScene;
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerBase> pAnimationManager;
|
||||
FbxMaterialToOsgStateSet& fbxMaterialToOsgStateSet;
|
||||
std::map<KFbxNode*, osg::Node*> nodeMap;
|
||||
std::map<FbxNode*, osg::Node*> nodeMap;
|
||||
BindMatrixMap boneBindMatrices;
|
||||
const std::set<const KFbxNode*>& fbxSkeletons;
|
||||
std::map<KFbxNode*, osgAnimation::Skeleton*> skeletonMap;
|
||||
const std::set<const FbxNode*>& fbxSkeletons;
|
||||
std::map<FbxNode*, osgAnimation::Skeleton*> skeletonMap;
|
||||
const osgDB::Options& options;
|
||||
bool lightmapTextures, tessellatePolygons;
|
||||
|
||||
@ -37,10 +37,10 @@ public:
|
||||
} authoringTool;
|
||||
|
||||
OsgFbxReader(
|
||||
KFbxSdkManager& pSdkManager1,
|
||||
KFbxScene& fbxScene1,
|
||||
FbxManager& pSdkManager1,
|
||||
FbxScene& fbxScene1,
|
||||
FbxMaterialToOsgStateSet& fbxMaterialToOsgStateSet1,
|
||||
const std::set<const KFbxNode*>& fbxSkeletons1,
|
||||
const std::set<const FbxNode*>& fbxSkeletons1,
|
||||
const osgDB::Options& options1,
|
||||
AuthoringTool authoringTool1,
|
||||
bool lightmapTextures1,
|
||||
@ -56,29 +56,29 @@ public:
|
||||
{}
|
||||
|
||||
osgDB::ReaderWriter::ReadResult readFbxNode(
|
||||
KFbxNode*, bool& bIsBone, int& nLightCount);
|
||||
FbxNode*, bool& bIsBone, int& nLightCount);
|
||||
|
||||
std::string readFbxAnimation(
|
||||
KFbxNode*, const char* targetName);
|
||||
FbxNode*, const char* targetName);
|
||||
|
||||
osgDB::ReaderWriter::ReadResult readFbxCamera(
|
||||
KFbxNode* pNode);
|
||||
FbxNode* pNode);
|
||||
|
||||
osgDB::ReaderWriter::ReadResult readFbxLight(
|
||||
KFbxNode* pNode, int& nLightCount);
|
||||
FbxNode* pNode, int& nLightCount);
|
||||
|
||||
osgDB::ReaderWriter::ReadResult readMesh(
|
||||
KFbxNode* pNode, KFbxMesh* fbxMesh,
|
||||
FbxNode* pNode, FbxMesh* fbxMesh,
|
||||
std::vector<StateSetContent>& stateSetList,
|
||||
const char* szName);
|
||||
|
||||
osgDB::ReaderWriter::ReadResult readFbxMesh(
|
||||
KFbxNode* pNode,
|
||||
FbxNode* pNode,
|
||||
std::vector<StateSetContent>&);
|
||||
};
|
||||
|
||||
osgAnimation::Skeleton* getSkeleton(KFbxNode*,
|
||||
const std::set<const KFbxNode*>& fbxSkeletons,
|
||||
std::map<KFbxNode*, osgAnimation::Skeleton*>&);
|
||||
osgAnimation::Skeleton* getSkeleton(FbxNode*,
|
||||
const std::set<const FbxNode*>& fbxSkeletons,
|
||||
std::map<FbxNode*, osgAnimation::Skeleton*>&);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user