Skip to content
This repository has been archived by the owner on Apr 27, 2018. It is now read-only.

Data is already json in parse function #2

Open
Strae opened this issue Sep 12, 2017 · 1 comment
Open

Data is already json in parse function #2

Strae opened this issue Sep 12, 2017 · 1 comment

Comments

@Strae
Copy link

Strae commented Sep 12, 2017

Hey, sorry if I dont provide a patch but im in a bit of hurry
Anyway, file https://raw.githubusercontent.com/antonio-gomez/three-gltf2-loader/master/lib/main.js
Used "as is" with GLTF2 models (downloaded from different sources, like sketchfab) give the error "Uncaught SyntaxError: Unexpected end of JSON input (GLTF2Loader.js:69)"

Solved changed this piece of code:

if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
  extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
  content = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content;
} else {
  content = convertUint8ArrayToString( new Uint8Array( data ) );
}
var json = JSON.parse( content );

into this:

if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
    extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
    content = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content;
    var json = JSON.parse( content );
} else {
  try {
    var json = JSON.parse( data );
  }
  catch ( e ) {
    content = convertUint8ArrayToString( new Uint8Array( data ) );
    var json = JSON.parse( content );
  }
}

(just check if it is already valid Json)

I'll submit a patch in the next days as soon as i'll find some time ;)

@donmccurdy
Copy link

Note that this repository is a mirror of the GLTF(2)Loader file from the threejs repository. I believe this issue has already been fixed in the official copy, you may want to try there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants