#include "MyOwnWriter.h"
MyOwnWriter::MyOwnWriter(FbxManager &pManager, int pID):
FbxWriter(pManager, pID, FbxStatusGlobal::GetRef()),
mFilePointer(NULL),
mManager(&pManager)
{
}
MyOwnWriter::~MyOwnWriter()
{
FileClose();
}
bool MyOwnWriter::FileCreate(char* pFileName)
{
if(mFilePointer != NULL)
{
FileClose();
}
FBXSDK_fopen(mFilePointer,pFileName,"w");
if(mFilePointer == NULL)
{
return false;
}
return true;
}
bool MyOwnWriter::FileClose()
{
if(mFilePointer != NULL)
{
fclose(mFilePointer);
return true;
}
return false;
}
bool MyOwnWriter::IsFileOpen()
{
if(mFilePointer != NULL)
return true;
return false;
}
void MyOwnWriter::GetWriteOptions()
{
}
bool MyOwnWriter::Write(FbxDocument* pDocument)
{
if (!pDocument)
{
GetStatus().SetCode(FbxStatus::eFailure, "Invalid document handle");
return false;
}
FbxScene* lScene = FbxCast<FbxScene>(pDocument);
bool lIsAScene = (lScene != NULL);
bool lResult = false;
if(lIsAScene)
{
PreprocessScene(*lScene);
FBXSDK_printf("I'm in my own writer\n");
FbxNode* lRootNode = lScene->GetRootNode();
PrintHierarchy(lRootNode);
PostprocessScene(*lScene);
lResult = true;
}
return lResult;
}
void MyOwnWriter::PrintHierarchy(FbxNode* pStartNode)
{
FbxNode* lChildNode;
const char* lParentName = pStartNode->GetName();
for(int i = 0; i<pStartNode->GetChildCount(); i++)
{
lChildNode = pStartNode->GetChild(i);
const char* lChildName = lChildNode->GetName();
FBXSDK_fprintf(mFilePointer,"%s%s%s%s%s%s%s","\"",lChildName,"\"",", parent is ","\"",lParentName,"\"\n");
}
int lNodeChildCount = pStartNode->GetChildCount ();
while (lNodeChildCount > 0)
{
lNodeChildCount--;
lChildNode = pStartNode->GetChild (lNodeChildCount);
PrintHierarchy(lChildNode);
}
}
bool MyOwnWriter::PreprocessScene(FbxScene& )
{
FBXSDK_printf("I'm in pre-process\n");
return true;
}
bool MyOwnWriter::PostprocessScene(FbxScene& )
{
FBXSDK_printf("I'm in post process\n");
return true;
}