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

yqrashawn picture yqrashawn  路  3Comments

clawconduce picture clawconduce  路  3Comments

alexprut picture alexprut  路  3Comments

Horray picture Horray  路  3Comments

zsitro picture zsitro  路  3Comments