Skip to content

Commit

Permalink
Refactor CurveConverter. Fix a bug where Converter cannot a file with…
Browse files Browse the repository at this point in the history
… a path which contains multibyte string
  • Loading branch information
durswd committed Apr 28, 2024
1 parent b9124fb commit f09080f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 53 deletions.
16 changes: 6 additions & 10 deletions Tool/fbxToEffekseerCurveConverter/source/FbxCurveConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "FbxCurveConverter.h"
#include <fstream>
#include <iostream>

FbxNurbsCurveData* FbxCurveConverter::SearchNurbsCurve(const FbxNodeInfo& _pNodeInfo)
{
Expand All @@ -18,15 +19,15 @@ FbxNurbsCurveData* FbxCurveConverter::SearchNurbsCurve(const FbxNodeInfo& _pNode
return nullptr;
}

bool FbxCurveConverter::Export(const std::string _Filepath, const FbxInfo& _pFbxeInfo)
bool FbxCurveConverter::Export(const std::string& file_path, const FbxInfo& _pFbxeInfo)
{
FbxNurbsCurveData* pCurve = nullptr;

for (int i = 0; i < _pFbxeInfo.mNodeCount; i++)
{
// search export data
pCurve = SearchNurbsCurve(*_pFbxeInfo.mNodes[i]);

if (pCurve != nullptr)
{
break;
Expand All @@ -35,22 +36,17 @@ bool FbxCurveConverter::Export(const std::string _Filepath, const FbxInfo& _pFbx

if (pCurve == nullptr)
{
std::cout << "Error : Curve is not found" << std::endl;

return false;
}

// change extention
std::string lFilepath = _Filepath;
std::string::size_type lExtentionPos = lFilepath.find_last_of('.');

lFilepath = lFilepath.substr(0, lExtentionPos);
lFilepath.append(".efkcurve");

//
// Start Export
//

// create export file
std::ofstream ofs(lFilepath, std::ios::out | std::ios::binary);
std::ofstream ofs(file_path, std::ios::out | std::ios::binary);

// export version
int version = ConverterVersion;
Expand Down
3 changes: 2 additions & 1 deletion Tool/fbxToEffekseerCurveConverter/source/FbxCurveConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FbxCurveConverter
static const int ConverterVersion = 1;

static FbxNurbsCurveData* SearchNurbsCurve(const FbxNodeInfo& _pFbxeInfo);

public:
static bool Export(const std::string _Filepath,const FbxInfo& _pNodeInfo);
static bool Export(const std::string& file_path, const FbxInfo& _pNodeInfo);
};
21 changes: 10 additions & 11 deletions Tool/fbxToEffekseerCurveConverter/source/FbxLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void FbxLoader::LoadNodeInfo(FbxNode* _pNode, FbxNodeInfo* _pNodeInfo)

// Load Child
_pNodeInfo->mChildCount = _pNode->GetChildCount();

for (int i = 0; i < _pNodeInfo->mChildCount; i++)
{
FbxNodeInfo* lNode = new FbxNodeInfo();
Expand Down Expand Up @@ -103,7 +103,6 @@ void FbxLoader::LoadAttribute(FbxNode* _pNode, FbxNodeInfo* _pNodeInfo)
_pNodeInfo->mAttributeID = -1;
_pNodeInfo->mAttributeType = "eNull";
}

}

void FbxLoader::LoadNurbsCurve(FbxNode* _pNode, FbxNodeInfo* _pNodeInfo)
Expand Down Expand Up @@ -141,15 +140,15 @@ void FbxLoader::LoadNurbsCurve(FbxNode* _pNode, FbxNodeInfo* _pNodeInfo)
pNurbsCurve->mDimension = pFbxNurbs->GetDimension();
}

FbxInfo* FbxLoader::Imoport(std::string _Filepath)
std::shared_ptr<FbxInfo> FbxLoader::Imoport(const std::string& file_path)
{
// Import Scene
FbxManager* pManager = FbxManager::Create();
FbxIOSettings* pIOS = FbxIOSettings::Create(pManager, IOSROOT);
pManager->SetIOSettings(pIOS);

FbxImporter* pImpoter = FbxImporter::Create(pManager, "");
if (!pImpoter->Initialize(_Filepath.c_str(), -1, pManager->GetIOSettings()))
if (!pImpoter->Initialize(file_path.c_str(), -1, pManager->GetIOSettings()))
{
printf("Call to FbxImporter::Initialize() failed.\n");
printf("Error returned: %s\n\n", pImpoter->GetStatus().GetErrorString());
Expand All @@ -160,19 +159,19 @@ FbxInfo* FbxLoader::Imoport(std::string _Filepath)
pImpoter->Import(pScene);
pImpoter->Destroy();

FbxInfo* lFbxInfo = new FbxInfo();
auto fbx_info = std::make_shared<FbxInfo>();

lFbxInfo->mNodeCount = pScene->GetNodeCount();
fbx_info->mNodeCount = pScene->GetNodeCount();

for (int i = 0; i < lFbxInfo->mNodeCount; i++)
for (int i = 0; i < fbx_info->mNodeCount; i++)
{
FbxNodeInfo* lNode = new FbxNodeInfo();
lFbxInfo->mNodes.push_back(lNode);
auto node = std::make_shared<FbxNodeInfo>();
fbx_info->mNodes.push_back(node);

LoadNodeInfo(pScene->GetNode(i), lNode);
LoadNodeInfo(pScene->GetNode(i), node.get());
}

pManager->Destroy();

return lFbxInfo;
return fbx_info;
}
13 changes: 3 additions & 10 deletions Tool/fbxToEffekseerCurveConverter/source/FbxLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fbxsdk.h>
#include <vector>
#include <string>
#include <memory>

struct FbxNurbsCurveData
{
Expand Down Expand Up @@ -49,15 +50,7 @@ struct FbxNodeInfo
struct FbxInfo
{
int mNodeCount;
std::vector<FbxNodeInfo*> mNodes;

~FbxInfo()
{
for (auto it : mNodes)
{
delete it;
}
}
std::vector<std::shared_ptr<FbxNodeInfo>> mNodes;
};

class FbxLoader
Expand All @@ -69,5 +62,5 @@ class FbxLoader
static void LoadNurbsCurve(FbxNode* _pNode, FbxNodeInfo* _pNodeInfo);

public:
static FbxInfo* Imoport(std::string _Filepath);
static std::shared_ptr<FbxInfo> Imoport(const std::string& file_path);
};
60 changes: 39 additions & 21 deletions Tool/fbxToEffekseerCurveConverter/source/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "FbxLoader.h"
#include "FbxCurveConverter.h"
#include "FbxLoader.h"

#include <iostream>

#if _DEBUG
#pragma comment(lib, "debug/libfbxsdk.lib")
Expand All @@ -13,36 +15,52 @@
//#pragma comment(lib, "release/zlib-mt.lib")
#endif

int main(int argc, char *argv[])
#ifdef _WIN32
#include <cstring>
#include <string>
#include <windows.h>

std::string ANSI_to_UTF8(std::string inANSI)
{
wchar_t tempWideChar[1024];
char outUTF8[1024];
MultiByteToWideChar(CP_ACP, 0, inANSI.c_str(), -1, tempWideChar, 1024);
WideCharToMultiByte(CP_UTF8, 0, tempWideChar, -1, outUTF8, 1024, NULL, NULL);
return outUTF8;
}

#endif

int main(int argc, char* argv[])
{
std::string lFilepath;// = "data//test_curve.fbx";
lFilepath = argv[1];
std::string import_path; // = "data//test_curve.fbx";
import_path = argv[1];

std::string export_path = import_path;
std::string::size_type ext_pos = export_path.find_last_of('.');

export_path = export_path.substr(0, ext_pos);
export_path.append(".efkcurve");

std::cout << "Import path : " << import_path << std::endl;
std::cout << "Export path : " << export_path << std::endl;

#ifdef _WIN32
import_path = ANSI_to_UTF8(import_path);
#endif

auto lFbxInfo = FbxLoader::Imoport(import_path);

auto lFbxInfo = FbxLoader::Imoport(lFilepath);

if (lFbxInfo == nullptr)
{
printf("Load Failed\n");

#ifdef _DEBUG
system("pause");
#endif // _DEBUG

std::cout << "Error : Failed to load" << std::endl;
return 1;
}

if (FbxCurveConverter::Export(lFilepath, *lFbxInfo) == false)
if (!FbxCurveConverter::Export(export_path, *lFbxInfo))
{
printf("Output Error\n");

#ifdef _DEBUG
system("pause");
#endif // _DEBUG

return 1;
}

delete lFbxInfo;

return 0;
}

0 comments on commit f09080f

Please sign in to comment.