From 073b4dac576d68bd042e9e152fb91ea6f2807b2d Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 12:34:07 -0800 Subject: [PATCH 01/14] Use gltf instead of binary. --- demo/addons/fbx/import_fbx.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/addons/fbx/import_fbx.gd b/demo/addons/fbx/import_fbx.gd index 6f38ae0..95d3dc5 100644 --- a/demo/addons/fbx/import_fbx.gd +++ b/demo/addons/fbx/import_fbx.gd @@ -32,7 +32,7 @@ func _import_scene(path: String, flags: int, bake_fps: int): ProjectSettings.add_property_info(property_info) var user_path_base = OS.get_user_data_dir() var path_global : String = ProjectSettings.globalize_path(path) - var output_path : String = "res://.godot/imported/" + path.get_file().get_basename() + "-" + path.md5_text() + ".glb" + var output_path : String = "res://.godot/imported/" + path.get_file().get_basename() + "-" + path.md5_text() + ".gltf" var output_path_global = ProjectSettings.globalize_path(output_path) var stdout = [].duplicate() var temp_dir_global = ProjectSettings.globalize_path("res://.godot/imported/") From ac35ea351f23671f545d0187352712ae0f54cce5 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 12:49:14 -0800 Subject: [PATCH 02/14] Add some basic install instructions. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f913471..f8f2cb9 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,7 @@ You need to install the MVSC redistributable on Windows. https://support.microso ## Build Instructions Reference the Github workflow. + +```bash +conan install . -i build -s build_type=Release -s compiler.cppstd=14 -s compiler.runtime=static --build=missing +``` \ No newline at end of file From 0b1240635b3518a92d174c7ce381296b5afd3a1f Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 12:51:28 -0800 Subject: [PATCH 03/14] Unused. --- conanfile.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/conanfile.py b/conanfile.py index cb623ec..7722cc0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -18,13 +18,7 @@ class FBX2glTFConan(ConanFile): generators = "cmake_find_package", "cmake_paths" def configure(self): - if ( - self.settings.compiler == "gcc" - and self.settings.compiler.libcxx == "libstdc++" - ): - raise Exception( - "Rerun 'conan install' with argument: '-s compiler.libcxx=libstdc++11'" - ) + pass def build(self): cmake = CMake(self) From 10d8a665e08a398c09a8556efb023ba00f3c6122 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 12:54:26 -0800 Subject: [PATCH 04/14] Requires c++17. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8f2cb9..1ca54d3 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,5 @@ You need to install the MVSC redistributable on Windows. https://support.microso Reference the Github workflow. ```bash -conan install . -i build -s build_type=Release -s compiler.cppstd=14 -s compiler.runtime=static --build=missing +conan install . -i build -s build_type=Release -s compiler.cppstd=17 -s compiler.runtime=static --build=missing ``` \ No newline at end of file From eef1a8f1537e840e7b39f6f0ac7aea86059b240a Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 13:15:40 -0800 Subject: [PATCH 05/14] Sync conan versions and Texturebuilder work. --- conanfile.py | 8 +++++++- src/gltf/TextureBuilder.cpp | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/conanfile.py b/conanfile.py index 7722cc0..cb623ec 100644 --- a/conanfile.py +++ b/conanfile.py @@ -18,7 +18,13 @@ class FBX2glTFConan(ConanFile): generators = "cmake_find_package", "cmake_paths" def configure(self): - pass + if ( + self.settings.compiler == "gcc" + and self.settings.compiler.libcxx == "libstdc++" + ): + raise Exception( + "Rerun 'conan install' with argument: '-s compiler.libcxx=libstdc++11'" + ) def build(self): cmake = CMake(self) diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 0a930dc..3d39986 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -202,27 +202,24 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: image = new ImageData(relativeFilename, *bufferView, mimeType); } - } else if (!relativeFilename.empty()) { + } else if (!relativeFilename.empty()) { std::string outputPath = outputFolder + "/" + relativeFilename; auto dstAbs = FileUtils::GetAbsolutePath(outputPath); image = new ImageData(relativeFilename, relativeFilename); auto srcAbs = FileUtils::GetAbsolutePath(rawTexture.fileLocation); - if (!FileUtils::FileExists(outputPath) && srcAbs != dstAbs) { - if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { - if (verboseOutput) { - fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); - } - } else { - // no point commenting further on read/write error; CopyFile() does enough of that, and we - // certainly want to to add an image struct to the glTF JSON, with the correct relative - // path reference, even if the copy failed. - } + if (FileUtils::FileExists(outputPath) || srcAbs == dstAbs)) { + return nullptr; } - } + if (!FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { + return nullptr; + } + if (verboseOutput) { + fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); + } + } if (!image) { return nullptr; } - std::shared_ptr texDat = gltf.textures.hold( new TextureData(textureName, *gltf.defaultSampler, *gltf.images.hold(image))); textureByIndicesKey.insert(std::make_pair(key, texDat)); From 64f4e6515c969aff279cfd3301e7908cd597e54c Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 13:20:36 -0800 Subject: [PATCH 06/14] Simplify. --- src/gltf/TextureBuilder.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 3d39986..72bb78b 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -203,23 +203,22 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: } } else if (!relativeFilename.empty()) { - std::string outputPath = outputFolder + "/" + relativeFilename; - auto dstAbs = FileUtils::GetAbsolutePath(outputPath); image = new ImageData(relativeFilename, relativeFilename); - auto srcAbs = FileUtils::GetAbsolutePath(rawTexture.fileLocation); - if (FileUtils::FileExists(outputPath) || srcAbs == dstAbs)) { - return nullptr; + std::string outputPath = outputFolder + "/" + relativeFilename; + if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { + if (verboseOutput) { + fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); + } + } else { + // no point commenting further on read/write error; CopyFile() does enough of that, and we + // certainly want to to add an image struct to the glTF JSON, with the correct relative path + // reference, even if the copy failed. } - if (!FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { - return nullptr; - } - if (verboseOutput) { - fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); - } - } + } if (!image) { return nullptr; } + std::shared_ptr texDat = gltf.textures.hold( new TextureData(textureName, *gltf.defaultSampler, *gltf.images.hold(image))); textureByIndicesKey.insert(std::make_pair(key, texDat)); From 9eb3423ca21836e9663f0cd3679b12ba45575213 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 13:33:12 -0800 Subject: [PATCH 07/14] Force embed resources. --- src/FBX2glTF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index e9ee876..2a87108 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -88,7 +88,7 @@ struct GltfOptions { /** Whether to output a .glb file, the binary format of glTF. */ bool outputBinary{false}; /** If non-binary, whether to inline all resources, for a single (large) .glTF file. */ - bool embedResources{false}; + bool embedResources{true}; bool separateTextures{true}; From 2c4a9ade9ff9e331a6c9db47459813d0b14e2fa9 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 13:48:43 -0800 Subject: [PATCH 08/14] Use keep original textures. --- demo/addons/fbx/import_fbx.gd | 1 + src/FBX2glTF.cpp | 12 ++++++++++-- src/FBX2glTF.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/demo/addons/fbx/import_fbx.gd b/demo/addons/fbx/import_fbx.gd index 95d3dc5..f214244 100644 --- a/demo/addons/fbx/import_fbx.gd +++ b/demo/addons/fbx/import_fbx.gd @@ -37,6 +37,7 @@ func _import_scene(path: String, flags: int, bake_fps: int): var stdout = [].duplicate() var temp_dir_global = ProjectSettings.globalize_path("res://.godot/imported/") var ret = OS.execute(fbx2gltf_path, [ + "--keep-originals", "--fbx-temp-dir", temp_dir_global, "-i", path_global, "-o", output_path_global], stdout, true) diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index 5bb8841..19fc32f 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -52,6 +52,12 @@ int main(int argc, char* argv[]) { gltfOptions.embedResources, "Inline buffers as data:// URIs within generated non-binary glTF."); + + app.add_flag( + "--keep-originals", + gltfOptions.keepOriginals, + "Keep the originals paths in a non-binary glTF."); + app.add_flag( "-t,--separate-textures", gltfOptions.separateTextures, "Write texture files out separately"); @@ -306,8 +312,10 @@ int main(int argc, char* argv[]) { if (gltfOptions.embedResources && gltfOptions.outputBinary) { fmt::printf("Note: Ignoring --embed; it's meaningless with --binary.\n"); } - - if (outputPath.empty()) { + + if (gltfOptions.keepOriginals) { + outputPath = "./" + FileUtils::GetFileBase(inputPath); + } else if (outputPath.empty() && !gltfOptions.keepOriginals) { // if -o is not given, default to the basename of the .fbx outputPath = "./" + FileUtils::GetFileBase(inputPath); } diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index 2a87108..11598a2 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -90,6 +90,8 @@ struct GltfOptions { /** If non-binary, whether to inline all resources, for a single (large) .glTF file. */ bool embedResources{true}; + bool keepOriginals{false}; + bool separateTextures{true}; /** Whether and how to use KHR_draco_mesh_compression to minimize static geometry size. */ From 8be4ef3931f01882b2978dedf5c938a0614c0f37 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 13:50:28 -0800 Subject: [PATCH 09/14] Do not auto embed resources. --- src/FBX2glTF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index 11598a2..0ab1e00 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -88,7 +88,7 @@ struct GltfOptions { /** Whether to output a .glb file, the binary format of glTF. */ bool outputBinary{false}; /** If non-binary, whether to inline all resources, for a single (large) .glTF file. */ - bool embedResources{true}; + bool embedResources{false}; bool keepOriginals{false}; From c9396fd2dbb73e0b69ed66b5a106c14451ea247d Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 14:27:20 -0800 Subject: [PATCH 10/14] Add to the keep original functionality. --- src/FBX2glTF.cpp | 4 +--- src/gltf/TextureBuilder.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index 19fc32f..a29b839 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -313,9 +313,7 @@ int main(int argc, char* argv[]) { fmt::printf("Note: Ignoring --embed; it's meaningless with --binary.\n"); } - if (gltfOptions.keepOriginals) { - outputPath = "./" + FileUtils::GetFileBase(inputPath); - } else if (outputPath.empty() && !gltfOptions.keepOriginals) { + if (outputPath.empty()) { // if -o is not given, default to the basename of the .fbx outputPath = "./" + FileUtils::GetFileBase(inputPath); } diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 72bb78b..0b21af8 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -185,7 +185,17 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: const std::string textureName = FileUtils::GetFileBase(rawTexture.name); const std::string relativeFilename = FileUtils::GetFileName(rawTexture.fileLocation); ImageData* image = nullptr; - if (options.outputBinary) { + if (options.keepOriginals && !relativeFilename.empty()) { + image = new ImageData(textureName, relativeFilename); + } else if (options.keepOriginals && relativeFilename.empty()) { + std::string outputPath = "textures/" + textureName; + image = new ImageData(textureName, outputPath); + if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { + if (verboseOutput) { + fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath); + } + } + } else if (options.outputBinary) { auto bufferView = gltf.AddBufferViewForFile(*gltf.defaultBuffer, rawTexture.fileLocation); if (bufferView) { const auto& suffix = FileUtils::GetFileSuffix(rawTexture.fileLocation); @@ -201,7 +211,6 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: } image = new ImageData(relativeFilename, *bufferView, mimeType); } - } else if (!relativeFilename.empty()) { image = new ImageData(relativeFilename, relativeFilename); std::string outputPath = outputFolder + "/" + relativeFilename; From 401bcccc7769da28fd4bebdca24031b10d9fd772 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 14:42:09 -0800 Subject: [PATCH 11/14] Use input path for keep originals. --- src/FBX2glTF.cpp | 15 +++++++-------- src/FBX2glTF.h | 1 + src/gltf/TextureBuilder.cpp | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index a29b839..dc480b2 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -40,9 +40,8 @@ int main(int argc, char* argv[]) { exit(0); }); - std::string inputPath; - app.add_option("FBX Model", inputPath, "The FBX model to convert.")->check(CLI::ExistingFile); - app.add_option("-i,--input", inputPath, "The FBX model to convert.")->check(CLI::ExistingFile); + app.add_option("FBX Model", gltfOptions.inputPath, "The FBX model to convert.")->check(CLI::ExistingFile); + app.add_option("-i,--input", gltfOptions.inputPath, "The FBX model to convert.")->check(CLI::ExistingFile); std::string outputPath; app.add_option("-o,--output", outputPath, "Where to generate the output, without suffix."); @@ -297,7 +296,7 @@ int main(int argc, char* argv[]) { } } - if (inputPath.empty()) { + if (gltfOptions.inputPath.empty()) { fmt::printf("You must supply a FBX file to convert.\n"); exit(1); } @@ -315,7 +314,7 @@ int main(int argc, char* argv[]) { if (outputPath.empty()) { // if -o is not given, default to the basename of the .fbx - outputPath = "./" + FileUtils::GetFileBase(inputPath); + outputPath = "./" + FileUtils::GetFileBase(gltfOptions.inputPath); } // the output folder in .gltf mode, not used for .glb std::string outputFolder; @@ -355,10 +354,10 @@ int main(int argc, char* argv[]) { RawModel raw; if (verboseOutput) { - fmt::printf("Loading FBX File: %s\n", inputPath); + fmt::printf("Loading FBX File: %s\n", gltfOptions.inputPath); } - if (!LoadFBXFile(raw, inputPath, {"png", "jpg", "jpeg"}, gltfOptions)) { - fmt::fprintf(stderr, "ERROR:: Failed to parse FBX: %s\n", inputPath); + if (!LoadFBXFile(raw, gltfOptions.inputPath, {"png", "jpg", "jpeg"}, gltfOptions)) { + fmt::fprintf(stderr, "ERROR:: Failed to parse FBX: %s\n", gltfOptions.inputPath); return 1; } diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index 0ab1e00..10b4e2a 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -78,6 +78,7 @@ enum class AnimationFramerateOptions { * User-supplied options that dictate the nature of the glTF being generated. */ struct GltfOptions { + std::string inputPath; /** * If negative, disabled. Otherwise, a bitfield of RawVertexAttributes that * specify the largest set of attributes that'll ever be kept for a vertex. diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index 0b21af8..e7d225c 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -188,7 +188,8 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: if (options.keepOriginals && !relativeFilename.empty()) { image = new ImageData(textureName, relativeFilename); } else if (options.keepOriginals && relativeFilename.empty()) { - std::string outputPath = "textures/" + textureName; + std::string inputPathBase = FileUtils::GetFileBase(gltfOptions.inputPath); + std::string outputPath = inputPathBase + "/textures/" + textureName; image = new ImageData(textureName, outputPath); if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { if (verboseOutput) { From 7063185f9f3b98b45aee797506b960989068e24e Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 14:47:17 -0800 Subject: [PATCH 12/14] Typo. --- src/gltf/TextureBuilder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index e7d225c..e3ace2f 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -188,7 +188,7 @@ std::shared_ptr TextureBuilder::simple(int rawTexIndex, const std:: if (options.keepOriginals && !relativeFilename.empty()) { image = new ImageData(textureName, relativeFilename); } else if (options.keepOriginals && relativeFilename.empty()) { - std::string inputPathBase = FileUtils::GetFileBase(gltfOptions.inputPath); + std::string inputPathBase = FileUtils::GetFileBase(options.inputPath); std::string outputPath = inputPathBase + "/textures/" + textureName; image = new ImageData(textureName, outputPath); if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) { From e76d5c2d99af1a29b649b9b3862c20aed22d521c Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 15:23:28 -0800 Subject: [PATCH 13/14] Name the gltf2 buffer uniquely. --- src/FBX2glTF.cpp | 2 +- src/gltf/GltfModel.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index dc480b2..3233a29 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -399,7 +399,7 @@ int main(int argc, char* argv[]) { assert(!outputFolder.empty()); - const std::string binaryPath = outputFolder + extBufferFilename; + const std::string binaryPath = outputFolder + FileUtils::GetFileBase(gltfOptions.inputPath) + extBufferFilename; FILE* fp = fopen(binaryPath.c_str(), "wb"); if (fp == nullptr) { fmt::fprintf(stderr, "ERROR:: Couldn't open file '%s' for writing.\n", binaryPath); diff --git a/src/gltf/GltfModel.hpp b/src/gltf/GltfModel.hpp index 0c4f40e..bd8cf40 100644 --- a/src/gltf/GltfModel.hpp +++ b/src/gltf/GltfModel.hpp @@ -230,6 +230,6 @@ class GltfModel { } BufferData* buildDefaultBuffer(const GltfOptions& options) { return options.outputBinary ? new BufferData(binary) - : new BufferData(extBufferFilename, binary, options.embedResources); + : new BufferData(FileUtils::GetFileBase(options.inputPath) + extBufferFilename, binary, options.embedResources); } }; From 7d564a9b02a6dd5c99c95193bc929e8b8fcf47ea Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sun, 28 Nov 2021 15:47:09 -0800 Subject: [PATCH 14/14] Set the default. --- src/gltf/GltfModel.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gltf/GltfModel.hpp b/src/gltf/GltfModel.hpp index bd8cf40..0c4f40e 100644 --- a/src/gltf/GltfModel.hpp +++ b/src/gltf/GltfModel.hpp @@ -230,6 +230,6 @@ class GltfModel { } BufferData* buildDefaultBuffer(const GltfOptions& options) { return options.outputBinary ? new BufferData(binary) - : new BufferData(FileUtils::GetFileBase(options.inputPath) + extBufferFilename, binary, options.embedResources); + : new BufferData(extBufferFilename, binary, options.embedResources); } };