From c5fe780949d8d060357d96041b787a0a48eb6441 Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Thu, 11 Aug 2022 11:20:10 +0200 Subject: [PATCH] Fixes #404 --- source/gltf/accessor.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/gltf/accessor.js b/source/gltf/accessor.js index b52358e0..401475d9 100644 --- a/source/gltf/accessor.js +++ b/source/gltf/accessor.js @@ -88,6 +88,10 @@ class gltfAccessor extends GltfObject break; } } + else if (this.sparse !== undefined) + { + this.typedView = this.createView(); + } if (this.typedView === undefined) { @@ -175,6 +179,10 @@ class gltfAccessor extends GltfObject this.filteredView[i] = dv[func](offset, true); } } + else if (this.sparse !== undefined) + { + this.filteredView = this.createView(); + } if (this.filteredView === undefined) { @@ -188,6 +196,18 @@ class gltfAccessor extends GltfObject return this.filteredView; } + createView() + { + const size = this.count * this.getComponentCount(this.type); + if (this.componentType == GL.BYTE) return new Int8Array(size); + if (this.componentType == GL.UNSIGNED_BYTE) return new Uint8Array(size); + if (this.componentType == GL.SHORT) return new Int16Array(size); + if (this.componentType == GL.UNSIGNED_SHORT) return new Uint16Array(size); + if (this.componentType == GL.UNSIGNED_INT) return new Uint32Array(size); + if (this.componentType == GL.FLOAT) return new Float32Array(size); + return undefined; + } + // getNormalizedDeinterlacedView provides an alternative view to the accessors data, // where quantized data is already normalized. This is useful if the data is not passed // to vertexAttribPointer but used immediately (like e.g. animations)