mirror of
https://github.com/godotengine/FBX2glTF.git
synced 2025-12-31 21:48:37 +03:00
Add boost::nowide for utf8 support.
use UTF-8 in boost::filesystem Use UTF-8 in stb_image Use UTF-8 in GltfModel.cpp Use UTF-8 in FileUtils::CopyFile Fix typo in File_Utils.cpp Use UTF-8 in output path Use UTF-8 in Raw2Gltf Fix typo in Raw2Gltf Fix Raw2Gltf.hpp Expose NativeToUTF8 in Fbx2Raw.cpp Use UTF-8 in fbxTempDir Use UTF-8 in TextureBuilder
This commit is contained in:
committed by
K. S. Ernest (iFire) Lee
parent
61543913dd
commit
7937f9eb4d
@@ -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
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <boost/nowide/filesystem.hpp>
|
||||
#include <boost/nowide/cstdio.hpp>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include "GltfModel.hpp"
|
||||
|
||||
std::shared_ptr<BufferViewData> GltfModel::GetAlignedBufferView(
|
||||
@@ -44,7 +45,7 @@ std::shared_ptr<BufferViewData> GltfModel::AddBufferViewForFile(
|
||||
}
|
||||
|
||||
std::shared_ptr<BufferViewData> 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);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <stb_image.h>
|
||||
@@ -77,7 +77,7 @@ static const std::vector<TriangleIndex> getIndexArray(const RawModel& raw) {
|
||||
}
|
||||
|
||||
ModelData* Raw2Gltf(
|
||||
std::ofstream& gltfOutStream,
|
||||
boost::nowide::ofstream& gltfOutStream,
|
||||
const std::string& outputFolder,
|
||||
const RawModel& raw,
|
||||
const GltfOptions& options) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "TextureBuilder.hpp"
|
||||
|
||||
#include <boost/nowide/cstdio.hpp>
|
||||
#include <stb_image.h>
|
||||
#include <stb_image_write.h>
|
||||
|
||||
@@ -140,7 +141,7 @@ std::shared_ptr<TextureData> 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;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "File_Utils.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -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;
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#define STBI_WINDOWS_UTF8
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
|
||||
#include <stb_image.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <stb_image_write.h>
|
||||
|
||||
namespace ImageUtils {
|
||||
|
||||
Reference in New Issue
Block a user