I know this has been asked before, and I've read ever question and answer I've been able to find, but nothing works.
I'm running this on a local server (IIS). I'm trying to load an image from imgur and then use that as texture for an object using the code:
var savedImage = /[^?]*$/.exec(location.search)[0];
if (savedImage != "") { savedImageLoad("http://i.imgur.com/" + savedImage + ".jpg"); };
function savedImageLoad(image) {
var mapOverlay = new THREE.ImageUtils.loadTexture(image);
sphere.material = new THREE.MeshBasicMaterial({map: mapOverlay, needsUpdate: true});;
sphere.geometry.buffersNeedUpdate = true;
sphere.geometry.uvsNeedUpdate = true;
}
But it's giving the error:
Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at http://i.imgur.com/uBD0g95.jpg may not be loaded.
I've tried placing THREE.ImageUtils.crossOrigin = "anonymous";
, or some variation of, at the beginning of my code, at the end, and at other various points. I've added a web.config with
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
but that didn't work. This also doesn't work on a site hosted on bitbucket.org, which to me says I'm missing something in my code.
It seems to be failing at the sphere.material = new THREE.MeshBasicMaterial({map: mapOverlay, needsUpdate: true});;
line, as if I comment that out then there's no error (but then the mesh isn't updated).
I'm really at a loss of what else to try here and any help would be appreciated.
question from:
https://stackoverflow.com/questions/24087757/three-js-and-loading-a-cross-domain-image 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…