Threejs Official website-How do I do local things (how to run things locally)
The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , or else. From this blog article refused to reprint or re-reproduced, thank you for your cooperation.
How do I do local things (how to run things locally) nme01 edited this pageon + Nov· Revisions
Procedural content
If you use just procedural geometries and don ' t load any textures, webpages should work straight from the file system, jus t double-click on HTML file-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 F Rom a file system would fail with a security exception.
There is ways how to solve this:
-
change Security for local files in a browser (Access page As file:///example
)
-
run files from a local server (Access page As http://localhost/example
)
if You use option 1, being aware that you may open yourself to some vulnerabilities If using the same BR Owser for a regular web surfing. Want to create a separate browser profile/shortcut used just for local development to be safe.
Change local Files Security Policysafari
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's also worth noting Safari has some odd Behaviour with caches, so it's 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 are probably to create a special shortcut which have added flag (right-click on shortcut Prope Target, Rties.
Firefox
- Go to
about:config
- Find
security.fileuri.strict_origin_policy
parameter
- 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 is enough to run the from a command line:
# Python 2.xpython-m simplehttpserver
# Python 3.xpython-m http.server
This would serve files from the current directory at localhost under Port 8000:
Http://localhost:8000/
If you have a Ruby installed, you can get the same result running this instead:
"s = webrick::httpserver.new (:P ort = 8000,:D ocumentroot = dir.pwd); Trap (' INT ') {s.shutdown}; S.start "
PHP also have 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 is 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 are a very lightweight general purpose webserver (on MAC OSX):
- Install it via homebrew
brew install lighttpd
- Create a configuration file called lighttpd.conf in the directory where you want to run your webserver. There is a sample on this page.
- In the conf file, change the server.document-root with the directory you want to serve
- Start it with
lighttpd -f lighttpd.conf
- Navigate to Http://localhost:3000/and It'll serve static files from the directory you chose.
Threejs Official website-How do I do local things (how to run things locally)