Consider Data URI buffers in binary. Fixes #79.

This commit is contained in:
Syoyo Fujita 2018-07-11 02:46:52 +09:00
parent 81bbf86e2a
commit 39abfb5f91
4 changed files with 31 additions and 5 deletions

BIN
models/box01.glb Normal file

Binary file not shown.

View File

@ -28,7 +28,7 @@ def run(filename):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
except:
print "Failed to execute: ", cmd
print("Failed to execute: ", cmd)
raise
if p.returncode != 0:

View File

@ -1,5 +1,6 @@
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "tiny_gltf.h"
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
@ -24,3 +25,18 @@ TEST_CASE("parse-error", "[parse]") {
}
TEST_CASE("datauri-in-glb", "[issue-79]") {
tinygltf::Model model;
tinygltf::TinyGLTF ctx;
std::string err;
bool ret = ctx.LoadBinaryFromFile(&model, &err, "../models/box01.glb");
if (!err.empty()) {
std::cerr << err << std::endl;
}
REQUIRE(true == ret);
}

View File

@ -2260,11 +2260,21 @@ static bool ParseBuffer(Buffer *buffer, std::string *err, const json &o,
size_t bytes = static_cast<size_t>(byteLength);
if (is_binary) {
// Still binary glTF accepts external dataURI. First try external resources.
// Still binary glTF accepts external dataURI.
if (!buffer->uri.empty()) {
// External .bin file.
LoadExternalFile(&buffer->data, err, buffer->uri, basedir, bytes, true, fs);
// First try embedded data URI.
if (IsDataURI(buffer->uri)) {
std::string mime_type;
if (!DecodeDataURI(&buffer->data, mime_type, buffer->uri, bytes, true)) {
if (err) {
(*err) += "Failed to decode 'uri' : " + buffer->uri + " in Buffer\n";
}
return false;
}
} else {
// External .bin file.
LoadExternalFile(&buffer->data, err, buffer->uri, basedir, bytes, true, fs);
}
} else {
// load data from (embedded) binary data