Skip to content

Commit

Permalink
Merge pull request #420 from KhronosGroup/fix/uncaught_type_error
Browse files Browse the repository at this point in the history
Fix uncaught type error
  • Loading branch information
UX3D-kanzler authored Nov 4, 2022
2 parents e2c7b8c + c5fe780 commit 75d834d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions source/gltf/accessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class gltfAccessor extends GltfObject
break;
}
}
else if (this.sparse !== undefined)
{
this.typedView = this.createView();
}

if (this.typedView === undefined)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit 75d834d

Please sign in to comment.