Three.js: Avoid setting crossOrigin when dealing with data urls

Created on 10 Feb 2012  ·  3Comments  ·  Source: mrdoob/three.js

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.

Question

Most helpful comment

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;

All 3 comments

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;

Works perfectly, thanks!

@mrdoob , thanks for the sample above !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrdoob picture mrdoob  ·  84Comments

sunag picture sunag  ·  161Comments

arefin86 picture arefin86  ·  64Comments

arctwelve picture arctwelve  ·  92Comments

ghost picture ghost  ·  81Comments