#include "../Common/Common.h"
#ifdef IOS_REF
#undef IOS_REF
#define IOS_REF (*(pSdkManager->GetIOSettings()))
#endif
void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene)
{
pSdkManager = FbxManager::Create();
if( !pSdkManager )
{
FBXSDK_printf("Unable to create the FBX SDK manager\n");
exit(0);
}
else
{
FBXSDK_printf("FBX SDK version %s\n\n", pSdkManager->GetVersion());
}
FbxIOSettings * ios = FbxIOSettings::Create(pSdkManager, IOSROOT );
pSdkManager->SetIOSettings(ios);
FbxString lPath = FbxGetApplicationDirectory();
pSdkManager->LoadPluginsDirectory(lPath.Buffer());
pScene = FbxScene::Create(pSdkManager,"");
}
void DestroySdkObjects(FbxManager* pSdkManager)
{
if (pSdkManager) pSdkManager->Destroy();
pSdkManager = NULL;
}
bool SaveScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename, int pFileFormat, bool pEmbedMedia)
{
int lMajor, lMinor, lRevision;
bool lStatus = true;
FbxExporter* lExporter = FbxExporter::Create(pSdkManager, "");
if( pFileFormat < 0 || pFileFormat >= pSdkManager->GetIOPluginRegistry()->GetWriterFormatCount() )
{
pFileFormat = pSdkManager->GetIOPluginRegistry()->GetNativeWriterFormat();
int lFormatIndex, lFormatCount = pSdkManager->GetIOPluginRegistry()->GetWriterFormatCount();
for (lFormatIndex=0; lFormatIndex<lFormatCount; lFormatIndex++)
{
if (pSdkManager->GetIOPluginRegistry()->WriterIsFBX(lFormatIndex))
{
FbxString lDesc =pSdkManager->GetIOPluginRegistry()->GetWriterFormatDescription(lFormatIndex);
char *lASCII = "ascii";
if (lDesc.Find(lASCII)>=0)
{
pFileFormat = lFormatIndex;
break;
}
}
}
}
IOS_REF.SetBoolProp(EXP_FBX_MATERIAL, true);
IOS_REF.SetBoolProp(EXP_FBX_TEXTURE, true);
IOS_REF.SetBoolProp(EXP_FBX_EMBEDDED, pEmbedMedia);
IOS_REF.SetBoolProp(EXP_FBX_SHAPE, true);
IOS_REF.SetBoolProp(EXP_FBX_GOBO, true);
IOS_REF.SetBoolProp(EXP_FBX_ANIMATION, true);
IOS_REF.SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true);
if(lExporter->Initialize(pFilename, pFileFormat, pSdkManager->GetIOSettings()) == false)
{
FBXSDK_printf("Call to FbxExporter::Initialize() failed.\n");
FBXSDK_printf("Error returned: %s\n\n", lExporter->GetLastErrorString());
return false;
}
FbxManager::GetFileFormatVersion(lMajor, lMinor, lRevision);
FBXSDK_printf("FBX version number for this version of the FBX SDK is %d.%d.%d\n\n", lMajor, lMinor, lRevision);
lStatus = lExporter->Export(pScene);
lExporter->Destroy();
return lStatus;
}
bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename)
{
int lFileMajor, lFileMinor, lFileRevision;
int lSDKMajor, lSDKMinor, lSDKRevision;
int i, lAnimStackCount;
bool lStatus;
char lPassword[1024];
FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision);
FbxImporter* lImporter = FbxImporter::Create(pSdkManager,"");
const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings());
lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);
if( !lImportStatus )
{
FBXSDK_printf("Call to FbxImporter::Initialize() failed.\n");
FBXSDK_printf("Error returned: %s\n\n", lImporter->GetLastErrorString());
if (lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedYet ||
lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedAnymore)
{
FBXSDK_printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
FBXSDK_printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision);
}
return false;
}
FBXSDK_printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
if (lImporter->IsFBX())
{
FBXSDK_printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision);
FBXSDK_printf("Animation Stack Information\n");
lAnimStackCount = lImporter->GetAnimStackCount();
FBXSDK_printf(" Number of Animation Stacks: %d\n", lAnimStackCount);
FBXSDK_printf(" Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer());
FBXSDK_printf("\n");
for(i = 0; i < lAnimStackCount; i++)
{
FbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i);
FBXSDK_printf(" Animation Stack %d\n", i);
FBXSDK_printf(" Name: \"%s\"\n", lTakeInfo->mName.Buffer());
FBXSDK_printf(" Description: \"%s\"\n", lTakeInfo->mDescription.Buffer());
FBXSDK_printf(" Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer());
FBXSDK_printf(" Import State: %s\n", lTakeInfo->mSelect ? "true" : "false");
FBXSDK_printf("\n");
}
IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true);
IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true);
IOS_REF.SetBoolProp(IMP_FBX_LINK, true);
IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true);
IOS_REF.SetBoolProp(IMP_FBX_GOBO, true);
IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true);
IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
}
lStatus = lImporter->Import(pScene);
if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError)
{
FBXSDK_printf("Please enter password: ");
lPassword[0] = '\0';
FBXSDK_CRT_SECURE_NO_WARNING_BEGIN
scanf("%s", lPassword);
FBXSDK_CRT_SECURE_NO_WARNING_END
FbxString lString(lPassword);
IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString);
IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true);
lStatus = lImporter->Import(pScene);
if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError)
{
FBXSDK_printf("\nPassword is wrong, import aborted.\n");
}
}
lImporter->Destroy();
return lStatus;
}