Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(cmake/flatbuffer.cmake)

add_subdirectory(examples/EncodeSample)
add_subdirectory(examples/DecodeSample)
add_subdirectory(examples/FbxSample)
add_subdirectory(src/FbxLibra)
add_dependencies(FbxLibra generate_flatbuffers_code)

Expand Down
1 change: 1 addition & 0 deletions src/FbxLibra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SOURCE_FILES
main.cpp
Status.h
FlatBufferLoader.h
FbxClient.h
FBXLibra.h
FBXLibra.cpp
CounterWeight/HierarchyCounterWeight.h
Expand Down
25 changes: 7 additions & 18 deletions src/FbxLibra/CounterWeight/HierarchyCounterWeightFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
#include "HierarchyCounterWeightFactory.h"
#include "HierarchyCounterWeight.h"
#include "../FlatBufferLoader.h"
#include "../FbxClient.h"
#include "flatbuffers/flatbuffers.h"

CounterWeight *HierarchyCounterWeightFactory::CreateCounterWeight(const std::filesystem::path &fbx_path) {
FbxManager* manager = FbxManager::Create();
FbxIOSettings* ios = FbxIOSettings::Create(manager, IOSROOT);
manager->SetIOSettings(ios);

FbxImporter* importer = FbxImporter::Create(manager, "");

if (!importer->Initialize(fbx_path.string().c_str(), -1, manager->GetIOSettings())){
std::cerr << "Failed to initialize FBX importer: " << importer->GetStatus().GetErrorString() << std::endl;
return nullptr;
FbxClient client;
if (!client.Load(fbx_path))
{
std::cerr << "Failed to load FBX file: " << fbx_path << std::endl;
return nullptr;
}

FbxScene* scene = FbxScene::Create(manager, "Scene");
importer->Import(scene);

FbxNode* rootNode = scene->GetRootNode();
FbxNode* rootNode = client.GetRootNode();

std::vector<flatbuffers::Offset<Weight::Node>> nodes;
if (rootNode){
Expand All @@ -37,11 +31,6 @@ CounterWeight *HierarchyCounterWeightFactory::CreateCounterWeight(const std::fil
this->builder->Finish(hierarchy_offset);
auto new_hierarchy = flatbuffers::GetRoot<Weight::Hierarchy>(builder->GetBufferPointer());

importer->Destroy();
scene->Destroy();
ios->Destroy();
manager->Destroy();

return new HierarchyCounterWeight(new_hierarchy);
}

Expand Down
20 changes: 9 additions & 11 deletions src/FbxLibra/CounterWeight/SkinWeightCounterWeightFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
#include "../FlatBufferLoader.h"
#include "cw_generated.h"
#include "SkinWeightCounterWeight.h"
#include "../FbxClient.h"
#include "fbxsdk.h"


CounterWeight *SkinWeightCounterWeightFactory::CreateCounterWeight(const std::filesystem::path &fbx_path) {
FbxManager* manager = FbxManager::Create();
FbxIOSettings* ios = FbxIOSettings::Create(manager, IOSROOT);
manager->SetIOSettings(ios);

FbxImporter* importer = FbxImporter::Create(manager, "");
if (!importer->Initialize(fbx_path.string().c_str(), -1, manager->GetIOSettings())) {
std::cerr << "Failed to initialize FBX importer: " << importer->GetStatus().GetErrorString() << std::endl;
return nullptr;
FbxClient client;
if (!client.Load(fbx_path))
{
std::cerr << "Failed to load FBX file: " << fbx_path << std::endl;
return nullptr;
}
FbxScene* scene = FbxScene::Create(manager, "Scene");
importer->Import(scene);

std::vector<flatbuffers::Offset<Weight::SkinWeight>> skinWeightList;
FbxNode* rootNode = scene->GetRootNode();
FbxNode* rootNode = client.GetRootNode();
if (rootNode)
{
ProcessNode(rootNode, skinWeightList);
Expand Down
25 changes: 7 additions & 18 deletions src/FbxLibra/CounterWeight/VertexCounterWeightFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
#include "VertexCounterWeight.h"
#include "VertexCounterWeightFactory.h"
#include "../FlatBufferLoader.h"
#include "../FbxClient.h"

using namespace std;
using namespace Weight;

CounterWeight* VertexCounterWeightFactory::CreateCounterWeight(const std::filesystem::path& fbx_path) {
FbxManager* manager = FbxManager::Create();
FbxIOSettings* ios = FbxIOSettings::Create(manager, IOSROOT);
manager->SetIOSettings(ios);

FbxImporter* importer = FbxImporter::Create(manager, "");

if (!importer->Initialize(fbx_path.string().c_str(), -1, manager->GetIOSettings())) {
std::cerr << "Failed to initialize FBX importer: " << importer->GetStatus().GetErrorString() << std::endl;
return nullptr;
FbxClient client;
if (!client.Load(fbx_path))
{
std::cerr << "Failed to load FBX file: " << fbx_path << std::endl;
return nullptr;
}

FbxScene* scene = FbxScene::Create(manager, "Scene");
importer->Import(scene);

FbxNode* rootNode = scene->GetRootNode();
FbxNode* rootNode = client.GetRootNode();

//scene内のMeshノードを取得
std::vector<FbxNode*> mesh_nodes;
Expand Down Expand Up @@ -140,11 +134,6 @@ CounterWeight* VertexCounterWeightFactory::CreateCounterWeight(const std::filesy
// FinishMeshesBuffer(*builder, meshes_offsets);
auto ne = flatbuffers::GetRoot<Weight::Meshes>(builder->GetBufferPointer());

importer->Destroy();
scene->Destroy();
ios->Destroy();
manager->Destroy();

return new VertexCounterWeight(ne);;
}

Expand Down
51 changes: 51 additions & 0 deletions src/FbxLibra/FbxClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef FBXCLIENT_H
#define FBXCLIENT_H
#include <filesystem>
#include <iostream>

#include "fbxsdk.h"

class FbxClient {
private:
FbxNode* root;

// RAII(Resource Acquisition Is Initialization)を利用してFbxManager, FbxIOSettings, FbxSceneを破棄する
static void DestroyFbxManager(FbxManager* manager) { manager->Destroy(); }
static void DestroyFbxIOSettings(FbxIOSettings* ios) { ios->Destroy(); }
static void DestroyFbxScene(FbxScene* scene) { scene->Destroy(); }

public:
FbxClient(): root(nullptr),
manager(FbxManager::Create(), DestroyFbxManager),
ios(FbxIOSettings::Create(manager.get(), IOSROOT), DestroyFbxIOSettings),
scene(FbxScene::Create(manager.get(), "Scene"), DestroyFbxScene){}

std::unique_ptr<FbxManager, void(*)(FbxManager*)> manager;
std::unique_ptr<FbxIOSettings, void(*)(FbxIOSettings*)> ios;
std::unique_ptr<FbxScene, void(*)(FbxScene*)> scene;
bool Load(const std::filesystem::path& fbx_path)
{
manager->SetIOSettings(ios.get());
if (!manager || !ios || !scene) {
std::cerr << "Failed to create FbxManager, FbxIOSettings, or FbxScene." << std::endl;
return false;
}

FbxImporter* importer = FbxImporter::Create(manager.get(), "");

if (!importer->Initialize(fbx_path.string().c_str(), -1, manager->GetIOSettings())){
std::cerr << "Failed to initialize FBX importer: " << importer->GetStatus().GetErrorString() << std::endl;
return false;
}
importer->Import(scene.get());
importer->Destroy();

root = scene->GetRootNode();
return true;
};
[[nodiscard]] FbxNode* GetRootNode() const { return root; }
};



#endif //FBXCLIENT_H
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ configure_file(

add_executable(${PROJECT_NAME}
../src/FbxLibra/Status.h
../src/FbxLibra/FbxClient.h
../src/FbxLibra/FlatBufferLoader.h
../src/FbxLibra/FBXLibra.h
../src/FbxLibra/FBXLibra.cpp
Expand Down