From 3e922bc40aaf99a096fbb1263ff310911ae27e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20V=C3=A1zquez=20Blanco?= Date: Sat, 11 May 2013 12:30:28 +0200 Subject: [PATCH] Make BinaryLoader work on iOS 4.3.3 and some older browsers. --- examples/js/loaders/BinaryLoader.js | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/examples/js/loaders/BinaryLoader.js b/examples/js/loaders/BinaryLoader.js index ae70d8dfaa..cf93aa3eef 100644 --- a/examples/js/loaders/BinaryLoader.js +++ b/examples/js/loaders/BinaryLoader.js @@ -39,6 +39,9 @@ THREE.BinaryLoader.prototype.loadAjaxJSON = function ( context, url, callback, t 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 ) { @@ -68,8 +71,6 @@ THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binary var xhr = new XMLHttpRequest(), url = binaryPath + "/" + json.buffers; - var length = 0; - xhr.onreadystatechange = function () { if ( xhr.readyState == 4 ) { @@ -78,6 +79,14 @@ THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binary 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