SceneJS import models does not workiwth IE

88 views Asked by At

I am exploring webGL frameworks. I like SceneJS, but there seems to be some compatibility issues with IE. For example, in IE 11, importing the OBJ files freezes up in the online examples:

Here is the link

Any ideas? Or is this good evidence that SceneJS, while interesting, has been suffiently abandoned as a project and I should move to another webGL framework?

1

There are 1 answers

2
adamM On BEST ANSWER

It seems the problem for IE (in my case IE 11), it was not in webGL, but how OBJ file are loaded within SceneJS. SceneJS used a method that does not seem to be compatible with IE.

In obj.js the load() function calls xhr.responseType = "arraybuffer"; This throws an state error in IE that prevents the obj from loading.

An easy solution is to edit the load function in obj.js (around line 75 non minified). Here is the complete function:

         function load(url, ok, error) {
                var xhr = new XMLHttpRequest();
                //xhr.responseType = "arraybuffer";  // chagned
//            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;
                                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);
            }
        })();

By commenting out xhr.responseType = "arraybuffer", it will set the default response type to "text", and then you need to explicitly convert the downloaded text string into an arraybuffer with the Uint8Array function. Seems to work on all browsers I have access to.