From 8036d6a00fe7c0c7870de9a3a174286c898c5b72 Mon Sep 17 00:00:00 2001 From: haroonq <29288912+haroonq@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:16:52 +0100 Subject: [PATCH] Allow BufferView indices to be unspecified. Allow BufferView indices for element array buffers to be unspecified to support some extensions. Note that this is similar to how invalid array buffers are handled in order to support, for example, sparse morph targets. --- tiny_gltf.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 2480c83..0b4a1d9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6145,20 +6145,22 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, return false; } - auto bufferView = + const auto bufferView = model->accessors[size_t(primitive.indices)].bufferView; - if (bufferView < 0 || size_t(bufferView) >= model->bufferViews.size()) { + if (bufferView < 0) { + // skip, bufferView could be null(-1) for certain extensions + } else if (size_t(bufferView) >= model->bufferViews.size()) { if (err) { (*err) += "accessor[" + std::to_string(primitive.indices) + "] invalid bufferView"; } return false; + } else { + model->bufferViews[size_t(bufferView)].target = + TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; + // we could optionally check if accessors' bufferView type is Scalar, as + // it should be } - - model->bufferViews[size_t(bufferView)].target = - TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; - // we could optionally check if accessors' bufferView type is Scalar, as - // it should be } for (auto &attribute : primitive.attributes) {