mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 09:56:06 +08:00
Fix storing uri to Buffer.uri
. Fixes #50.
Fix decoding DataURI with 'data:application/gltf-buffer;base64' mime.
This commit is contained in:
parent
4f0b893d73
commit
20244e1e4e
30
tiny_gltf.h
30
tiny_gltf.h
@ -1282,6 +1282,11 @@ static bool IsDataURI(const std::string &in) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header = "data:application/gltf-buffer;base64,";
|
||||||
|
if (in.find(header) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1329,6 +1334,13 @@ static bool DecodeDataURI(std::vector<unsigned char> *out,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.empty()) {
|
||||||
|
header = "data:application/gltf-buffer;base64,";
|
||||||
|
if (in.find(header) == 0) {
|
||||||
|
data = base64_decode(in.substr(header.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data.empty()) {
|
if (data.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1774,11 +1786,11 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In glTF 2.0, uri is not mandatory anymore
|
// In glTF 2.0, uri is not mandatory anymore
|
||||||
std::string uri;
|
buffer->uri.clear();
|
||||||
ParseStringProperty(&uri, err, o, "uri", false, "Buffer");
|
ParseStringProperty(&buffer->uri, err, o, "uri", false, "Buffer");
|
||||||
|
|
||||||
// having an empty uri for a non embedded image should not be valid
|
// having an empty uri for a non embedded image should not be valid
|
||||||
if (!is_binary && uri.empty()) {
|
if (!is_binary && buffer->uri.empty()) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "'uri' is missing from non binary glTF file buffer.\n";
|
(*err) += "'uri' is missing from non binary glTF file buffer.\n";
|
||||||
}
|
}
|
||||||
@ -1798,9 +1810,9 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
|
|||||||
if (is_binary) {
|
if (is_binary) {
|
||||||
// Still binary glTF accepts external dataURI. First try external resources.
|
// Still binary glTF accepts external dataURI. First try external resources.
|
||||||
|
|
||||||
if (!uri.empty()) {
|
if (!buffer->uri.empty()) {
|
||||||
// External .bin file.
|
// External .bin file.
|
||||||
LoadExternalFile(&buffer->data, err, uri, basedir, bytes, true);
|
LoadExternalFile(&buffer->data, err, buffer->uri, basedir, bytes, true);
|
||||||
} else {
|
} else {
|
||||||
// load data from (embedded) binary data
|
// load data from (embedded) binary data
|
||||||
|
|
||||||
@ -1828,16 +1840,16 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (IsDataURI(uri)) {
|
if (IsDataURI(buffer->uri)) {
|
||||||
if (!DecodeDataURI(&buffer->data, uri, bytes, true)) {
|
if (!DecodeDataURI(&buffer->data, buffer->uri, bytes, true)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "Failed to decode 'uri' : " + uri + " in Buffer\n";
|
(*err) += "Failed to decode 'uri' : " + buffer->uri + " in Buffer\n";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Assume external .bin file.
|
// Assume external .bin file.
|
||||||
if (!LoadExternalFile(&buffer->data, err, uri, basedir, bytes, true)) {
|
if (!LoadExternalFile(&buffer->data, err, buffer->uri, basedir, bytes, true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user