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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.