我正在编写一个使用纹理的 WebGL - Three.js 应用程序,并且一直在使用http://stemkoski.github.com/Three.js/上的教程。当我尝试在本地运行页面时,出现以下错误。
Uncaught TypeError: Cannot read property 'map' of undefined Three.js:2728
Cross-origin image load denied by Cross-Origin Resource Sharing policy. index.html:1
Uncaught TypeError: Cannot read property 'attributes' of undefined Three.js:3600
Cross-origin image load denied by Cross-Origin Resource Sharing policy. index.html:1
Uncaught TypeError: Cannot read property 'attributes' of undefined Three.js:3600
Uncaught TypeError: Cannot read property 'attributes' of undefined Three.js:3600
我知道跨域资源共享策略与在本地使用图像有关。但是,即使在使用目标打开的 Chrome 窗口中,它仍然会发生:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
我可以使用过时的开关吗?我所做的是通过快捷方式打开 Chrome 浏览器,然后查看地址历史记录以查找我的 index.html 文件的位置。
这是我编写的一些代码,以及我认为与手头的问题最相关的代码。
var materialArray = [];
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-xpos.png" ) } ) );
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-xneg.png" ) } ) );
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-ypos.png" ) } ) );
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-yneg.png" ) } ) );
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-zpos.png" ) } ) );
materialArray.push( new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( "img/skybox-zneg.png" ) } ) );
for ( var i = 0; i < 6; i++ )
{
materialArray[ i ].side = THREE.BackSide;
}
var skyboxMaterial = new THREE.MeshFaceMaterial( materialArray );
var skyboxGeom = new THREE.CubeGeometry( 5000, 5000, 5000, 1, 1, 1 );
ShapeShifter.skybox = new THREE.Mesh( skyboxGeom, skyboxMaterial );
ShapeShifter.scene.add( ShapeShifter.skybox );
我认为这个问题:Problems with MeshFaceMaterial since revision 54(Update 2)也可能与我面临的问题有关,但是,我不确定如何实现答案。对 THREE.GeometryUtils.setMaterialIndex 的调用会去哪里?
谢谢你的帮助。