mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-10 03:29:01 +08:00
Consider Data URI buffers in binary. Fixes #79.
This commit is contained in:
parent
81bbf86e2a
commit
39abfb5f91
BIN
models/box01.glb
Normal file
BIN
models/box01.glb
Normal file
Binary file not shown.
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
18
tiny_gltf.h
18
tiny_gltf.h
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user