UNPKG

2.95 kBTypeScriptView Raw
1import { Object3D } from "../core/Object3D.js";
2import { DirectionalLight } from "../lights/DirectionalLight.js";
3import { ColorRepresentation } from "../math/Color.js";
4import { Matrix4 } from "../math/Matrix4.js";
5import { Line } from "../objects/Line.js";
6
7/**
8 * Helper object to assist with visualizing a {@link THREE.DirectionalLight | DirectionalLight}'s effect on the scene
9 * @remarks
10 * This consists of plane and a line representing the light's position and direction.
11 * @example
12 * ```typescript
13 * const light = new THREE.DirectionalLight(0xFFFFFF);
14 * scene.add(light);
15 *
16 * const helper = new THREE.DirectionalLightHelper(light, 5);
17 * scene.add(helper);
18 * ```
19 * @see {@link https://threejs.org/docs/index.html#api/en/helpers/DirectionalLightHelper | Official Documentation}
20 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/helpers/DirectionalLightHelper.js | Source}
21 */
22export class DirectionalLightHelper extends Object3D {
23 /**
24 * Create a new instance of {@link DirectionalLightHelper}
25 * @param light The light to be visualized.
26 * @param size Dimensions of the plane. Default `1`
27 * @param color If this is not the set the helper will take the color of the light. Default `light.color`
28 */
29 constructor(light: DirectionalLight, size?: number, color?: ColorRepresentation);
30
31 /**
32 * A Read-only _string_ to check if `this` object type.
33 * @remarks Sub-classes will update this value.
34 * @override
35 * @defaultValue `DirectionalLightHelper`
36 */
37 override readonly type: string | "DirectionalLightHelper";
38
39 /**
40 * Contains the line mesh showing the location of the directional light.
41 */
42 lightPlane: Line;
43
44 /**
45 * Reference to the {@link THREE.DirectionalLight | directionalLight} being visualized.
46 */
47 light: DirectionalLight;
48
49 /**
50 * Reference to the {@link THREE.DirectionalLight.matrixWorld | light.matrixWorld}.
51 */
52 matrix: Matrix4;
53
54 /**
55 * Is set to `false`, as the helper is using the {@link THREE.DirectionalLight.matrixWorld | light.matrixWorld}.
56 * @see {@link THREE.Object3D.matrixAutoUpdate | Object3D.matrixAutoUpdate}.
57 * @defaultValue `false`.
58 */
59 override matrixAutoUpdate: boolean;
60
61 /**
62 * The color parameter passed in the constructor.
63 * @remarks If this is changed, the helper's color will update the next time {@link update} is called.
64 * @defaultValue `undefined`
65 */
66 color: ColorRepresentation | undefined;
67
68 targetLine: Line; // TODO: Double check if this need to be exposed or not.
69
70 /**
71 * Updates the helper to match the position and direction of the {@link light | DirectionalLight} being visualized.
72 */
73 update(): void;
74
75 /**
76 * Frees the GPU-related resources allocated by this instance
77 * @remarks
78 * Call this method whenever this instance is no longer used in your app.
79 */
80 dispose(): void;
81}