BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Color.setHex()

The Color.setHex() method is used to set the color of a material or object by its hexadecimal color code.

Parameters

Color.setHex(hex: number)

  • hex : A hexadecimal color code, represented as an integer.

Example

// 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.

Notes

  • The hex parameter must be a valid hexadecimal color code.
  • The 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.
  • The Color.setHex() method can also be used in conjunction with other color-related methods of THREE.js, such as Color.getHexString().