- Real-Time 3D Graphics with WebGL 2
- Farhad Ghayour Diego Cantor
- 220字
- 2021-06-10 19:43:01
Time for Action: Loading a Cone with AJAX
Follow the given steps:
- Make sure that your web server is running and access the ch02_07_ajax-cone.html file using your web server.
Web Server Address
You know that you are using the web server if the URL in the address bar starts with localhost/ or 127.0.0.1/ instead of file://.
You know that you are using the web server if the URL in the address bar starts with localhost/ or 127.0.0.1/ instead of file://.
- The folder containing the code for this chapter should look like this:
- Click on ch02_07_ajax-cone.html.
- The example will load in your browser and you will see something similar to this:
- Please review the load functions to better understand the use of AJAX and JSON in the application.
- How is the global model variable used? (Check the source code.)
- Check what happens when you change the color in the common/models/geometries/cone.json file and reload the page.
- Modify the coordinates of the cone in the common/models/geometries/cone.json file and reload the page. Here, you can verify that WebGL reads and renders the coordinates from the file. If you modify them in the file, the geometry will be updated on the screen.
What just happened?
You learned how to use AJAX and JSON to load geometries from a remote location (web server) instead of specifying these geometries (using JavaScript arrays) inside the web page.