我正在学习 Three.js。我已将对象的 .obj 文件转换为 .js 文件,并使用 JSONLoader 加载该对象。它显示在 Firefox 浏览器上。但它在控制台中显示 javascript 异常,如下所示:
not well-formed Porsche_911_GT2.js:1:1
与我在 Chrome 浏览器上运行的代码相同。但有对象没有显示。控制台出现如下错误:
XMLHttpRequest cannot load file:///C:/Users/inwindow/Desktop/webGL/myTHREE.js/obj/car/Porsche_911_GT2.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. three.min.js:263
THREE.JSONLoader: "obj/car/Porsche_911_GT2.js" seems to be unreachable or the file is empty. three.min.js:262
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/inwindow/Desktop/webGL/myTHREE.js/obj/car/Porsche_911_GT2.js'. three.min.js:263
为什么会发生这种情况?有人可以帮我吗?
最佳答案
将 Porsche_911_GT2.js 的本地服务器相对 URL 提供给 JSONLoader。 它不适用于文件协议(protocol)... 它应该位于服务器上并且可以通过 http 或 https 协议(protocol)访问。
关于JavaScript异常: "not well-formed" on firefox browser and "XMLHttpRequest.." error on chrome browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29232145/