Three.js: GLTFExporter: glb downloads corrupt on MS Edge

Created on 20 Nov 2017  路  5Comments  路  Source: mrdoob/three.js

When using the GLTFExporter demo and exporting a binary (.glb) file from MSEdge, the resulting model cannot be viewed in https://gltf-viewer.donmccurdy.com/ (using any browser). Same problem is happening for .glb models downloaded from https://gltf-trees.donmccurdy.com/. Also tried swapping out the download code for downloadjs, no effect.

Example of corrupted file: https://github.com/donmccurdy/three-gltf-viewer/files/1486071/tree.zip

Downloads are working as expected from Chrome, Safari, and Firefox.

@bghgary @sbtron I am wondering if Edge handles the application/octet-stream mimeType vs .glb extension differently?

Most helpful comment

BTW: At least Microsoft is working on an implementation of TextDecoder 馃槉

https://developer.microsoft.com/en-us/microsoft-edge/platform/status/encodingstandard/

All 5 comments

^This only applies to downloads initiated by JS, like this. Downloading files from a server works normally.

The JSON chunk contains null bytes. If I remove those during parsing, the model loads correctly.

JSON.parse(jsonContent); // fails

const re = new RegExp(decodeURIComponent('%00'), 'g');
jsonContent = jsonContent.replace(re, '');

JSON.parse(jsonContent); // works

But, it still seems like a strange case in MS Edge that this would be necessary. 馃槙

I only have IE11 to test this on, but my Chrome supports TextEncoder while my IE11 does not.
From GLTFExporter.js:

function stringToArrayBuffer( text ) {

    if ( window.TextEncoder !== undefined ) {

        return new TextEncoder().encode( text ).buffer;

    }

    var buffer = new ArrayBuffer( text.length * 2 ); // 2 bytes per character.

    var bufferView = new Uint16Array( buffer );

    for ( var i = 0; i < text.length; ++ i ) {

        bufferView[ i ] = text.charCodeAt( i );

    }

    return buffer;

}

Chrome's TextEncoder has a default encoding of UTF-8, the code above (which IE would then execute) goes for UTF-16 (sorta?). That could explain the 0x00 bytes in the JSON.

Nice find, thanks! Edge doesn't support TextEncoder either, and if I replace that with a Uint8Array everything works. So that definitely looks like the issue. 馃槄

BTW: At least Microsoft is working on an implementation of TextDecoder 馃槉

https://developer.microsoft.com/en-us/microsoft-edge/platform/status/encodingstandard/

Was this page helpful?
0 / 5 - 0 ratings