Skip to content

Commit dfee250

Browse files
authored
#260 SDKで書き出したFBXが一緒に書き出したテクスチャを参照していない (#265)
1 parent d700e46 commit dfee250

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

examples/export_fbx/export_fbx.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ int main() {
6767
const auto destination = fs::path(".").string();
6868
const auto gml_file_name = fs::path(gml_file_path).filename().string();
6969
auto base_obj_name = fs::path(gml_file_name).replace_extension(".fbx").string();
70-
const auto gltf_file_path = fs::path(destination).append(base_obj_name).make_preferred().string();
71-
plateau::meshWriter::FbxWriteOptions options;
72-
options.file_format = plateau::meshWriter::FbxFileFormat::ASCII;
73-
auto result = plateau::meshWriter::FbxWriter().write(gltf_file_path , *model, options);
70+
const auto fbx_file_path = fs::path(destination).append(base_obj_name).make_preferred().string();
7471

72+
plateau::meshWriter::FbxWriteOptions options;
73+
options.file_format = plateau::meshWriter::FbxFileFormat::Binary;
74+
options.coordinate_system = plateau::geometry::CoordinateSystem::ENU;
75+
auto result = plateau::meshWriter::FbxWriter().write(fbx_file_path, *model, options);
7576
}
7677
catch (std::exception& e) {
7778
std::cout << e.what() << std::endl;

src/mesh_writer/fbx_writer.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace plateau::meshWriter {
8888

8989
for (int i = 0; i < model.getRootNodeCount(); ++i) {
9090
const auto& node = model.getRootNodeAt(i);
91-
processNodeRecursive(node, fbx_scene->GetRootNode(), fbx_scene);
91+
processNodeRecursive(node, fbx_scene->GetRootNode(), fbx_scene, fs::absolute(path).u8string());
9292
}
9393

9494
const auto exporter = FbxExporter::Create(manager_, "");
@@ -107,14 +107,14 @@ namespace plateau::meshWriter {
107107
exporter->Destroy();
108108

109109
// テクスチャファイルコピー
110-
for (const auto& texture : required_textures_) {
111-
copyTexture(fs::absolute(path).u8string(), texture);
110+
for (const auto& texture_path : required_textures_) {
111+
copyTexture(fs::absolute(path).u8string(), texture_path);
112112
}
113113

114114
return true;
115115
}
116116

117-
void processNodeRecursive(const polygonMesh::Node& node, FbxNode* parent_fbx_node, FbxScene* fbx_scene) {
117+
void processNodeRecursive(const polygonMesh::Node& node, FbxNode* parent_fbx_node, FbxScene* fbx_scene, const std::string& fbx_path) {
118118
const auto fbx_node = FbxNode::Create(fbx_scene, node.getName().c_str());
119119
parent_fbx_node->AddChild(fbx_node);
120120

@@ -137,15 +137,15 @@ namespace plateau::meshWriter {
137137

138138
const auto mesh = node.getMesh();
139139
if (mesh != nullptr)
140-
addMesh(*mesh, fbx_scene, fbx_node);
140+
addMesh(*mesh, fbx_scene, fbx_node, fbx_path);
141141

142142
for (size_t i = 0; i < node.getChildCount(); ++i) {
143143
const auto& child_node = node.getChildAt(i);
144-
processNodeRecursive(child_node, fbx_node, fbx_scene);
144+
processNodeRecursive(child_node, fbx_node, fbx_scene, fbx_path);
145145
}
146146
}
147147

148-
void addMesh(const polygonMesh::Mesh& mesh, FbxScene* fbx_scene, FbxNode* fbx_node) {
148+
void addMesh(const polygonMesh::Mesh& mesh, FbxScene* fbx_scene, FbxNode* fbx_node, const std::string& fbx_path) {
149149
const auto fbx_mesh = FbxMesh::Create(fbx_scene, "");
150150

151151
// Create control points.
@@ -245,7 +245,10 @@ namespace plateau::meshWriter {
245245
if (FbxColorProperty.IsValid()) {
246246
//Create a fbx property
247247
FbxFileTexture* lTexture = FbxFileTexture::Create(fbx_scene, fs::u8path(texture_path).filename().u8string().c_str());
248-
lTexture->SetFileName(texture_path.c_str());
248+
auto dst_path = fs::u8path(fbx_path).parent_path();
249+
dst_path /= fs::u8path(texture_path).parent_path().filename();
250+
dst_path /= fs::u8path(texture_path).filename();
251+
lTexture->SetFileName(dst_path.u8string().c_str());
249252
lTexture->SetTextureUse(FbxTexture::eStandard);
250253
lTexture->SetMappingType(FbxTexture::eUV);
251254
lTexture->ConnectDstProperty(FbxColorProperty);

0 commit comments

Comments
 (0)