问题
How to load cross domain image in textureloader and im getting "Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin..." error
var loader = new THREE.TextureLoader();
loader.load('http://myurl.com/img/box.png', onTextureLoaded);
回答1:
First option
Add a CORS header to the asset, permitting cross-domain requests:
Access-Control-Allow-Origin: *
Second option
You can create a server side proxy, and then load the asset like this
loader.load('myproxy?url=http://myurl.com/img/box.png', onTextureLoaded);
However you need to be careful, as proxies can use up a lot of bandwidth and you need to be very thorough when setting it up so you don't accidentally open your server to some code injection attacks.
来源:https://stackoverflow.com/questions/36883592/load-cross-domain-image-in-texture