Using the THREE.Color object

Before we move on to the next light, we're going to look closer at the THREE.Color object. In Three.js, when you need to provide a color (for example, for materials, lights, and so on.) you can pass in a THREE.Color object, or Three.js will create one from a passed-in string value, as we've seen for THREE.AmbientLight. Three.js is very flexible when parsing the input for the THREE.Color constructor. You can create a THREE.Color object in the following ways:

  • Empty constructor: new THREE.Color() will create a white color object.
  • Hex value: new THREE.Color(0xababab) will parse the passed-in hex value and create a color from that. This is the preferred way of creating colors.
  • Hex stringnew THREE.Color("#ababab") ...

Get Learn Three.js - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.