我知道以前有人问过这个问题,我读过我能找到的问题和答案,但没有任何效果。
我在本地服务器 (IIS) 上运行它。我正在尝试从 imgur 加载图像,然后使用代码将其用作对象的纹理:
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;
}
但它给出了错误:
Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at http://i.imgur.com/uBD0g95.jpg may not be loaded.
我试过THREE.ImageUtils.crossOrigin = "anonymous";在我的代码的开头、结尾和其他不同的地方放置或它的一些变体。我添加了一个 web.config
<?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>
但这没有用。这也不适用于托管在 bitbucket.org 上的网站,这对我来说是说我的代码中缺少某些内容。
它似乎在线上失败了sphere.material = new THREE.MeshBasicMaterial({map: mapOverlay, needsUpdate: true});;,就好像我将其注释掉那样就没有错误(但是网格没有更新)。
我真的不知道还有什么可以在这里尝试的,任何帮助将不胜感激。