我正在学习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
为什么会这样?有人能帮帮我吗?
答案 0 :(得分:2)
将您的本地服务器Porsche_911_GT2.js的相对网址提供给JSONLoader。 它不适用于文件协议... 它应该在服务器上,可以通过http或https协议访问。