【发布时间】:2014-07-28 01:46:09
【问题描述】:
我知道以前有人问过这个问题,并且我已经阅读过我能够找到的问题和答案,但没有任何效果。
我在本地服务器 (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"; 或一些变体放在我的代码开头、结尾和其他不同的位置。我添加了一个带有
<?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});; 行似乎失败了,好像我将其注释掉然后没有错误(但随后网格未更新)。
我真的不知道还能在这里尝试什么,如果能提供任何帮助,我们将不胜感激。
【问题讨论】:
标签: javascript three.js cross-domain