我如何在没有HTTP服务器的情况下加载一个three.js Blender 2.7导出的模型



嗨,我现在正在做我所有的THREE.js文件:///.

当我按照教程加载模型时,它们会

var myLoader = new THREE.JSONLoader();
myLoader.load( url-path-to-file );

错误:

XMLHttpRequest cannot load file:///C:/.../.../.../testmodel.js. Cross origin requests are only supported for HTTP. three.js:11996
THREE.JSONLoader: "./testmodel.js" seems to be unreachable or the file is empty. three.js:11952
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/.../.../.../testmodel.js'. 

由于使用文件协议的限制,我不能加载这样的东西。我想知道如何跳过这个?我正在考虑将导出的blender存储为JavaScript对象,然后可能已经有一个three。js可以为我完成其余的工作?

从根目录运行python web服务器是我为避免XSS相关错误所做的。我已经在windows中安装了python。

Python version 3 in windows from存放HTML文件的目录etc:

c:Python33python.exe -m http.server

然后将浏览器指向:

http://localhost:8000/yourhtmlfile.html

有关在不同版本的python/OS上运行服务器的更多信息,请参阅这里:

https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally

查看这个小项目。它是一个3D文件查看器,能够在客户端本地加载STL和Collada文件。可在本地和服务器上工作:

https://github.com/yomboprime/Visor3D

从代码中派生一个本地 JSON加载器函数是微不足道的。您可以开始修改loadDAEFile()函数(main.js),它将本地文件读取为文本。

最新更新