dist/claygl.es.js
function (buffer) {
        var header = new Uint32Array(buffer, 0, 4);
        if (header[0] !== 0x46546C67) {
            this.trigger('error', 'Invalid glTF binary format: Invalid header');
            return;
        }
        if (header[0] < 2) {
            this.trigger('error', 'Only glTF2.0 is supported.');
            return;
        }

        var dataView = new DataView(buffer, 12);

        var json;
        var buffers = [];
        // Read chunks
        for (var i = 0; i < dataView.byteLength;) {
            var chunkLength = dataView.getUint32(i, true);
            i += 4;
            var chunkType = dataView.getUint32(i, true);
            i += 4;

            // json
            if (chunkType === 0x4E4F534A) {
                var arr = new Uint8Array(buffer, i + 12, chunkLength);
                // TODO, for the browser not support TextDecoder.
                var decoder = new TextDecoder();
                var str = decoder.decode(arr);
                try {
                    json = JSON.parse(str);
                }
                catch (e) {
                    this.trigger('error', 'JSON Parse error:' + e.toString());
                    return;
                }
            }
            else if (chunkType === 0x004E4942) {
                buffers.push(buffer.slice(i + 12, i + 12 + chunkLength));
            }

            i += chunkLength;
        }
        if (!json) {
            this.trigger('error', 'Invalid glTF binary format: Can\'t find JSON.');
            return;
        }

        return this.parse(json, buffers);
    }
function (buffer) {
        var header = new Uint32Array(buffer, 0, 4);
        if (header[0] !== 0x46546C67) {
            this.trigger('error', 'Invalid glTF binary format: Invalid header');
            return;
        }
        if (header[0] < 2) {
            this.trigger('error', 'Only glTF2.0 is supported.');
            return;
        }

        var dataView = new DataView(buffer, 12);

        var json;
        var buffers = [];
        // Read chunks
        for (var i = 0; i < dataView.byteLength;) {
            var chunkLength = dataView.getUint32(i, true);
            i += 4;
            var chunkType = dataView.getUint32(i, true);
            i += 4;

            // json
            if (chunkType === 0x4E4F534A) {
                var arr = new Uint8Array(buffer, i + 12, chunkLength);
                // TODO, for the browser not support TextDecoder.
                var decoder = new TextDecoder();
                var str = decoder.decode(arr);
                try {
                    json = JSON.parse(str);
                }
                catch (e) {
                    this.trigger('error', 'JSON Parse error:' + e.toString());
                    return;
                }
            }
            else if (chunkType === 0x004E4942) {
                buffers.push(buffer.slice(i + 12, i + 12 + chunkLength));
            }

            i += chunkLength;
        }
        if (!json) {
            this.trigger('error', 'Invalid glTF binary format: Can\'t find JSON.');
            return;
        }

        return this.parse(json, buffers);
    }
function ( buffer ) { var header = new Uint32Array ( buffer , 0 , 4 ) ; if ( header [ 0 ] !== 0x46546C67 ) { this . trigger ( 'error' , 'Invalid glTF binary format: Invalid header' ) ; return ; } if ( header [ 0 ] < 2 ) { this . trigger ( 'error' , 'Only glTF2.0 is supported.' ) ; return ; } var dataView = new DataView ( buffer , 12 ) ; var json ; var buffers = [ ] ; // Read chunks for ( var i = 0 ; i < dataView . byteLength ; ) { var chunkLength = dataView . getUint32 ( i , true ) ; i += 4 ; var chunkType = dataView . getUint32 ( i , true ) ; i += 4 ; // json if ( chunkType === 0x4E4F534A ) { var arr = new Uint8Array ( buffer , i + 12 , chunkLength ) ; // TODO, for the browser not support TextDecoder. var decoder = new TextDecoder ( ) ; var str = decoder . decode ( arr ) ; try { json = JSON . parse ( str ) ; } catch ( e ) { this . trigger ( 'error' , 'JSON Parse error:' + e . toString ( ) ) ; return ; } } else if ( chunkType === 0x004E4942 ) { buffers . push ( buffer . slice ( i + 12 , i + 12 + chunkLength ) ) ; } i += chunkLength ; } if ( ! json ) { this . trigger ( 'error' , 'Invalid glTF binary format: Can\'t find JSON.' ) ; return ; } return this . parse ( json , buffers ) ; }
Parse glTF binary
@param {ArrayBuffer} buffer
@return {clay.loader.GLTF.Result}
Parse glTF binary