This article mainly introduces to you the relevant information on how to run the three.js Chinese document learning locally. The article introduces it in detail through the example code. It has certain reference learning value for everyone's study or work. Friends who need it Let’s follow the editor to learn together, I hope it can help everyone.
If you are just using procedural geometry and do not need to load any materials, the web page should be loaded directly from the file system. Just double-click the HTML file in the file manager and it should run in your browser (address bar Looks like this: file:///yourFile.html)
Loading content from external files
If you download modules and materials from external files, due to the browser’s same-origin policy Security restrictions will cause a security exception and fail to load.
There are two solutions:
Modify the security of local files in the browser. You can enter the web page like this:
file:///yourFile.html
Run the file from the local web server, you can enter the web page like this:
http://localhost/yourFile.html
If you use the first method, pay attention to what you use The same browser (after modifying the security) will leave itself vulnerable when surfing the Internet normally. You can create a separate browser configuration and shortcuts for local development only to ensure security. Let's look at each method in turn.
Running a local server
Many programming languages have built-in HTTP servers. They don't have the full functionality of Apache or NGINX, but they are sufficient for testing three.js applications.
Node.js Server
There is a simple HTTP server installation package, install:
npm install http-server -g
Run:
http-server -p 8000
Python server
If you have installed Python, run the following command line in your working directory:
//Python 2.x python -m SimpleHTTPServer //Python 3.x python -m http.server
It will go from the current directory to port 80 of localhost to initiate the service. The address bar is like this:
http://localhost:8000/
PHP Server
PHP also has a built-in web server, php 5.4.0 and later:
php -S localhost:8000
Ruby Server
If Once you have this installed, you can run code like:
ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
Lighttpd
It is a very lightweight general purpose web server. Let’s take an OSX system with HomeBrew installed as an example. Unlike the above servers, lighttpd is a mature server product.
Install via homebrew
brew install loghttpd
Create a configuration file named lighttpd.conf where you want to run the web server. Example:
server.document-root = "/var/www/servers/www.example.org/pages/" server.port = 3000 mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png" )
In the configuration file, change server.document-root to the directory you need to serve.
Enable:
lighttpd -f lighttpd.conf
Enter http://localhost:3000/ to serve static files from the directory you choose.
Change the security policy for local files
Safari
Use the preferences panel to turn on developer options: Advanced-> "In the menu The development menu ".
is displayed in the bar and then in Develop-> disable local file restrictions. If you use Safari for editing and debugging, it's worth noting that Safari always behaves strangely with caching, so clicking Disable Cache in the same menu is a wise choice.
chrome
First close all running chrome instances, remember all.
Under Windows, you need to use the process manager to check whether they are all closed. Or, if you see the chrome icon in the system tray, open the right-click menu and click Exit. This should shut down all instances.
Then start the chrome program through the command line flag:
chrome --allow-file-access-from-files
Under Window, the easiest way is to create a special shortcut icon and add the above logo at the end. (Right-click the chrome shortcut-> Properties-> Target)
Firefox
In the address bar, enter about:config
to find security The .fileuri.strict_origin_policy parameter
is set to false
Other simple methods are also discussed in Stack Overflow.
Related recommendations:
JS Library Three.js Basics Introduction
Three.js How to Create a Scene
The above is the detailed content of Detailed explanation of how to run three.js locally. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools