Threejs official website-How to run things locally (How to run things locally)

Source: Internet
Author: User

Threejs official website-How to run things locally (How to run things locally)

Threejs official website-How to run things locally (How to run things locally)

Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.




How to run local stuff (How to run things locally) nme01 edited this page On 26 Nov 2013· 13 revisions

Procedural content

If you use just procedural geometries and don't load any textures, webpages shocould work straight from the file system, just double-click on HTML file in a file manager and it shoshould appear working in the browser (accessedfile:///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 pagefile:///example)

  2. Run files from a local server (access pagehttp://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 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 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 cut which has added flag (right-click on shortcut-> properties-> target ).

    Firefox
    1. Goabout:config
    2. Findsecurity.fileuri.strict_origin_policyParameter
    3. Set itfalse Run local server

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

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

      # Python 2.xpython -m SimpleHTTPServer
      # Python 3.xpython -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 homebrewbrew 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.doc ument-root with the directory you want to serve
      4. Start itlighttpd -f lighttpd.conf
      5. Navigate to http: // localhost: 3000/and it will serve static files from the directory you chose.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.