Capítulo 105 de 859

Chapter 105: DirectionalLight

Core Idea

A light that gets emitted in a specific direction. This light will behave as though it is infinitely far away and the rays produced from it are all parallel. The common use case for this is to simulate daylight; the sun is far enough away that its position can be considered to be infinite, and all light rays coming from it are parallel.

A common point of confusion for directional lights is that setting the rotation has no effect. This is because three.js's DirectionalLight is the equivalent to what is often called a 'Target Direct Light' in other applications.

This means that its direction is calculated as pointing from the light's Object3D#position to the DirectionalLight#target position (as opposed to a 'Free Direct Light' that just has a rotation component).

This light can cast shadows - see the DirectionalLightShadow for details.

Key Concepts

  • isDirectionalLight : boolean (readonly): This flag can be used for type testing.
  • shadow : DirectionalLightShadow: This property holds the light's shadow configuration.
  • target : Object3D: The directional light points from its position to the target's position.

Code Examples

// White directional light at half intensity shining from the top.
const directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
scene.add( directionalLight );
  • What it demonstrates: Typical usage of DirectionalLight.

Reference Tables

Constructor

Signature
`new DirectionalLight( color : number

Properties

PropertyDescription
.isDirectionalLight : boolean (readonly)This flag can be used for type testing.
.shadow : DirectionalLightShadowThis property holds the light's shadow configuration.
.target : Object3DThe directional light points from its position to the target's position.

Key Takeaways

  1. DirectionalLight extends: EventDispatcher → Object3D → Light
  2. Most relevant properties: isDirectionalLight, shadow, target.

Connects To