/** * @author alteredq / http://alteredqualia.com/ */ THREE.BinaryLoader = function ( showStatus ) { THREE.Loader.call( this, showStatus ); }; THREE.BinaryLoader.prototype = Object.create( THREE.Loader.prototype ); // Load models generated by slim OBJ converter with BINARY option (converter_obj_three_slim.py -t binary) // - binary models consist of two files: JS and BIN // - parameters // - url (required) // - callback (required) // - texturePath (optional: if not specified, textures will be assumed to be in the same folder as JS model file) // - binaryPath (optional: if not specified, binary file will be assumed to be in the same folder as JS model file) THREE.BinaryLoader.prototype.load = function( url, callback, texturePath, binaryPath ) { // todo: unify load API to for easier SceneLoader use texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url ); binaryPath = binaryPath && ( typeof binaryPath === "string" ) ? binaryPath : this.extractUrlBase( url ); var callbackProgress = this.showProgress ? THREE.Loader.prototype.updateProgress : null; this.onLoadStart(); // #1 load JS part via web worker this.loadAjaxJSON( this, url, callback, texturePath, binaryPath, callbackProgress ); }; THREE.BinaryLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, binaryPath, callbackProgress ) { var xhr = new XMLHttpRequest(); texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url ); binaryPath = binaryPath && ( typeof binaryPath === "string" ) ? binaryPath : this.extractUrlBase( url ); xhr.onreadystatechange = function () { if ( xhr.readyState == 4 ) { if ( xhr.status == 200 || xhr.status == 0 ) { var json = JSON.parse( xhr.responseText ); context.loadAjaxBuffers( json, callback, binaryPath, texturePath, callbackProgress ); } else { console.error( "THREE.BinaryLoader: Couldn't load [" + url + "] [" + xhr.status + "]" ); } } }; xhr.open( "GET", url, true ); xhr.send( null ); }; THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binaryPath, texturePath, callbackProgress ) { var xhr = new XMLHttpRequest(), url = binaryPath + "/" + json.buffers; xhr.onreadystatechange = function () { if ( xhr.readyState == 4 ) { if ( xhr.status == 200 || xhr.status == 0 ) { var buffer = xhr.response; if ( buffer === undefined ) buffer = ( new Uint8Array( xhr.responseBody ) ).buffer; // IEWEBGL needs this if ( buffer.byteLength == 0 ) { // iOS and other XMLHttpRequest level 1 var buffer = new ArrayBuffer( xhr.responseText.length ); var bufView = new Uint8Array( buffer ); for ( var i=0, strLen=xhr.responseText.length; i