From 753739f77bd108c1e4af1a63a93ee76b8ff2ec8e Mon Sep 17 00:00:00 2001 From: Sacchy Date: Fri, 21 Feb 2025 00:16:14 +0900 Subject: [PATCH] =?UTF-8?q?#260=20SDK=E3=81=A7=E6=9B=B8=E3=81=8D=E5=87=BA?= =?UTF-8?q?=E3=81=97=E3=81=9FFBX=E3=81=8C=E4=B8=80=E7=B7=92=E3=81=AB?= =?UTF-8?q?=E6=9B=B8=E3=81=8D=E5=87=BA=E3=81=97=E3=81=9F=E3=83=86=E3=82=AF?= =?UTF-8?q?=E3=82=B9=E3=83=81=E3=83=A3=E3=82=92=E5=8F=82=E7=85=A7=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/export_fbx/export_fbx.cpp | 9 +++++---- src/mesh_writer/fbx_writer.cpp | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/export_fbx/export_fbx.cpp b/examples/export_fbx/export_fbx.cpp index 3093618b..3aa4f480 100644 --- a/examples/export_fbx/export_fbx.cpp +++ b/examples/export_fbx/export_fbx.cpp @@ -67,11 +67,12 @@ int main() { const auto destination = fs::path(".").string(); const auto gml_file_name = fs::path(gml_file_path).filename().string(); auto base_obj_name = fs::path(gml_file_name).replace_extension(".fbx").string(); - const auto gltf_file_path = fs::path(destination).append(base_obj_name).make_preferred().string(); - plateau::meshWriter::FbxWriteOptions options; - options.file_format = plateau::meshWriter::FbxFileFormat::ASCII; - auto result = plateau::meshWriter::FbxWriter().write(gltf_file_path , *model, options); + const auto fbx_file_path = fs::path(destination).append(base_obj_name).make_preferred().string(); + plateau::meshWriter::FbxWriteOptions options; + options.file_format = plateau::meshWriter::FbxFileFormat::Binary; + options.coordinate_system = plateau::geometry::CoordinateSystem::ENU; + auto result = plateau::meshWriter::FbxWriter().write(fbx_file_path, *model, options); } catch (std::exception& e) { std::cout << e.what() << std::endl; diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index d8307559..63b33c9f 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -88,7 +88,7 @@ namespace plateau::meshWriter { for (int i = 0; i < model.getRootNodeCount(); ++i) { const auto& node = model.getRootNodeAt(i); - processNodeRecursive(node, fbx_scene->GetRootNode(), fbx_scene); + processNodeRecursive(node, fbx_scene->GetRootNode(), fbx_scene, fs::absolute(path).u8string()); } const auto exporter = FbxExporter::Create(manager_, ""); @@ -107,14 +107,14 @@ namespace plateau::meshWriter { exporter->Destroy(); // テクスチャファイルコピー - for (const auto& texture : required_textures_) { - copyTexture(fs::absolute(path).u8string(), texture); + for (const auto& texture_path : required_textures_) { + copyTexture(fs::absolute(path).u8string(), texture_path); } return true; } - void processNodeRecursive(const polygonMesh::Node& node, FbxNode* parent_fbx_node, FbxScene* fbx_scene) { + void processNodeRecursive(const polygonMesh::Node& node, FbxNode* parent_fbx_node, FbxScene* fbx_scene, const std::string& fbx_path) { const auto fbx_node = FbxNode::Create(fbx_scene, node.getName().c_str()); parent_fbx_node->AddChild(fbx_node); @@ -137,15 +137,15 @@ namespace plateau::meshWriter { const auto mesh = node.getMesh(); if (mesh != nullptr) - addMesh(*mesh, fbx_scene, fbx_node); + addMesh(*mesh, fbx_scene, fbx_node, fbx_path); for (size_t i = 0; i < node.getChildCount(); ++i) { const auto& child_node = node.getChildAt(i); - processNodeRecursive(child_node, fbx_node, fbx_scene); + processNodeRecursive(child_node, fbx_node, fbx_scene, fbx_path); } } - void addMesh(const polygonMesh::Mesh& mesh, FbxScene* fbx_scene, FbxNode* fbx_node) { + void addMesh(const polygonMesh::Mesh& mesh, FbxScene* fbx_scene, FbxNode* fbx_node, const std::string& fbx_path) { const auto fbx_mesh = FbxMesh::Create(fbx_scene, ""); // Create control points. @@ -245,7 +245,10 @@ namespace plateau::meshWriter { if (FbxColorProperty.IsValid()) { //Create a fbx property FbxFileTexture* lTexture = FbxFileTexture::Create(fbx_scene, fs::u8path(texture_path).filename().u8string().c_str()); - lTexture->SetFileName(texture_path.c_str()); + auto dst_path = fs::u8path(fbx_path).parent_path(); + dst_path /= fs::u8path(texture_path).parent_path().filename(); + dst_path /= fs::u8path(texture_path).filename(); + lTexture->SetFileName(dst_path.u8string().c_str()); lTexture->SetTextureUse(FbxTexture::eStandard); lTexture->SetMappingType(FbxTexture::eUV); lTexture->ConnectDstProperty(FbxColorProperty);