mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 11:13:50 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fda7422022 | ||
|
|
decfabd67e | ||
|
|
10b23b6af2 | ||
|
|
fe3cfbe996 | ||
|
|
3b73caa8e8 | ||
|
|
fea6786129 | ||
|
|
fb58f88a4e | ||
|
|
143ff45b61 |
@@ -9,7 +9,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch (b
|
||||
## Status
|
||||
|
||||
Currently TinyGLTF is stable and maintenance mode. No drastic changes and feature additions planned.
|
||||
|
||||
- v2.9.0 Various fixes and improvements. Filesystem callback API change.
|
||||
- v2.8.0 Add URICallbacks for custom URI handling in Buffer and Image. PR#397
|
||||
- v2.7.0 Change WriteImageDataFunction user callback function signature. PR#393
|
||||
- v2.6.0 Support serializing sparse accessor(Thanks to @fynv).
|
||||
|
||||
@@ -1199,4 +1199,51 @@ TEST_CASE("inverse-bind-matrices-optional", "[issue-492]") {
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(err.empty());
|
||||
}
|
||||
}
|
||||
|
||||
bool LoadImageData(tinygltf::Image * /* image */, const int /* image_idx */, std::string * /* err */,
|
||||
std::string * /* warn */, int /* req_width */, int /* req_height */,
|
||||
const unsigned char * /* bytes */, int /* size */, void * /*user_data */) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteImageData(const std::string * /* basepath */, const std::string * /* filename */,
|
||||
const tinygltf::Image *image, bool /* embedImages */,
|
||||
const tinygltf::FsCallbacks * /* fs_cb */, const tinygltf::URICallbacks * /* uri_cb */,
|
||||
std::string * /* out_uri */, void * user_pointer) {
|
||||
REQUIRE(user_pointer != nullptr);
|
||||
auto counter = static_cast<int*>(user_pointer);
|
||||
*counter = *counter + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_CASE("empty-images-not-written", "[issue-495]") {
|
||||
std::string err;
|
||||
std::string warn;
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
|
||||
ctx.SetImageLoader(LoadImageData, nullptr);
|
||||
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
||||
REQUIRE(ok);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
|
||||
CHECK(model.images.size() == 2);
|
||||
for (const auto& image : model.images) {
|
||||
// No data loaded or decoded
|
||||
CHECK(image.image.empty());
|
||||
// The URI is kept
|
||||
CHECK_FALSE(image.uri.empty());
|
||||
// The URI should not be a data URI
|
||||
CHECK(image.uri.find("data:") != 0);
|
||||
}
|
||||
|
||||
// Now write the loaded model
|
||||
int counter = 0;
|
||||
ctx.SetImageWriter(WriteImageData, &counter);
|
||||
ok = ctx.WriteGltfSceneToFile(&model, "issue-495-external.gltf");
|
||||
CHECK(ok);
|
||||
// WriteImageData should be invoked for both images
|
||||
CHECK(counter == 2);
|
||||
}
|
||||
|
||||
32
tiny_gltf.h
32
tiny_gltf.h
@@ -2767,6 +2767,12 @@ bool WriteImageData(const std::string *basepath, const std::string *filename,
|
||||
const Image *image, bool embedImages,
|
||||
const FsCallbacks* fs_cb, const URICallbacks *uri_cb,
|
||||
std::string *out_uri, void *) {
|
||||
// Early out on empty images, report the original uri if the image was not written.
|
||||
if (image->image.empty()) {
|
||||
*out_uri = *filename;
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string ext = GetFilePathExtension(*filename);
|
||||
|
||||
// Write image to temporary buffer
|
||||
@@ -3309,11 +3315,12 @@ static bool UpdateImageObject(const Image &image, std::string &baseDir,
|
||||
filename = std::to_string(index) + "." + ext;
|
||||
}
|
||||
|
||||
// If callback is set and image data exists, modify image data object. If
|
||||
// image data does not exist, this is not considered a failure and the
|
||||
// original uri should be maintained.
|
||||
// If callback is set, modify image data object.
|
||||
// Note that the callback is also invoked for images without data.
|
||||
// The default callback implementation simply returns true for
|
||||
// empty images and sets the out URI to filename.
|
||||
bool imageWritten = false;
|
||||
if (WriteImageData != nullptr && !filename.empty() && !image.image.empty()) {
|
||||
if (WriteImageData != nullptr && !filename.empty()) {
|
||||
imageWritten = WriteImageData(&baseDir, &filename, &image, embedImages,
|
||||
fs_cb, uri_cb, out_uri, user_data);
|
||||
if (!imageWritten) {
|
||||
@@ -4387,7 +4394,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
||||
}
|
||||
} else {
|
||||
// Assume external file
|
||||
// Keep texture path (for textures that cannot be decoded)
|
||||
// Unconditionally keep the external URI of the image
|
||||
image->uri = uri;
|
||||
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
|
||||
return true;
|
||||
@@ -4434,6 +4441,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return LoadImageData(image, image_idx, err, warn, 0, 0, &img.at(0),
|
||||
static_cast<int>(img.size()), load_image_user_data);
|
||||
}
|
||||
@@ -5597,7 +5605,7 @@ static bool ParseAnimation(Animation *animation, std::string *err,
|
||||
}
|
||||
sampler.input = inputIndex;
|
||||
sampler.output = outputIndex;
|
||||
ParseExtrasAndExtensions(&sampler, err, o,
|
||||
ParseExtrasAndExtensions(&sampler, err, s,
|
||||
store_original_json_for_extras_and_extensions);
|
||||
|
||||
animation->samplers.emplace_back(std::move(sampler));
|
||||
@@ -6108,16 +6116,8 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||
}
|
||||
}
|
||||
|
||||
model->buffers.clear();
|
||||
model->bufferViews.clear();
|
||||
model->accessors.clear();
|
||||
model->meshes.clear();
|
||||
model->cameras.clear();
|
||||
model->nodes.clear();
|
||||
model->extensionsUsed.clear();
|
||||
model->extensionsRequired.clear();
|
||||
model->extensions.clear();
|
||||
model->defaultScene = -1;
|
||||
// Reset the model
|
||||
(*model) = Model();
|
||||
|
||||
// 1. Parse Asset
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user