Parse method of GLTFLoader for glbs

I have a problem with using GLTFLoader’s ‘parse’ method. I have my glb file content written in the string. When I try to convert it to the ArrayBuffer and pass to parse method

var buf = new ArrayBuffer(content.length * 2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var j = 0, strLen = content.length; j < strLen; j++) {
      bufView[j] = content.charCodeAt(j);

this.loader.parse(buf, '', function ( gltf ) {

I get an error

Uncaught SyntaxError: Unexpected token g in JSON at position 0 at JSON.parse ()

The same error I have when I just pass the content as the first argument.

Do you use the function incorrectly? Can you help please?

I used gltf-SDK C++ to generate stream and stringstream.str() to convert it to string. In the file you can find the string I use.

file.txt (494.8 KB)

See responses to this thread:

Converting “binary ↔ string” is not something you can do unless you’re sure about the encoding required. I’m not sure what stringstream.str() does but it doesn’t sound right here… can you get a Data URI from the C++ SDK instead? Or a Base64-encoded string? Or (ideally) an actual binary file, which avoids the +33% size overhead of using Base64 strings?

Thank you very much for your response!
The attached thread helped a lot :heart_eyes: