Merge branch 'master' into feat/mocha-tests

This commit is contained in:
Par Winzell 2018-12-12 12:52:26 -08:00
commit b9e18f3dd2
8 changed files with 83 additions and 17 deletions

View File

@ -9,12 +9,6 @@ endif ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Iconv QUIET)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
include(ExternalProject)
@ -34,6 +28,32 @@ if (NOT FBXSDK_FOUND)
)
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
find_package(Iconv QUIET)
if (WIN32)
# this will suffice for now; don't really care about 32-bit
set(LIBXML2_INCLUDE_DIRS ${FBXSDK_INCLUDE_DIR})
set(LIBXML2_LIBRARIES ${FBXSDK_ROOT}/lib/vs2017/x64/release/libxml2-mt.lib)
set(LIBXML2_LIBRARIES_DEBUG ${FBXSDK_ROOT}/lib/vs2017/x64/debug/libxml2-mt.lib)
if (NOT LIBXML2_INCLUDE_DIRS OR NOT LIBXML2_LIBRARIES)
message(FATAL_ERROR "Cannot find libxml2.lib in the expected location.")
endif()
set(ZLIB_INCLUDE_DIRS ${FBXSDK_INCLUDE_DIR})
set(ZLIB_LIBRARIES ${FBXSDK_ROOT}/lib/vs2017/x64/release/zlib-mt.lib)
set(ZLIB_LIBRARIES_DEBUG ${FBXSDK_ROOT}/lib/vs2017/x64/debug/zlib-mt.lib)
if (NOT ZLIB_LIBRARIES)
message(FATAL_ERROR "Cannot find zlib.lib in the expected location.")
endif()
else()
find_package(LibXml2 REQUIRED)
find_package(ZLIB REQUIRED)
endif()
# DRACO
ExternalProject_Add(Draco
GIT_REPOSITORY https://github.com/google/draco
@ -235,11 +255,23 @@ target_link_libraries(libFBX2glTF
optimized ${FBXSDK_LIBRARY}
debug ${FBXSDK_LIBRARY_DEBUG}
${CMAKE_DL_LIBS}
${LIBXML2_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
if (WIN32)
target_link_libraries(libFBX2glTF
optimized ${LIBXML2_LIBRARIES}
debug ${LIBXML2_LIBRARIES_DEBUG}
optimized ${ZLIB_LIBRARIES}
debug ${ZLIB_LIBRARIES_DEBUG}
)
else()
target_link_libraries(libFBX2glTF
${LIBXML2_LIBRARIES}
${ZLIB_LIBRARIES}
)
endif()
target_include_directories(libFBX2glTF PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
)

View File

@ -27,7 +27,7 @@ if (NOT DEFINED FBXSDK_VERSION)
set(FBXSDK_VERSION "2018.1.1")
endif()
set(_fbxsdk_vstudio_version "vs2015")
set(_fbxsdk_vstudio_version "vs2017")
message("Looking for FBX SDK version: ${FBXSDK_VERSION}")

View File

@ -221,7 +221,9 @@ int main(int argc, char *argv[])
if (options.count("output") == 0) {
// if -o is not given, default to the basename of the .fbx
outputPath = "./" + StringUtils::GetFileBaseString(inputPath);
outputPath = fmt::format(".{}{}", (const char)StringUtils::GetPathSeparator(), StringUtils::GetFileBaseString(inputPath));
fmt::printf("outputPath = %s\n", outputPath);
}
std::string outputFolder; // the output folder in .gltf mode, not used for .glb
std::string modelPath; // the path of the actual .glb or .gltf file
@ -231,7 +233,7 @@ int main(int argc, char *argv[])
} else {
// in gltf mode, we create a folder and write into that
outputFolder = outputPath + "_out/";
outputFolder = fmt::format("{}_out{}", outputFolder.c_str(), (const char)StringUtils::GetPathSeparator());
modelPath = outputFolder + StringUtils::GetFileNameString(outputPath) + ".gltf";
}
if (!FileUtils::CreatePath(modelPath.c_str())) {

View File

@ -184,8 +184,9 @@ std::shared_ptr<TextureData> TextureBuilder::simple(int rawTexIndex, const std::
} else if (!relativeFilename.empty()) {
image = new ImageData(relativeFilename, relativeFilename);
std::string outputPath = outputFolder + relativeFilename;
if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath)) {
std::string outputPath = outputFolder + StringUtils::NormalizePath(relativeFilename);
if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true))
{
if (verboseOutput) {
fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath);
}

View File

@ -184,7 +184,7 @@ namespace FileUtils {
return true;
}
bool CopyFile(const std::string &srcFilename, const std::string &dstFilename) {
bool CopyFile(const std::string &srcFilename, const std::string &dstFilename, bool createPath) {
std::ifstream srcFile(srcFilename, std::ios::binary);
if (!srcFile) {
fmt::printf("Warning: Couldn't open file %s for reading.\n", srcFilename);
@ -195,9 +195,14 @@ namespace FileUtils {
std::streamsize srcSize = srcFile.tellg();
srcFile.seekg(0, std::ios::beg);
if (createPath && !CreatePath(dstFilename.c_str())) {
fmt::printf("Warning: Couldn't create directory %s.\n", dstFilename);
return false;
}
std::ofstream dstFile(dstFilename, std::ios::binary | std::ios::trunc);
if (!dstFile) {
fmt::printf("Warning: Couldn't open file %s for writing.\n", srcFilename);
fmt::printf("Warning: Couldn't open file %s for writing.\n", dstFilename);
return false;
}
dstFile << srcFile.rdbuf();

View File

@ -24,6 +24,5 @@ namespace FileUtils {
bool CreatePath(const char *path);
bool CopyFile(const std::string &srcFilename, const std::string &dstFilename);
bool CopyFile(const std::string &srcFilename, const std::string &dstFilename, bool createPath = false);
}

View File

@ -16,6 +16,30 @@ namespace StringUtils {
return (s == PATH_WIN) ? PATH_UNIX : PATH_WIN;
}
PathSeparator GetPathSeparator() {
#if defined( __unix__ ) || defined( __APPLE__ )
return PATH_UNIX;
#else
return PATH_WIN;
#endif
}
const std::string NormalizePath(const std::string &path)
{
PathSeparator separator = GetPathSeparator();
char replace;
if (separator == PATH_WIN) {
replace = PATH_UNIX;
}
else {
replace = PATH_WIN;
}
std::string normalizedPath = path;
for (size_t s = normalizedPath.find(replace, 0); s != std::string::npos; s = normalizedPath.find(replace, s)) {
normalizedPath[s] = separator;
}
return normalizedPath;
}
const std::string GetFolderString(const std::string &path)
{
size_t s = path.rfind(PATH_WIN);

View File

@ -31,6 +31,9 @@ namespace StringUtils {
PathSeparator operator!(const PathSeparator &s);
PathSeparator GetPathSeparator();
const std::string NormalizePath(const std::string &path);
const std::string GetCleanPathString(const std::string &path, const PathSeparator separator = PATH_WIN);
template<size_t size>