Threejs 官网 - 怎样执行本地的东西(How to run things locally)

太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的漂亮人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则。出自本博客的文章拒绝转载或再转载,谢谢合作。

Procedural content

If you use just procedural geometries and don't load any textures, webpages should work straight from the file system, just double-click on HTML file in a file manager and it should appear working in the browser (accessed as file:///example).

Content loaded from external files

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.

There are two ways how to solve this:

  1. Change security for local files in a browser (access page as file:///example)

  2. Run files from a local server (access page as http://localhost/example)

If you use option 1, be aware that you may open yourself to some vulnerabilities if using the same browser for a regular web surfing. You may want to create a separate browser profile / shortcut used just for local development to be safe.


Change local files security policy

Safari

Enable the develop menu using the preferences panel, under Advanced -> "Show develop menu in menu bar"

Then from the safari "Develop" menu, select "Disable local file restrictions", it is also worth noting safari has some odd behaviour with caches, so it is advisable to use the "Disable caches" option in the same menu; if you are editing & debugging using safari.

Chrome

Close all running chrome instances first. Then start Chrome executable with a command line flag:

chrome --allow-file-access-from-files

On Windows, the easiest is probably to create a special shortcut which has added flag (right-click on shortcut -> properties -> target).

Firefox

  1. Go to about:config
  2. Find security.fileuri.strict_origin_policy parameter
  3. Set it to false

Run local server

The simplest probably is to use Python's built-in http server.

If you have Python installed, it should be enough to run this from a command line:

# Python 2.x
python -m SimpleHTTPServer
# Python 3.x
python -m http.server

This will serve files from the current directory at localhost under port 8000:

http://localhost:8000/

If you have Ruby installed, you can get the same result running this instead:

ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"

PHP also has a built-in web server, starting with php 5.4.0:

php -S localhost:8000

Node.js has a simple HTTP server package. To install:

npm install http-server -g

To run:

http-server .

Other simple alternatives are discussed here on Stack Overflow.

Of course, you can use any other regular full-fledged web server like Apache or nginx.

Example with lighttpd, which is a very lightweight general purpose webserver (on MAC OSX):

  1. Install it via homebrew brew install lighttpd
  2. Create a configuration file called lighttpd.conf in the directory where you want to run your webserver. There is a sample in this page.
  3. In the conf file, change the server.document-root with the directory you want to serve
  4. Start it with lighttpd -f lighttpd.conf
  5. Navigate to http://localhost:3000/ and it will serve static files from the directory you chose.

Threejs 官网 - 怎样执行本地的东西(How to run things locally)的更多相关文章

  1. Threejs 官网 - Three.js 的图形用户界面工具(GUI Tools with Three.js)

    Threejs 官网 - Three.js 的图形用户界面工具(GUI Tools with Three.js) 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) ...

  2. Scrapy官网程序执行示例

    Windows 10家庭中文版本,Python 3.6.4,Scrapy 1.5.0, Scrapy已经安装很久了,前面也看了不少Scrapy的资料,自己尝试使其抓取微博的数据时,居然连登录页面(首页 ...

  3. [微软官网] SQLSERVER 执行页面还原

    执行页面还原 https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2008-r2/ms175168(v=sql.105) ...

  4. browsersync按照官网,然后本地配置后,动态监听时不起作用

    官方API也未曾标注,要添加文件指向 --files 所以解决方案就是: browser-sync start --proxy "tp5.cn" --files "css ...

  5. maven向本地仓库导入jar包(处理官网没有的jar包)

    对于官网没有的jar包,maven向本地仓库导入jar包用如下命令 mvn install:install-file -DgroupId=包名 -DartifactId=项目名 -Dversion=版 ...

  6. 新手也能学会本地调试微信,natapp 官网映射

    本地调试微信的新手指引~ 照着配置,一定可以配置成功,实现本地调试微信,公司好几个同事按照我写的步骤,都独立配成功了. 1.首选在natapp注册一个账号,申请免费隧道或者购买隧道,我买了一个月9元的 ...

  7. APOC官网触发器示例执行后Web页面一直转圈

    apoc使用触发器:如apoc官网指导 CREATE (d:Person {name:'Daniel'}) CREATE (l:Person {name:'Mary'}) CREATE (t:Pers ...

  8. Threejs实现滴滴官网首页地球动画

    .katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...

  9. Linux小项目/rhel-基于同步官网yum仓库数据搭建本地yum服务器

    本文的实验环境:aws上的Redhat 7.x , 同样也适用于Centos 7.x 简单说主要分为三步: (1) 向官网同步yum数据,可以根据具体情况,创建脚本及配置周期例行任务  (2) 搭建w ...

随机推荐

  1. 开源DDos 机器学习思路求解的一些源码——TODO 待分析

    一些源码:https://github.com/elbaulp/MafDet System that aims to detect and mitigate DDoS attacks using Ma ...

  2. CodeForces 131C C (组合)

    There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory" ...

  3. golang 初体验

    1.下载golang https://code.google.com/p/go/downloads/list 在windows下安装,下载windows32版本 2.安装 安装完毕,默认在C:\Go ...

  4. 使用autofac在mvc5下依赖注入

    把遇到的问题汇总一下: 一.安装mvc5版本 命令:pm> Install-Package Autofac 结果安装的Autofac.Integration.Mvc(版本为4.0),所引用的依赖 ...

  5. Session版购物车+MVC局部刷新

     效果图: 大致代码: <script type="text/javascript"> $(function () { LoadOrderDetailList(); } ...

  6. (转载)RxJava 与 Retrofit 结合的最佳实践

    RxJava 与 Retrofit 结合的最佳实践 作者:tough1985 感谢 DaoCloud 为作者提供的 500 RMB 写作赞助: 成为赞助方 /开始写作 前言 RxJava和Retrof ...

  7. 腾讯云TrustAsia DV SSL CA证书的申请及使用

    1.证书申请及管理     对于已经拥有域名及公网服务器的用户,可以通过腾讯云申请TrustAsia DV SSL CA证书,证书申请流程包含填写基本信息和域名认证两步,非常清晰和简单,没有什么需要过 ...

  8. epoll的实现与深入思考

    提契 纸上得来终觉浅,绝知此事要躬行. 正文 前段时间写了一篇epoll的学习文章,但没有自己的心得总觉得比较肤浅,花了一些时间补充一个epoll的实例,并浅析一下过程中遇到的问题. 上epoll_s ...

  9. (转)基于MVC4+EasyUI的Web开发框架经验总结(2)- 使用EasyUI的树控件构建Web界面

    http://www.cnblogs.com/wuhuacong/p/3669575.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...

  10. VS2008中C++打开Excel(MFC)

    VS2008中C++打开Excel(MFC)——摘自网络,并加以细化 第一步:建立project(新建项目) 英文版 中文版 选择C++下的MFC Application(基于对话框的项目) 英文版 ...