From c4044fbff207ba4fdeb5765f114a3e19b11cf489 Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sat, 23 Apr 2022 21:51:59 +0200 Subject: [PATCH] VOXELFORMAT: apply index offset this is always zero in current cases --- src/modules/voxelformat/GLTFFormat.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/modules/voxelformat/GLTFFormat.cpp b/src/modules/voxelformat/GLTFFormat.cpp index e0938db37..92062b39a 100644 --- a/src/modules/voxelformat/GLTFFormat.cpp +++ b/src/modules/voxelformat/GLTFFormat.cpp @@ -411,9 +411,9 @@ const tinygltf::Accessor *GLTFFormat::getGltfAccessor(const tinygltf::Model &mod namespace gltf_priv { template -void copyGltfIndices(const uint8_t *data, size_t count, size_t stride, core::DynamicArray &indices) { +void copyGltfIndices(const uint8_t *data, size_t count, size_t stride, core::DynamicArray &indices, uint32_t offset) { for (size_t i = 0; i < count; i++) { - indices.push_back(*(const T*)data); + indices.push_back((uint32_t)(*(const T*)data) + offset); data += stride; } } @@ -466,24 +466,26 @@ bool GLTFFormat::loadGltfIndices(const tinygltf::Model &model, const tinygltf::P const size_t offset = accessor->byteOffset + bufferView.byteOffset; const uint8_t *indexBuf = buffer.data.data() + offset; + const size_t applyOffset = indices.size(); + switch (accessor->componentType) { case TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; case TINYGLTF_COMPONENT_TYPE_BYTE: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; case TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; case TINYGLTF_COMPONENT_TYPE_SHORT: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; case TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; case TINYGLTF_COMPONENT_TYPE_INT: - gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices); + gltf_priv::copyGltfIndices(indexBuf, accessor->count, stride, indices, applyOffset); break; default: Log::error("Unknown component type for indices: %i", accessor->componentType);