scenejs icon indicating copy to clipboard operation
scenejs copied to clipboard

OBJ impoter does not work in IE - see fix

Open AdamMcM opened this issue 9 years ago • 0 comments

Description of the problem

Loading OBJ files in IE (in my case IE 11) causes a state exception in the Ajax request object. This occurs when, the xhr is set to "arraybuffer". This is a known problem in IE. The work around is to not set xhr to "arraybuffer", but keep its default as "text". Download the file as a string, and then convert it to an arraybuffer before passing it to ok()

Here is the full load() function with comments at the changes.

   function load(url, ok, error) {
            var xhr = new XMLHttpRequest();
            //xhr.responseType = "arraybuffer";  // *** CHNAGED

// xhr.addEventListener('progress', // function (event) { // // TODO: Update the task? { type:'progress', loaded:event.loaded, total:event.total } // }, false); xhr.addEventListener('load', function(event) { if (event.target.response) { var s = event.target.response; // *** CHANGEs HERE!!! var uintArray = new Uint8Array(s.split('').map(function(char) {return char.charCodeAt(0);})); ok(uintArray); } else { error('Invalid file [' + url + ']'); } }, false); xhr.addEventListener('error', function() { error('Couldn't load URL [' + url + ']'); }, false); xhr.open('GET', url, true); xhr.send(null); } })();

SceneJS version
  • [ ] Dev
  • [x ] Master
  • [ ] ...
Browser
  • [] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ x] Internet Explorer
OS
  • [] All of them
  • [ x] Windows
  • [ ] Linux
  • [ ] Android
  • [ ] IOS
Hardware Requirements

AdamMcM avatar Aug 20 '16 20:08 AdamMcM