From 9df05806adcbd81453dd6a94fd46a5f702cf3ffd Mon Sep 17 00:00:00 2001 From: viperscape Date: Wed, 5 Dec 2018 14:11:01 -0500 Subject: [PATCH] find missing bufferView target types and fill them in --- tiny_gltf.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tiny_gltf.h b/tiny_gltf.h index c9203cf..b62eb8f 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -3479,6 +3479,29 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, } } + // Assign missing bufferView target types + // - Look for missing Mesh indices + // - Look for missing bufferView targets + for (auto &mesh : model->meshes) + { + for (auto &primitive : mesh.primitives) + { + if (primitive.indices > -1) // has indices from parsing step, must be Element Array Buffer + { + model->bufferViews[primitive.indices].target = TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; + // we could optionally check if acessors' bufferView type is Scalar, as it should be + } + } + } + // find any missing targets, must be an array buffer type if not fulfilled from previous check + for (auto &bufferView : model->bufferViews) + { + if (bufferView.target == 0) // missing target type + { + bufferView.target = TINYGLTF_TARGET_ARRAY_BUFFER; + } + } + // 7. Parse Node { json::const_iterator rootIt = v.find("nodes");