【发布时间】:2013-01-20 11:11:53
【问题描述】:
我写了一个 webgl 程序,它在本地服务器上运行良好,现在我想在本地运行它。 但是我遇到了错误,经过一些研究,我发现这是加载纹理时的跨域问题。
function loadTexture( path ) {
var texture = new THREE.Texture( texture_placeholder );
var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: true} );
var image = new Image();
image.onload = function () {
texture.needsUpdate = true;
material.map.image = this;
render();
};
texture.deallocate();
renderer3D.deallocateTexture( texture );
return material;
}
我尝试了几种解决方案:
github.com/mrdoob/three.js/issues/1305
github.com/mrdoob/three.js/issues/944
gist.github.com/ekeneijeoma/1186920
github.com/mrdoob/three.js/wiki/How-to-run-things-locally(1.Change security for local files in a browser (access page as file:///example))
我确切地说我在 Firefox 上没有问题,它可以在没有任何改变的情况下工作。 适用于 Chrome 的唯一解决方案是使用 --allow-file-access-from-files 启动它。 在 IE 上,我不知道如何解决它,我在浏览器安全选项中启用了“跨域访问数据源”和“跨不同域导航子框架”(http://msdn.microsoft.com/fr-fr/library/ee797612(v=cs.20).aspx)但没有。我使用 IEWebGL,我注意到在 http://iewebgl.com/,“IEWebGL v1.0 已发布”部分,写着“- 安全(无本地内容加载,无跨域纹理)”。所以也许它不能在 IE 上解决,因为 IEWebGL !?
那么,如果有 IE 的解决方案是什么?有没有办法通过更改代码来解决问题,而无需启动本地服务器或带有特殊选项的 Chrome?
谢谢!
【问题讨论】:
标签: cross-domain three.js webgl