Avoid setting crossOrigin when dealing with data urls

Greetings,

in this piece of code, can we avoid setting d.crossOrigin when we are dealing with a data url ?

THREE.ImageUtils = {crossOrigin: "",loadTexture: function(a, b, c) {
        var d = new Image, e = new THREE.Texture(d, b);
        d.onload = function() {
            e.needsUpdate = !0;
            c && c(this)
        };
        d.crossOrigin = this.crossOrigin;
        d.src = a;
        return e

You can add a check like this:

if( a.substr(0,4) != "data" )
  d.crossOrigin = this.crossOrigin;

this does the trick. Otherwise Chrome 17 throws a Cross-origin image load denied by Cross-Origin Resource Sharing policy for a data url.

T.

Author: Fantashit

1 thought on “Avoid setting crossOrigin when dealing with data urls

  1. Hmm… I think you shouldn’t use ImageUtils.loadTexture in that case. Just do this:

    var image = document.createElement( 'img' );
    image.src = dataurl;
    
    var texture = new THREE.Texture( image );
    texture.needsUpdate = true;

Comments are closed.