Rearrange, extract, clean up.

Hopefully without unintentional changes to functionality. This renames header
files to .hpp, imposes a gltf/raw/fbx directory structure, extracts standalone
chunks of Fbx2Raw into distinct files, and undoes some particularly egregious
mistakes from when I knew even less C++ than I do now.

This is in anticipation of implementing 3ds Max's "Physical Material".
This commit is contained in:
Par Winzell 2018-08-27 15:48:33 -07:00 committed by Pär Winzell
parent b475fbead4
commit 7d36e7f4d7
3 changed files with 97 additions and 30 deletions

View File

@ -7,6 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "File_Utils.hpp"
#include <string>
#include <vector>
#include <fstream>
@ -35,7 +37,7 @@
#include <sys/stat.h>
#include "FBX2glTF.h"
#include "String_Utils.h"
#include "String_Utils.hpp"
namespace FileUtils {

View File

@ -7,16 +7,23 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "Image_Utils.hpp"
#include <string>
#include <algorithm>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
#include "Image_Utils.h"
namespace ImageUtils {
static bool imageHasTransparentPixels(FILE *f) {
static bool imageHasTransparentPixels(FILE *f)
{
int width, height, channels;
// RGBA: we have to load the pixels to figure out if the image is fully opaque
uint8_t *pixels = stbi_load_from_file(f, &width, &height, &channels, 0);
@ -54,3 +61,17 @@ ImageProperties GetImageProperties(char const *filePath)
return result;
}
std::string suffixToMimeType(std::string suffix)
{
std::transform(suffix.begin(), suffix.end(), suffix.begin(), ::tolower);
if (suffix == "jpg" || suffix == "jpeg") {
return "image/jpeg";
}
if (suffix == "png") {
return "image/png";
}
return "image/unknown";
}
}

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "String_Utils.h"
#include "String_Utils.hpp"
namespace StringUtils {
@ -16,4 +16,48 @@ namespace StringUtils {
return (s == PATH_WIN) ? PATH_UNIX : PATH_WIN;
}
const std::string GetFolderString(const std::string &path)
{
size_t s = path.rfind(PATH_WIN);
s = (s != std::string::npos) ? s : path.rfind(PATH_UNIX);
return path.substr(0, s + 1);
}
const std::string GetCleanPathString(const std::string &path, const PathSeparator separator)
{
std::string cleanPath = path;
for (size_t s = cleanPath.find(!separator, 0); s != std::string::npos; s = cleanPath.find(!separator, s)) {
cleanPath[s] = separator;
}
return cleanPath;
}
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);
}
const std::string GetFileBaseString(const std::string &path)
{
const std::string fileName = GetFileNameString(path);
return fileName.substr(0, fileName.rfind('.')).c_str();
}
const std::string GetFileSuffixString(const std::string &path)
{
const std::string fileName = GetFileNameString(path);
size_t pos = fileName.rfind('.');
if (pos == std::string::npos) {
return "";
}
return fileName.substr(++pos);
}
int CompareNoCase(const std::string &s1, const std::string &s2)
{
return strncasecmp(s1.c_str(), s2.c_str(), MAX_PATH_LENGTH);
}
}