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

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

问题描述

我试图加载OBJ模型Three.js。

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线运行铬:铬--allow文件存取的档案

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

仍然一无所获。

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

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:

XMLHTT prequest无法load.Origin空不受访问控制 - 允许 - 产地允许的。

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.

我想看看这件事在互联网上,但没有成功。 我真的需要帮助。我AP preciate任何指针人可能对如何突破这个。

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浏览器的安全问题。火狐可能会显示出模型,而无需任何额外的步骤。

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

- 让文件存取的档案

因此​​,这将是这个样子的Windows

So it would look something like this on Windows

C:\ Program Files文件(x86)的\谷歌\浏览器\应用程序\的chrome.exe--allow文件存取的档案

还有这里更多信息一>

There is more information on this topic here.

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

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