使用 Three.js 从本地机器加载 OBJ 模型? [英] Loading OBJ model from local machine with Three.js?

查看:43
本文介绍了使用 Three.js 从本地机器加载 OBJ 模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Three.js 加载 OBJ 模型.

I'm trying to load an OBJ model with Three.js.

起初我试过这个:

var loader = new THREE.OBJLoader( );
loader.load( 'chair.obj', function ( object )
{
   scene.add( object );
});

但我收到一条错误消息,说只有 HTTP 支持跨源请求.

But I got an error saying that cross origin request are only supported in HTTP.

我在互联网上寻求帮助,找到了这个页面:https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally

I looked on the internet for help, found this page: https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally

并尝试从 cmd 行运行 Chrome:chrome --allow-file-access-from-files

and tried to run Chrome from cmd line: chrome --allow-file-access-from-files

还是什么都没有.

最后我尝试使用 Python 的内置 Http 服务器.并尝试像这样加载:

Finally I tried using Python's built in Http server. and tried loading like this:

var loader = new THREE.OBJLoader( );
loader.load( 'http://localhost:8000/chair.obj', function ( object )            
{
   scene.add( object );

});

现在场景加载了,但我尝试加载的模型没有显示.在 Chrome 开发工具中,我看到以下错误:

Now the scene loads but the model that I tried to load does not show up. In Chrome Dev tools, I see the following error:

XMLHTTPRequest 无法加载.Access-Control-Allow-Origin 不允许为 null.

XMLHTTPRequest Could not load.Origin null is not allowed by Access-Control-Allow-Origin.

我有桌面 3D 图形方面的专业知识,但我对 JavaScript 和互联网技术完全陌生.我对 Three.js 感到非常兴奋,并且非常有动力去探索它,但我遇到了这些问题.

I have expertise with 3D graphics on the desktop, but I am completely new to JavaScript and internet technology. I'm really excited by Three.js and am really motivated to explore it but I have these kinds of hiccups getting set.

我曾尝试在互联网上查找此内容,但没有成功.我真的需要帮助.我很感激任何人可能对如何解决这个问题的任何指示.

I've tried to look this up on the internet but have not succeeded. I really need help. I'd appreciate any pointers anyone might have on how to get past this.

谢谢

推荐答案

这听起来像是本地运行 Three.js 的 Chrome 安全问题.Firefox 可能会在没有任何额外步骤的情况下显示模型.

This sounds like a Chrome security issue of running three.js locally. Firefox would probably show the model without any additional steps.

要使其正常工作,您需要将此行添加到 Chrome 快捷方式目标

To get this working, you need to add this line to the Chrome shortcut target

--allow-file-access-from-files

所以它在 Windows 上看起来像这样

So it would look something like this on Windows

"C:Program Files (x86)GoogleChromeApplicationchrome.exe" --allow-file-access-from-files

有关此主题的更多信息此处.

There is more information on this topic here.

这篇关于使用 Three.js 从本地机器加载 OBJ 模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆