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 -> "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.
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 -> properties -> 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.