在运行three.js开源项目的时候遇到如下的错误,如图:
three.js:34636 Access to XMLHttpRequest at 'file:///Users/mac/three.js-master/examples/models/collada/elf/elf.dae'
from origin 'null' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
load @ three.js:34636
three.js:22676 THREE.WebGLRenderer 104
解决方案
1.解决浏览器跨域问题
参考 Mac上Chrome浏览器跨域解决方案
在浏览器中改变本地文件的安全策略,这将使你可以通过
file:///yourFile.html
2.从本地的服务器运行文件,这可以让你通过
http://localhost/yourFile.html
如何开启本地服务器请参考:Three.js官方文档