Drop the Gltf:: namespace prefix. (#77)

This commit is contained in:
Pär Winzell 2018-02-25 17:19:19 -08:00 committed by GitHub
parent 3f796dd90f
commit a984f7bf37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 96 deletions

View File

@ -1319,22 +1319,22 @@ static void ReadAnimations(RawModel &raw, FbxScene *pScene)
static std::string GetInferredFileName(const std::string &fbxFileName, const std::string &directory, const std::vector<std::string> &directoryFileList) static std::string GetInferredFileName(const std::string &fbxFileName, const std::string &directory, const std::vector<std::string> &directoryFileList)
{ {
// Get the file name with file extension. // Get the file name with file extension.
const std::string fileName = Gltf::StringUtils::GetFileNameString(Gltf::StringUtils::GetCleanPathString(fbxFileName)); const std::string fileName = StringUtils::GetFileNameString(StringUtils::GetCleanPathString(fbxFileName));
// Try to find a match with extension. // Try to find a match with extension.
for (const auto &file : directoryFileList) { for (const auto &file : directoryFileList) {
if (Gltf::StringUtils::CompareNoCase(fileName, file) == 0) { if (StringUtils::CompareNoCase(fileName, file) == 0) {
return std::string(directory) + file; return std::string(directory) + file;
} }
} }
// Get the file name without file extension. // Get the file name without file extension.
const std::string fileBase = Gltf::StringUtils::GetFileBaseString(fileName); const std::string fileBase = StringUtils::GetFileBaseString(fileName);
// Try to find a match without file extension. // Try to find a match without file extension.
for (const auto &file : directoryFileList) { for (const auto &file : directoryFileList) {
// If the two extension-less base names match. // If the two extension-less base names match.
if (Gltf::StringUtils::CompareNoCase(fileBase, Gltf::StringUtils::GetFileBaseString(file)) == 0) { if (StringUtils::CompareNoCase(fileBase, StringUtils::GetFileBaseString(file)) == 0) {
// Return the name with extension of the file in the directory. // Return the name with extension of the file in the directory.
return std::string(directory) + file; return std::string(directory) + file;
} }
@ -1357,10 +1357,10 @@ FindFbxTextures(
FbxScene *pScene, const char *fbxFileName, const char *extensions, std::map<const FbxTexture *, FbxString> &textureLocations) FbxScene *pScene, const char *fbxFileName, const char *extensions, std::map<const FbxTexture *, FbxString> &textureLocations)
{ {
// Get the folder the FBX file is in. // Get the folder the FBX file is in.
const std::string folder = Gltf::StringUtils::GetFolderString(fbxFileName); const std::string folder = StringUtils::GetFolderString(fbxFileName);
// Check if there is a filename.fbm folder to which embedded textures were extracted. // Check if there is a filename.fbm folder to which embedded textures were extracted.
const std::string fbmFolderName = folder + Gltf::StringUtils::GetFileBaseString(fbxFileName) + ".fbm/"; const std::string fbmFolderName = folder + StringUtils::GetFileBaseString(fbxFileName) + ".fbm/";
// Search either in the folder with embedded textures or in the same folder as the FBX file. // Search either in the folder with embedded textures or in the same folder as the FBX file.
const std::string searchFolder = FileUtils::FolderExists(fbmFolderName) ? fbmFolderName : folder; const std::string searchFolder = FileUtils::FolderExists(fbmFolderName) ? fbmFolderName : folder;

View File

@ -448,39 +448,39 @@ ModelData *Raw2Gltf(
}; };
int width = -1, height = -1; int width = -1, height = -1;
std::string mergedName = tag;
std::string mergedFilename = tag; std::string mergedFilename = tag;
std::vector<TexInfo> texes { }; std::vector<TexInfo> texes { };
for (const int rawTexIx : rawTexIndices) { for (const int rawTexIx : rawTexIndices) {
TexInfo info(rawTexIx); TexInfo info(rawTexIx);
if (rawTexIx >= 0) { if (rawTexIx >= 0) {
const RawTexture &rawTex = raw.GetTexture(rawTexIx); const RawTexture &rawTex = raw.GetTexture(rawTexIx);
const std::string &fileLoc = rawTex.fileLocation; const std::string &fileLoc = rawTex.fileLocation;
const std::string &fileLocBase = Gltf::StringUtils::GetFileBaseString(Gltf::StringUtils::GetFileNameString(fileLoc)); const std::string &name = StringUtils::GetFileBaseString(StringUtils::GetFileNameString(fileLoc));
if (!fileLoc.empty()) { if (!fileLoc.empty()) {
info.pixels = stbi_load(fileLoc.c_str(), &info.width, &info.height, &info.channels, 0); info.pixels = stbi_load(fileLoc.c_str(), &info.width, &info.height, &info.channels, 0);
if (!info.pixels) { if (!info.pixels) {
fmt::printf("Warning: merge texture [%d](%s) could not be loaded.\n", fmt::printf("Warning: merge texture [%d](%s) could not be loaded.\n",
rawTexIx, rawTexIx,
Gltf::StringUtils::GetFileBaseString(Gltf::StringUtils::GetFileNameString(fileLoc))); name);
} else { } else {
if (width < 0) { if (width < 0) {
width = info.width; width = info.width;
height = info.height; height = info.height;
} else if (width != info.width || height != info.height) { } else if (width != info.width || height != info.height) {
fmt::printf("Warning: texture %s (%d, %d) can't be merged with previous texture(s) of dimension (%d, %d)\n", fmt::printf("Warning: texture %s (%d, %d) can't be merged with previous texture(s) of dimension (%d, %d)\n",
Gltf::StringUtils::GetFileBaseString(Gltf::StringUtils::GetFileNameString(fileLoc)), name,
info.width, info.height, width, height); info.width, info.height, width, height);
// this is bad enough that we abort the whole merge // this is bad enough that we abort the whole merge
return nullptr; return nullptr;
} }
mergedName += "_" + rawTex.fileName; mergedFilename += "_" + name;
mergedFilename += "_" + fileLocBase;
} }
} }
} }
texes.push_back(info); texes.push_back(info);
} }
// at the moment, the best choice of filename is also the best choice of name
const std::string mergedName = mergedFilename;
if (width < 0) { if (width < 0) {
// no textures to merge; bail // no textures to merge; bail
@ -579,14 +579,14 @@ ModelData *Raw2Gltf(
} }
const RawTexture &rawTexture = raw.GetTexture(rawTexIndex); const RawTexture &rawTexture = raw.GetTexture(rawTexIndex);
const std::string textureName = Gltf::StringUtils::GetFileBaseString(rawTexture.name); const std::string textureName = StringUtils::GetFileBaseString(rawTexture.name);
const std::string relativeFilename = Gltf::StringUtils::GetFileNameString(rawTexture.fileLocation); const std::string relativeFilename = StringUtils::GetFileNameString(rawTexture.fileLocation);
ImageData *image = nullptr; ImageData *image = nullptr;
if (options.outputBinary) { if (options.outputBinary) {
auto bufferView = gltf->AddBufferViewForFile(buffer, rawTexture.fileLocation); auto bufferView = gltf->AddBufferViewForFile(buffer, rawTexture.fileLocation);
if (bufferView) { if (bufferView) {
std::string suffix = Gltf::StringUtils::GetFileSuffixString(rawTexture.fileLocation); std::string suffix = StringUtils::GetFileSuffixString(rawTexture.fileLocation);
image = new ImageData(relativeFilename, *bufferView, suffixToMimeType(suffix)); image = new ImageData(relativeFilename, *bufferView, suffixToMimeType(suffix));
} }

View File

@ -91,7 +91,7 @@ int RawModel::AddTexture(const std::string &name, const std::string &fileName, c
return -1; return -1;
} }
for (size_t i = 0; i < textures.size(); i++) { for (size_t i = 0; i < textures.size(); i++) {
if (Gltf::StringUtils::CompareNoCase(textures[i].name, name) == 0 && textures[i].usage == usage) { if (StringUtils::CompareNoCase(textures[i].name, name) == 0 && textures[i].usage == usage) {
return (int) i; return (int) i;
} }
} }
@ -159,7 +159,7 @@ int RawModel::AddMaterial(
int RawModel::AddSurface(const RawSurface &surface) int RawModel::AddSurface(const RawSurface &surface)
{ {
for (size_t i = 0; i < surfaces.size(); i++) { for (size_t i = 0; i < surfaces.size(); i++) {
if (Gltf::StringUtils::CompareNoCase(surfaces[i].name, surface.name) == 0) { if (StringUtils::CompareNoCase(surfaces[i].name, surface.name) == 0) {
return (int) i; return (int) i;
} }
} }

View File

@ -197,7 +197,7 @@ Copyright (c) 2016-2017 Oculus VR, LLC.
if (options.count("output") == 0) { if (options.count("output") == 0) {
// if -o is not given, default to the basename of the .fbx // if -o is not given, default to the basename of the .fbx
outputPath = "./" + Gltf::StringUtils::GetFileBaseString(inputPath); outputPath = "./" + StringUtils::GetFileBaseString(inputPath);
} }
std::string outputFolder; // the output folder in .gltf mode, not used for .glb 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 std::string modelPath; // the path of the actual .glb or .gltf file
@ -208,7 +208,7 @@ Copyright (c) 2016-2017 Oculus VR, LLC.
} else { } else {
// in gltf mode, we create a folder and write into that // in gltf mode, we create a folder and write into that
outputFolder = outputPath + "_out/"; outputFolder = outputPath + "_out/";
modelPath = outputFolder + Gltf::StringUtils::GetFileNameString(outputPath) + ".gltf"; modelPath = outputFolder + StringUtils::GetFileNameString(outputPath) + ".gltf";
} }
if (!FileUtils::CreatePath(modelPath.c_str())) { if (!FileUtils::CreatePath(modelPath.c_str())) {
fmt::fprintf(stderr, "ERROR: Failed to create folder: %s'\n", outputFolder.c_str()); fmt::fprintf(stderr, "ERROR: Failed to create folder: %s'\n", outputFolder.c_str());

View File

@ -41,14 +41,14 @@ namespace FileUtils {
std::string GetCurrentFolder() std::string GetCurrentFolder()
{ {
char cwd[Gltf::StringUtils::MAX_PATH_LENGTH]; char cwd[StringUtils::MAX_PATH_LENGTH];
if (!_getcwd(cwd, sizeof(cwd))) { if (!_getcwd(cwd, sizeof(cwd))) {
return std::string(); return std::string();
} }
cwd[sizeof(cwd) - 1] = '\0'; cwd[sizeof(cwd) - 1] = '\0';
Gltf::StringUtils::GetCleanPath(cwd, cwd, Gltf::StringUtils::PATH_UNIX); StringUtils::GetCleanPath(cwd, cwd, StringUtils::PATH_UNIX);
const size_t length = strlen(cwd); const size_t length = strlen(cwd);
if (cwd[length - 1] != '/' && length < Gltf::StringUtils::MAX_PATH_LENGTH - 1) { if (cwd[length - 1] != '/' && length < StringUtils::MAX_PATH_LENGTH - 1) {
cwd[length + 0] = '/'; cwd[length + 0] = '/';
cwd[length + 1] = '\0'; cwd[length + 1] = '\0';
} }
@ -155,12 +155,12 @@ namespace FileUtils {
bool CreatePath(const char *path) bool CreatePath(const char *path)
{ {
#if defined( __unix__ ) || defined( __APPLE__ ) #if defined( __unix__ ) || defined( __APPLE__ )
Gltf::StringUtils::PathSeparator separator = Gltf::StringUtils::PATH_UNIX; StringUtils::PathSeparator separator = StringUtils::PATH_UNIX;
#else #else
Gltf::StringUtils::PathSeparator separator = Gltf::StringUtils::PATH_WIN; StringUtils::PathSeparator separator = StringUtils::PATH_WIN;
#endif #endif
std::string folder = Gltf::StringUtils::GetFolderString(path); std::string folder = StringUtils::GetFolderString(path);
std::string clean = Gltf::StringUtils::GetCleanPathString(folder, separator); std::string clean = StringUtils::GetCleanPathString(folder, separator);
std::string build = clean; std::string build = clean;
for (int i = 0; i < clean.length(); i ++) { for (int i = 0; i < clean.length(); i ++) {
if (clean[i] == separator && i > 0) { if (clean[i] == separator && i > 0) {

View File

@ -9,13 +9,11 @@
#include "String_Utils.h" #include "String_Utils.h"
namespace Gltf { namespace StringUtils {
namespace StringUtils {
PathSeparator operator!(const PathSeparator &s)
{
return (s == PATH_WIN) ? PATH_UNIX : PATH_WIN;
}
PathSeparator operator!(const PathSeparator &s)
{
return (s == PATH_WIN) ? PATH_UNIX : PATH_WIN;
} }
}// namespace Gltf
}

View File

@ -20,76 +20,72 @@
#define strcasecmp _stricmp #define strcasecmp _stricmp
#endif #endif
namespace Gltf // TODO replace namespace StringUtils {
{
namespace StringUtils {
static const unsigned int MAX_PATH_LENGTH = 1024; static const unsigned int MAX_PATH_LENGTH = 1024;
enum PathSeparator enum PathSeparator
{ {
PATH_WIN = '\\', PATH_WIN = '\\',
PATH_UNIX = '/' PATH_UNIX = '/'
}; };
PathSeparator operator!(const PathSeparator &s); PathSeparator operator!(const PathSeparator &s);
inline const std::string GetCleanPathString(const std::string &path, const PathSeparator separator = PATH_WIN) inline const std::string GetCleanPathString(const std::string &path, const PathSeparator separator = PATH_WIN)
{ {
std::string cleanPath = path; std::string cleanPath = path;
for (size_t s = cleanPath.find(!separator, 0); s != std::string::npos; s = cleanPath.find(!separator, s)) { for (size_t s = cleanPath.find(!separator, 0); s != std::string::npos; s = cleanPath.find(!separator, s)) {
cleanPath[s] = separator; cleanPath[s] = separator;
}
return cleanPath;
} }
template<size_t size> return cleanPath;
inline void GetCleanPath(char (&dest)[size], const char *path, const PathSeparator separator = PATH_WIN) }
{ template<size_t size>
size_t len = size - 1; inline void GetCleanPath(char (&dest)[size], const char *path, const PathSeparator separator = PATH_WIN)
strncpy(dest, path, len); {
char *destPtr = dest; size_t len = size - 1;
while ((destPtr = strchr(destPtr, !separator)) != nullptr) { strncpy(dest, path, len);
*destPtr = separator; char *destPtr = dest;
} while ((destPtr = strchr(destPtr, !separator)) != nullptr) {
*destPtr = separator;
} }
}
inline const std::string GetFolderString(const std::string &path) inline const std::string GetFolderString(const std::string &path)
{ {
size_t s = path.rfind(PATH_WIN); size_t s = path.rfind(PATH_WIN);
s = (s != std::string::npos) ? s : path.rfind(PATH_UNIX); s = (s != std::string::npos) ? s : path.rfind(PATH_UNIX);
return path.substr(0, s + 1); return path.substr(0, s + 1);
}
inline const std::string GetFileNameString(const std::string &path)
{
size_t s = path.rfind(PATH_WIN);
s = (s != std::string::npos) ? s : path.rfind(PATH_UNIX);
return path.substr(s + 1, std::string::npos);
}
inline const std::string GetFileBaseString(const std::string &path)
{
const std::string fileName = GetFileNameString(path);
return fileName.substr(0, fileName.rfind('.')).c_str();
}
inline const std::string GetFileSuffixString(const std::string &path)
{
const std::string fileName = GetFileNameString(path);
unsigned long pos = fileName.rfind('.');
if (pos == std::string::npos) {
return "";
} }
return fileName.substr(++pos);
}
inline const std::string GetFileNameString(const std::string &path) inline int CompareNoCase(const std::string &s1, const std::string &s2)
{ {
size_t s = path.rfind(PATH_WIN); return strncasecmp(s1.c_str(), s2.c_str(), MAX_PATH_LENGTH);
s = (s != std::string::npos) ? s : path.rfind(PATH_UNIX); }
return path.substr(s + 1, std::string::npos);
}
inline const std::string GetFileBaseString(const std::string &path) } // StringUtils
{
const std::string fileName = GetFileNameString(path);
return fileName.substr(0, fileName.rfind('.')).c_str();
}
inline const std::string GetFileSuffixString(const std::string &path)
{
const std::string fileName = GetFileNameString(path);
unsigned long pos = fileName.rfind('.');
if (pos == std::string::npos) {
return "";
}
return fileName.substr(++pos);
}
inline int CompareNoCase(const std::string &s1, const std::string &s2)
{
return strncasecmp(s1.c_str(), s2.c_str(), MAX_PATH_LENGTH);
}
} // StringUtils
}// namespace Gltf
#endif // _STRING_UTILS_H__ #endif // _STRING_UTILS_H__