javascript - 如何使用 Three.js 加载 VRML 模型 (wrl)

标签 javascript 3d three.js vrml

我正在尝试使用 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/

相关文章:

javascript - 有没有办法在 Three.js 中制作小 Canvas ?

javascript - 单击说明该场景的图像后显示 Three.js 场景

javascript - 使用 momentjs 获取给定日期的开始时间

javascript - QuotaExceededError (DOM Exception 22) : The quota has been exceeded on Safari in incognito

opengl - 除了游戏/电影/图片之外,计算机图形还有实际用途吗?

wordpress - WordPress 网站上的 Three.js JavaScript 3D 库

c++ - 尝试从 OpenGL 中的 .object 绘制网格时不显示某些三角形

three.js - 将物体放置在同一高度

php - 如何通过 PHP 获取浏览器渲染后计算出的图像宽度?

javascript - System.config() 调用 <head> 或 <body>?