Skip to main content
Engineering LibreTexts

12.5: Three.js Examples

  • Page ID
    14104
  • Three.js is a JavaScript library for 3D graphics on Web pages, using WebGL and the HTML canvas. It is discussed in Chapter 5. The examples can be found in the folder named threejs, inside the source folder of the web site download. All of the examples use the JavaScript file threejs/three.min.js, which is a “minified” version of the library, not meant for human readers. The original version, threejs/three.js is also available. The version is three.js Release 89. Three.js is an open-source project. It can be downloaded from threejs.org.

    • threejs/full-window.htmlThree.js is typically used to write programs that fill the browser window and continually run an animation. This example shows how to do that, but my other examples do not follow the same pattern. The animation shows colored balls bouncing around inside a translucent box. The user can rotate the scene with the mouse. From Section 5.1.
    • threejs/modeling-starter.html — A starter program for experimenting with building and animating a scene graph model with three.js. The user can rotate the model using the keyboard. It includes a simple example. From Section 5.1.
    • threejs/diskworld-1.html — Shows an animated model of a simple “car” driving around the edge of a disk, with “trees” made from a cylinder and a cone. Based on the previous sample program. From Section 5.1.
    • threejs/MeshFaceMaterial.html — Shows how to use a MeshFaceMaterial on a cube and on a pyramid whose geometry is constructed by hand as an indexed face set. From Section 5.2.
    • threejs/textured-pyramid.html — Shows the same pyramid as the previous example, with a texture. Shows how to define texture coordinates for a three.js geometry. From Section 5.2.
    • threejs/curves-and-surfaces.html — Creates several surfaces using a parametric surface, tube geometry, lathing, and extrusion. From Section 5.2.
    • threejs/json-model-viewer.html — Displays models that are loaded from files in the JSON format used by three.js. I exported one of the models from Blender. The others are from the three.js download. (See the demo c5/mesh-animation.html to see animated versions of two of the models.) From Section 5.2.
    • threejs/anaglyph.html — Uses an AnaglyphEffect to show a scene meant to be viewed with red/cyan 3D glasses. Aside from the anaglyph effect, the program is a copy of threejs/full-window.html. From Section 5.3.
    • threejs/skybox.html — Demonstrates using a cubemap texture to make a skybox. From Section 5.3.
    • threejs/reflection.html — A demonstration of using an environment map to simulate the reflection by an object of its environment. The environment is a skybox. From Section 5.3.
    • threejs/refraction.html — A demonstration of simulated refraction. This example is almost identical to the previous example, except for using refraction rather than reflection. From Section 5.3.