diff --git a/CMakeLists.txt b/CMakeLists.txt index e24b390..b4537af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ find_package(Threads REQUIRED) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_BINARY_DIR}") # stuff we get from Conan -find_package(Boost 1.76 COMPONENTS system filesystem program_options REQUIRED ) +find_package(Boost 1.76 COMPONENTS system filesystem program_options nowide REQUIRED ) find_package(ZLIB MODULE REQUIRED) find_package(fmt MODULE REQUIRED) find_package(Iconv MODULE REQUIRED) @@ -209,6 +209,7 @@ target_link_libraries(libFBX2glTF ${DRACO_LIB} Boost::system Boost::filesystem + Boost::nowide optimized ${FBXSDK_LIBRARY} debug ${FBXSDK_LIBRARY_DEBUG} fmt::fmt diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index 40c15b6..5211188 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -6,7 +6,9 @@ * LICENSE file in the root directory of this source tree. */ -#include +#include +#include +#include #include #include #include @@ -20,9 +22,14 @@ #include "utils/File_Utils.hpp" #include "utils/String_Utils.hpp" +// in Fbx2Raw.cpp +extern std::string NativeToUTF8(const std::string& str); + bool verboseOutput = false; int main(int argc, char* argv[]) { + boost::nowide::nowide_filesystem(); + GltfOptions gltfOptions; CLI::App app{ @@ -310,6 +317,8 @@ 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); + } else { + outputPath = NativeToUTF8(outputPath); } // the output folder in .gltf mode, not used for .glb std::string outputFolder; @@ -362,7 +371,7 @@ int main(int argc, char* argv[]) { raw.Condense(gltfOptions.maxSkinningWeights, gltfOptions.normalizeSkinningWeights); raw.TransformGeometry(gltfOptions.computeNormals); - std::ofstream outStream; // note: auto-flushes in destructor + boost::nowide::ofstream outStream; // note: auto-flushes in destructor const auto streamStart = outStream.tellp(); outStream.open(modelPath, std::ios::trunc | std::ios::ate | std::ios::out | std::ios::binary); @@ -395,7 +404,7 @@ int main(int argc, char* argv[]) { assert(!outputFolder.empty()); const std::string binaryPath = outputFolder + extBufferFilename; - FILE* fp = fopen(binaryPath.c_str(), "wb"); + FILE* fp = boost::nowide::fopen(binaryPath.c_str(), "wb"); if (fp == nullptr) { fmt::fprintf(stderr, "ERROR:: Couldn't open file '%s' for writing.\n", binaryPath); return 1; diff --git a/src/fbx/Fbx2Raw.cpp b/src/fbx/Fbx2Raw.cpp index 40a2cf3..63d7231 100644 --- a/src/fbx/Fbx2Raw.cpp +++ b/src/fbx/Fbx2Raw.cpp @@ -42,7 +42,7 @@ float scaleFactor; -static std::string NativeToUTF8(const std::string& str) { +std::string NativeToUTF8(const std::string& str) { #if _WIN32 char* u8cstr = nullptr; #if (_UNICODE || UNICODE) @@ -1131,13 +1131,14 @@ bool LoadFBXFile( FbxManager* pManager = FbxManager::Create(); if (!options.fbxTempDir.empty()) { - pManager->GetXRefManager().AddXRefProject("embeddedFileProject", options.fbxTempDir.c_str()); + const auto& fbxTempDir = NativeToUTF8(options.fbxTempDir); + pManager->GetXRefManager().AddXRefProject("embeddedFileProject", fbxTempDir.c_str()); FbxXRefManager::sEmbeddedFileProject = "embeddedFileProject"; - pManager->GetXRefManager().AddXRefProject("configurationProject", options.fbxTempDir.c_str()); + pManager->GetXRefManager().AddXRefProject("configurationProject", fbxTempDir.c_str()); FbxXRefManager::sConfigurationProject = "configurationProject"; - pManager->GetXRefManager().AddXRefProject("localizationProject", options.fbxTempDir.c_str()); + pManager->GetXRefManager().AddXRefProject("localizationProject", fbxTempDir.c_str()); FbxXRefManager::sLocalizationProject = "localizationProject"; - pManager->GetXRefManager().AddXRefProject("temporaryFileProject", options.fbxTempDir.c_str()); + pManager->GetXRefManager().AddXRefProject("temporaryFileProject", fbxTempDir.c_str()); FbxXRefManager::sTemporaryFileProject = "temporaryFileProject"; } diff --git a/src/gltf/GltfModel.cpp b/src/gltf/GltfModel.cpp index d4e981f..16a27fd 100644 --- a/src/gltf/GltfModel.cpp +++ b/src/gltf/GltfModel.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include "GltfModel.hpp" std::shared_ptr GltfModel::GetAlignedBufferView( @@ -44,7 +45,7 @@ std::shared_ptr GltfModel::AddBufferViewForFile( } std::shared_ptr result; - std::ifstream file(filename, std::ios::binary | std::ios::ate); + boost::nowide::ifstream file(filename, std::ios::binary | std::ios::ate); if (file) { std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); diff --git a/src/gltf/Raw2Gltf.cpp b/src/gltf/Raw2Gltf.cpp index f6da104..8aba780 100644 --- a/src/gltf/Raw2Gltf.cpp +++ b/src/gltf/Raw2Gltf.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -77,7 +77,7 @@ static const std::vector getIndexArray(const RawModel& raw) { } ModelData* Raw2Gltf( - std::ofstream& gltfOutStream, + boost::nowide::ofstream& gltfOutStream, const std::string& outputFolder, const RawModel& raw, const GltfOptions& options) { diff --git a/src/gltf/Raw2Gltf.hpp b/src/gltf/Raw2Gltf.hpp index 9dd753f..cba219f 100644 --- a/src/gltf/Raw2Gltf.hpp +++ b/src/gltf/Raw2Gltf.hpp @@ -10,6 +10,7 @@ #include #include +#include // This can be a macro under Windows, confusing Draco #undef ERROR @@ -203,7 +204,7 @@ struct ModelData { }; ModelData* Raw2Gltf( - std::ofstream& gltfOutStream, + boost::nowide::ofstream& gltfOutStream, const std::string& outputFolder, const RawModel& raw, const GltfOptions& options); diff --git a/src/gltf/TextureBuilder.cpp b/src/gltf/TextureBuilder.cpp index e626a43..99e3953 100644 --- a/src/gltf/TextureBuilder.cpp +++ b/src/gltf/TextureBuilder.cpp @@ -8,6 +8,7 @@ #include "TextureBuilder.hpp" +#include #include #include @@ -140,7 +141,7 @@ std::shared_ptr TextureBuilder::combine( } else { const std::string imageFilename = mergedFilename + (".png"); const std::string imagePath = outputFolder + imageFilename; - FILE* fp = fopen(imagePath.c_str(), "wb"); + FILE* fp = boost::nowide::fopen(imagePath.c_str(), "wb"); if (fp == nullptr) { fmt::printf("Warning:: Couldn't write file '%s' for writing.\n", imagePath); return nullptr; diff --git a/src/utils/File_Utils.cpp b/src/utils/File_Utils.cpp index 1f2b148..5bfdcdc 100644 --- a/src/utils/File_Utils.cpp +++ b/src/utils/File_Utils.cpp @@ -8,7 +8,7 @@ #include "File_Utils.hpp" -#include +#include #include #include #include @@ -57,7 +57,7 @@ bool CreatePath(const std::string path) { } bool CopyFile(const std::string& srcFilename, const std::string& dstFilename, bool createPath) { - std::ifstream srcFile(srcFilename, std::ios::binary); + boost::nowide::ifstream srcFile(srcFilename, std::ios::binary); if (!srcFile) { fmt::printf("Warning: Couldn't open file %s for reading.\n", srcFilename); return false; @@ -72,7 +72,7 @@ bool CopyFile(const std::string& srcFilename, const std::string& dstFilename, bo return false; } - std::ofstream dstFile(dstFilename, std::ios::binary | std::ios::trunc); + boost::nowide::ofstream dstFile(dstFilename, std::ios::binary | std::ios::trunc); if (!dstFile) { fmt::printf("Warning: Couldn't open file %s for writing.\n", dstFilename); return false; diff --git a/src/utils/Image_Utils.cpp b/src/utils/Image_Utils.cpp index b44677d..cc38d7f 100644 --- a/src/utils/Image_Utils.cpp +++ b/src/utils/Image_Utils.cpp @@ -11,12 +11,11 @@ #include #include +#define STBI_WINDOWS_UTF8 #define STB_IMAGE_IMPLEMENTATION - #include #define STB_IMAGE_WRITE_IMPLEMENTATION - #include namespace ImageUtils {