mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-17 12:48:52 +00:00
Compare commits
5 Commits
github-act
...
separate-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bafde6a53e | ||
|
|
3d939fd3ee | ||
|
|
fbbeb4d6a9 | ||
|
|
cef1787ef8 | ||
|
|
2f5aa9f13b |
@@ -153,6 +153,7 @@ if (!ret) {
|
|||||||
|
|
||||||
## Compile options
|
## Compile options
|
||||||
|
|
||||||
|
* `TINYGLTF_ENABLE_SERIALIZER` : Enable glTF serialization feature.
|
||||||
* `TINYGLTF_NOEXCEPTION` : Disable C++ exception in JSON parsing. You can use `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION` and `TINYGLTF_NOEXCEPTION` to fully remove C++ exception codes when compiling TinyGLTF.
|
* `TINYGLTF_NOEXCEPTION` : Disable C++ exception in JSON parsing. You can use `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION` and `TINYGLTF_NOEXCEPTION` to fully remove C++ exception codes when compiling TinyGLTF.
|
||||||
* `TINYGLTF_NO_STB_IMAGE` : Do not load images with stb_image. Instead use `TinyGLTF::SetImageLoader(LoadimageDataFunction LoadImageData, void *user_data)` to set a callback for loading images.
|
* `TINYGLTF_NO_STB_IMAGE` : Do not load images with stb_image. Instead use `TinyGLTF::SetImageLoader(LoadimageDataFunction LoadImageData, void *user_data)` to set a callback for loading images.
|
||||||
* `TINYGLTF_NO_STB_IMAGE_WRITE` : Do not write images with stb_image_write. Instead use `TinyGLTF::SetImageWriter(WriteimageDataFunction WriteImageData, void *user_data)` to set a callback for writing images.
|
* `TINYGLTF_NO_STB_IMAGE_WRITE` : Do not write images with stb_image_write. Instead use `TinyGLTF::SetImageWriter(WriteimageDataFunction WriteImageData, void *user_data)` to set a callback for writing images.
|
||||||
|
|||||||
@@ -412,3 +412,19 @@ TEST_CASE("image-uri-spaces", "[issue-236]") {
|
|||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TINYGLTF_NO_FS
|
||||||
|
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||||
|
|
||||||
|
std::string s1 = "\xe5\xaf\xb9"; // utf-8 string
|
||||||
|
|
||||||
|
std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */nullptr);
|
||||||
|
|
||||||
|
// expected: E5 AF B9
|
||||||
|
REQUIRE(3 == ret.size());
|
||||||
|
|
||||||
|
REQUIRE(0xe5 == static_cast<uint8_t>(ret[0]));
|
||||||
|
REQUIRE(0xaf == static_cast<uint8_t>(ret[1]));
|
||||||
|
REQUIRE(0xb9 == static_cast<uint8_t>(ret[2]));
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
53
tiny_gltf.h
53
tiny_gltf.h
@@ -26,6 +26,7 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
// Version:
|
// Version:
|
||||||
|
// - v2.4.3 Introduce TINYGLTF_ENABLE_SERIALIZER.
|
||||||
// - v2.4.2 Decode percent-encoded URI.
|
// - v2.4.2 Decode percent-encoded URI.
|
||||||
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
|
// - v2.4.1 Fix some glTF object class does not have `extensions` and/or
|
||||||
// `extras` property.
|
// `extras` property.
|
||||||
@@ -1249,7 +1250,13 @@ struct FsCallbacks {
|
|||||||
|
|
||||||
bool FileExists(const std::string &abs_filename, void *);
|
bool FileExists(const std::string &abs_filename, void *);
|
||||||
|
|
||||||
std::string ExpandFilePath(const std::string &filepath, void *);
|
///
|
||||||
|
/// Expand file path(e.g. `~` to home directory on posix, `%APPDATA%` to `C:\Users\tinygltf\AppData`)
|
||||||
|
///
|
||||||
|
/// @param[in] filepath File path string. Assume UTF-8
|
||||||
|
/// @param[in] userdata User data. Set to `nullptr` if you don't need it.
|
||||||
|
///
|
||||||
|
std::string ExpandFilePath(const std::string &filepath, void *userdata);
|
||||||
|
|
||||||
bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
bool ReadWholeFile(std::vector<unsigned char> *out, std::string *err,
|
||||||
const std::string &filepath, void *);
|
const std::string &filepath, void *);
|
||||||
@@ -1317,6 +1324,8 @@ class TinyGLTF {
|
|||||||
const std::string &base_dir = "",
|
const std::string &base_dir = "",
|
||||||
unsigned int check_sections = REQUIRE_VERSION);
|
unsigned int check_sections = REQUIRE_VERSION);
|
||||||
|
|
||||||
|
#if defined(TINYGLTF_ENABLE_SERIALIZER)
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Write glTF to stream, buffers and images will be embeded
|
/// Write glTF to stream, buffers and images will be embeded
|
||||||
///
|
///
|
||||||
@@ -1330,16 +1339,22 @@ class TinyGLTF {
|
|||||||
bool embedImages, bool embedBuffers,
|
bool embedImages, bool embedBuffers,
|
||||||
bool prettyPrint, bool writeBinary);
|
bool prettyPrint, bool writeBinary);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set callback to use for loading image data
|
/// Set callback to use for loading image data
|
||||||
///
|
///
|
||||||
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
|
void SetImageLoader(LoadImageDataFunction LoadImageData, void *user_data);
|
||||||
|
|
||||||
|
#if defined(TINYGLTF_ENABLE_SERIALIZER)
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set callback to use for writing image data
|
/// Set callback to use for writing image data
|
||||||
///
|
///
|
||||||
void SetImageWriter(WriteImageDataFunction WriteImageData, void *user_data);
|
void SetImageWriter(WriteImageDataFunction WriteImageData, void *user_data);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set callbacks to use for filesystem (fs) access and their user data
|
/// Set callbacks to use for filesystem (fs) access and their user data
|
||||||
///
|
///
|
||||||
@@ -2387,11 +2402,15 @@ bool LoadImageData(Image *image, const int image_idx, std::string *err,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(TINYGLTF_ENABLE_SERIALIZER)
|
||||||
|
|
||||||
void TinyGLTF::SetImageWriter(WriteImageDataFunction func, void *user_data) {
|
void TinyGLTF::SetImageWriter(WriteImageDataFunction func, void *user_data) {
|
||||||
WriteImageData = func;
|
WriteImageData = func;
|
||||||
write_image_user_data_ = user_data;
|
write_image_user_data_ = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
static void WriteToMemory_stbi(void *context, void *data, int size) {
|
static void WriteToMemory_stbi(void *context, void *data, int size) {
|
||||||
std::vector<unsigned char> *buffer =
|
std::vector<unsigned char> *buffer =
|
||||||
@@ -2483,6 +2502,15 @@ static inline std::wstring UTF8ToWchar(const std::string &str) {
|
|||||||
(int)wstr.size());
|
(int)wstr.size());
|
||||||
return wstr;
|
return wstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline std::string WcharToUTF8(const std::wstring &wstr) {
|
||||||
|
int str_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(),
|
||||||
|
nullptr, 0, NULL, NULL);
|
||||||
|
std::string str(str_size, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), &str[0],
|
||||||
|
(int)str.size(), NULL, NULL);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_FS
|
#ifndef TINYGLTF_NO_FS
|
||||||
@@ -2534,15 +2562,16 @@ bool FileExists(const std::string &abs_filename, void *) {
|
|||||||
|
|
||||||
std::string ExpandFilePath(const std::string &filepath, void *) {
|
std::string ExpandFilePath(const std::string &filepath, void *) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DWORD len = ExpandEnvironmentStringsA(filepath.c_str(), NULL, 0);
|
// Assume input `filepath` is encoded in UTF-8
|
||||||
char *str = new char[len];
|
std::wstring wfilepath = UTF8ToWchar(filepath);
|
||||||
ExpandEnvironmentStringsA(filepath.c_str(), str, len);
|
DWORD wlen = ExpandEnvironmentStringsW(wfilepath.c_str(), nullptr, 0);
|
||||||
|
wchar_t *wstr = new wchar_t[wlen];
|
||||||
|
ExpandEnvironmentStringsW(wfilepath.c_str(), wstr, wlen);
|
||||||
|
|
||||||
std::string s(str);
|
std::wstring ws(wstr);
|
||||||
|
delete[] wstr;
|
||||||
|
return WcharToUTF8(ws);
|
||||||
|
|
||||||
delete[] str;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
||||||
@@ -6198,6 +6227,8 @@ bool TinyGLTF::LoadBinaryFromFile(Model *model, std::string *err,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(TINYGLTF_ENABLE_SERIALIZER)
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// GLTF Serialization
|
// GLTF Serialization
|
||||||
///////////////////////
|
///////////////////////
|
||||||
@@ -7326,8 +7357,8 @@ static void SerializeGltfModel(Model *model, json &o) {
|
|||||||
{
|
{
|
||||||
auto has_khr_lights_punctual = std::find_if(
|
auto has_khr_lights_punctual = std::find_if(
|
||||||
extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) {
|
extensionsUsed.begin(), extensionsUsed.end(), [](const std::string &s) {
|
||||||
return (s.compare("KHR_lights_punctual") == 0);
|
return (s.compare("KHR_lights_punctual") == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (has_khr_lights_punctual == extensionsUsed.end()) {
|
if (has_khr_lights_punctual == extensionsUsed.end()) {
|
||||||
extensionsUsed.push_back("KHR_lights_punctual");
|
extensionsUsed.push_back("KHR_lights_punctual");
|
||||||
@@ -7603,6 +7634,8 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // TINYGLTF_ENABLE_SERIALIZER
|
||||||
|
|
||||||
} // namespace tinygltf
|
} // namespace tinygltf
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
|||||||
Reference in New Issue
Block a user