1 | import { Object3D } from "../core/Object3D.js";
|
2 | import { ColorRepresentation } from "../math/Color.js";
|
3 | import { Vector3 } from "../math/Vector3.js";
|
4 | import { DirectionalLightShadow } from "./DirectionalLightShadow.js";
|
5 | import { Light } from "./Light.js";
|
6 |
|
7 | /**
|
8 | * A light that gets emitted in a specific direction
|
9 | * @remarks
|
10 | * This light will behave as though it is infinitely far away and the rays produced from it are all parallel
|
11 | * 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.
|
12 | * A common point of confusion for directional lights is that setting the rotation has no effect
|
13 | * @remarks
|
14 | * This is because three.js's {@link DirectionalLight} is the equivalent to what is often called a 'Target Direct Light' in other applications.
|
15 | * This means that its direction is calculated as pointing from the light's {@link THREE.Object3D.position | position} to the {@link THREE.DirectionalLight.target | target}'s
|
16 | * position (as opposed to a 'Free Direct Light' that just has a rotation component).
|
17 | * See the {@link THREE.DirectionalLight.target | target} property below for details on updating the target.
|
18 | * @example
|
19 | * ```typescript
|
20 | * // White directional light at half intensity shining from the top.
|
21 | * const {@link DirectionalLight} = new THREE.DirectionalLight(0xffffff, 0.5);
|
22 | * scene.add(directionalLight);
|
23 | * ```
|
24 | * @see Example: {@link https://threejs.org/examples/#misc_controls_fly | controls / fly }
|
25 | * @see Example: {@link https://threejs.org/examples/#webgl_effects_parallaxbarrier | effects / parallaxbarrier }
|
26 | * @see Example: {@link https://threejs.org/examples/#webgl_effects_stereo | effects / stereo }
|
27 | * @see Example: {@link https://threejs.org/examples/#webgl_geometry_extrude_splines | geometry / extrude / splines }
|
28 | * @see Example: {@link https://threejs.org/examples/#webgl_materials_bumpmap | materials / bumpmap }
|
29 | * @see {@link https://threejs.org/docs/index.html#api/en/lights/DirectionalLight | Official Documentation}
|
30 | * @see {@link https://github.com/mrdoob/three.js/blob/master/src/lights/DirectionalLight.js | Source}
|
31 | */
|
32 | export class DirectionalLight extends Light<DirectionalLightShadow> {
|
33 | /**
|
34 | * Creates a new {@link DirectionalLight}.
|
35 | * @param color Hexadecimal color of the light. Default `0xffffff` _(white)_.
|
36 | * @param intensity Numeric value of the light's strength/intensity. Expects a `Float`. Default `1`
|
37 | */
|
38 | constructor(color?: ColorRepresentation, intensity?: number);
|
39 |
|
40 | /**
|
41 | * Read-only flag to check if a given object is of type { DirectionalLight}.
|
42 | * This is a _constant_ value
|
43 | * `true`
|
44 | */
|
45 | readonly isDirectionalLight: true;
|
46 |
|
47 | /**
|
48 | * A Read-only _string_ to check if `this` object type.
|
49 | * @remarks Sub-classes will update this value.
|
50 | * @defaultValue `DirectionalLight`
|
51 | */
|
52 | override readonly type: string | "DirectionalLight";
|
53 |
|
54 | /**
|
55 | * Whether the object gets rendered into shadow map.
|
56 | * @remarks
|
57 | * If set to `true` light will cast dynamic shadows.
|
58 | * **Warning**: This is expensive and requires tweaking to get shadows looking right.
|
59 | * @see {@link THREE.DirectionalLightShadow | DirectionalLightShadow} for details.
|
60 | * @defaultValue `false`
|
61 | */
|
62 | override castShadow: boolean;
|
63 |
|
64 | /**
|
65 | * This is set equal to {@link THREE.Object3D.DEFAULT_UP}, so that the light shines from the top down.
|
66 | * @defaultValue {@link Object3D.DEFAULT_UP} _(0, 1, 0)_
|
67 | */
|
68 | override readonly position: Vector3;
|
69 |
|
70 | /**
|
71 | * A {@link THREE.DirectionalLightShadow | DirectionalLightShadow} used to calculate shadows for this light.
|
72 | * @defaultValue `new THREE.DirectionalLightShadow()`
|
73 | */
|
74 | shadow: DirectionalLightShadow;
|
75 |
|
76 | /**
|
77 | * The {@link DirectionalLight} points from its {@link DirectionalLight.position | position} to target.position.
|
78 | * @remarks **Note**: For the target's position to be changed to anything other than the default,
|
79 | * it must be added to the {@link THREE.Scene | scene} using
|
80 | * ```typescript
|
81 | * Scene.add( light.target );
|
82 | * ```
|
83 | * This is so that the target's {@link THREE.Object3D.matrixWorld | matrixWorld} gets automatically updated each frame.
|
84 | *
|
85 | * It is also possible to set the target to be another object in the scene (anything with a {@link THREE.Object3D.position | position} property),
|
86 | * like so:
|
87 | * ```typescript
|
88 | * const targetObject = new THREE.Object3D();
|
89 | * scene.add(targetObject);
|
90 | * light.target = targetObject;
|
91 | * ```
|
92 | * The {@link DirectionalLight} will now track the target object.
|
93 | * @defaultValue `new THREE.Object3D()` at _(0, 0, 0)_
|
94 | */
|
95 | target: Object3D;
|
96 |
|
97 | /**
|
98 | * Frees the GPU-related resources allocated by this instance
|
99 | * @remarks
|
100 | * Call this method whenever this instance is no longer used in your app.
|
101 | */
|
102 | dispose(): void;
|
103 | }
|