The Color.setHex()
method is used to set the color of a material or object by its hexadecimal color code.
Color.setHex(hex: number)
hex
: A hexadecimal color code, represented as an integer.// Set the color of a material
var material = new THREE.MeshBasicMaterial();
material.color.setHex(0xff0000); // Sets the material's color to red
// Set the color of an object
var object = new THREE.Mesh();
object.material.color.setHex(0x00ff00); // Sets the color of the object to green
In the above example, we have set the color of a material and an object using the Color.setHex()
method. The hex
parameter represents the hexadecimal color code. In this example, we have used the color codes 0xff0000
and 0x00ff00
to set the material and object color to red and green, respectively.
hex
parameter must be a valid hexadecimal color code.Color.setHex()
method applies the color to the material or object it is called upon. For multiple objects, multiple calls to Color.setHex()
are required.Color.setHex()
method can also be used in conjunction with other color-related methods of THREE.js
, such as Color.getHexString()
.