From 0067a9e43a60cd3dbdccfad5db33c5b22df63f06 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Mon, 4 Jun 2018 18:26:05 +0900 Subject: [PATCH] Support `gltf-buffer` mime. Make `min` and `max` parameters in `Accessor` optional. --- tiny_gltf_loader.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 6e55276..0389a8d 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -1010,6 +1010,14 @@ static bool IsDataURI(const std::string &in) { return true; } + // NOTE(syoyo) `gltf-buffer` is still in draft as of Jun 4, 2018, + // but some glTF sample model uses `gltf-buffer` so we deal with it. + // https://github.com/KhronosGroup/glTF/pull/1180 + header = "data:application/gltf-buffer;base64,"; + if (in.find(header) == 0) { + return true; + } + header = "data:image/png;base64,"; if (in.find(header) == 0) { return true; @@ -1037,6 +1045,13 @@ static bool DecodeDataURI(std::vector *out, data = base64_decode(in.substr(header.size())); // cut mime string. } + if (data.empty()) { + header = "data:application/gltf-buffer;base64,"; + if (in.find(header) == 0) { + data = base64_decode(in.substr(header.size())); // cut mime string. + } + } + if (data.empty()) { header = "data:image/jpeg;base64,"; if (in.find(header) == 0) { @@ -1662,11 +1677,11 @@ static bool ParseAccessor(Accessor *accessor, std::string *err, accessor->minValues.clear(); accessor->maxValues.clear(); - if(!ParseNumberArrayProperty(&accessor->minValues, err, o, "min", true, "Accessor")) { + if(!ParseNumberArrayProperty(&accessor->minValues, err, o, "min", false, "Accessor")) { return false; } - if(!ParseNumberArrayProperty(&accessor->maxValues, err, o, "max", true, "Accessor")) { + if(!ParseNumberArrayProperty(&accessor->maxValues, err, o, "max", false, "Accessor")) { return false; }