Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid setting crossOrigin when dealing with data urls #1305

Closed
konijn opened this issue Feb 10, 2012 · 3 comments
Closed

Avoid setting crossOrigin when dealing with data urls #1305

konijn opened this issue Feb 10, 2012 · 3 comments
Labels

Comments

@konijn
Copy link

konijn commented Feb 10, 2012

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.

@mrdoob
Copy link
Owner

mrdoob commented Feb 10, 2012

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;

@konijn
Copy link
Author

konijn commented Feb 11, 2012

Works perfectly, thanks!

@remoe
Copy link
Contributor

remoe commented Feb 19, 2012

@mrdoob , thanks for the sample above !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants