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:
parent
b475fbead4
commit
7d36e7f4d7
|
@ -7,6 +7,8 @@
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "File_Utils.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -35,7 +37,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "FBX2glTF.h"
|
#include "FBX2glTF.h"
|
||||||
#include "String_Utils.h"
|
#include "String_Utils.hpp"
|
||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,23 @@
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Image_Utils.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
#include <stb_image_write.h>
|
#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;
|
int width, height, channels;
|
||||||
// RGBA: we have to load the pixels to figure out if the image is fully opaque
|
// 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);
|
uint8_t *pixels = stbi_load_from_file(f, &width, &height, &channels, 0);
|
||||||
|
@ -54,3 +61,17 @@ ImageProperties GetImageProperties(char const *filePath)
|
||||||
return result;
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "String_Utils.h"
|
#include "String_Utils.hpp"
|
||||||
|
|
||||||
namespace StringUtils {
|
namespace StringUtils {
|
||||||
|
|
||||||
|
@ -16,4 +16,48 @@ namespace StringUtils {
|
||||||
return (s == PATH_WIN) ? PATH_UNIX : PATH_WIN;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue