天天看点

Threejs 官网 - 如何运行本地的东西(How to run things locally) 如何运行本地的东西(How to run things locally) 

Threejs 官网 - 如何运行本地的东西(How to run things locally)

<a target="_blank" href="http://blog.csdn.net/opengl_es">转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。</a>

<a target="_blank" href="http://blog.csdn.net/opengl_es"></a>

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 <code>file:///example</code>).

There are two ways how to solve this:

Change security for local files in a browser (access page as <code>file:///example</code>)

Run files from a local server (access page as <code>http://localhost/example</code>)

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.

Enable the develop menu using the preferences panel, under Advanced -&gt; "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 &amp; debugging using safari.

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

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

Go to <code>about:config</code>

Find <code>security.fileuri.strict_origin_policy</code> parameter

Set it to <code>false</code>

The simplest probably is to use Python's built-in 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:

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

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

To run:

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

Install it via homebrew <code>brew install lighttpd</code>

In the conf file, change the server.document-root with the directory you want to serve

Start it with <code>lighttpd -f lighttpd.conf</code>

Navigate to http://localhost:3000/ and it will serve static files from the directory you chose.