我正在尝试使用 Three.js 加载 VRML 模型,但我的代码似乎无法正常工作,并且无法在网页上显示 3D 模型。我的代码有问题吗?
var loader = new THREE.VRMLLoader();
loader.load('./Bluegg/Bluegg/Bluegg.wrl', function(object){
alert(object);
scene.add(object);
});
并且错误消息显示
无法加载 file:///C:/Users/ninom/Desktop/takahiro_note/3DJS/Bluegg/Bluegg/Bluegg.wrl:仅协议(protocol)方案支持跨源请求:http、data、chrome、chrome-扩展名,https。
这个消息是什么意思?感谢您抽出宝贵时间。
最佳答案
来自 how to run things locally 的文档部分-
If you load models or textures from external files, due to browsers' same origin policy security restrictions, loading from a file system will fail with a security exception.
如果您的页面使用 file://
URL,则它会如上所述从文件系统加载。要解决此问题,您需要运行本地服务器。有很多快速方法可以完成文档中提到的操作。我喜欢的一个安装了 Node.js v6+ 的版本是:
# first time only
npm install -g serve
# start a local server "hosting" the current directory
serve .
关于javascript - 如何使用 Three.js 加载 VRML 模型 (wrl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49724479/