Skip to content
Merged
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
9 changes: 5 additions & 4 deletions examples/export_fbx/export_fbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions src/mesh_writer/fbx_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_, "");
Expand All @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Loading