UNPKG

3.47 kBTypeScriptView Raw
1import { OrthographicCamera } from "../cameras/OrthographicCamera.js";
2import { LightShadow } from "./LightShadow.js";
3
4/**
5 * This is used internally by {@link DirectionalLight | DirectionalLights} for calculating shadows.
6 * Unlike the other shadow classes, this uses an {@link THREE.OrthographicCamera | OrthographicCamera} to calculate the shadows,
7 * rather than a {@link THREE.PerspectiveCamera | PerspectiveCamera}
8 * @remarks
9 * This is because light rays from a {@link THREE.DirectionalLight | DirectionalLight} are parallel.
10 * @example
11 * ```typescript
12 * //Create a WebGLRenderer and turn on shadows in the renderer
13 * const renderer = new THREE.WebGLRenderer();
14 * renderer.shadowMap.enabled = true;
15 * renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
16 * //Create a DirectionalLight and turn on shadows for the light
17 * const light = new THREE.DirectionalLight(0xffffff, 1);
18 * light.position.set(0, 1, 0); //default; light shining from top
19 * light.castShadow = true; // default false
20 * scene.add(light);
21 * //Set up shadow properties for the light
22 * light.shadow.mapSize.width = 512; // default
23 * light.shadow.mapSize.height = 512; // default
24 * light.shadow.camera.near = 0.5; // default
25 * light.shadow.camera.far = 500; // default
26 * //Create a sphere that cast shadows (but does not receive them)
27 * const sphereGeometry = new THREE.SphereGeometry(5, 32, 32);
28 * const sphereMaterial = new THREE.MeshStandardMaterial({
29 * color: 0xff0000
30 * });
31 * const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
32 * sphere.castShadow = true; //default is false
33 * sphere.receiveShadow = false; //default
34 * scene.add(sphere);
35 * //Create a plane that receives shadows (but does not cast them)
36 * const planeGeometry = new THREE.PlaneGeometry(20, 20, 32, 32);
37 * const planeMaterial = new THREE.MeshStandardMaterial({
38 * color: 0x00ff00
39 * })
40 * const plane = new THREE.Mesh(planeGeometry, planeMaterial);
41 * plane.receiveShadow = true;
42 * scene.add(plane);
43 * //Create a helper for the shadow camera (optional)
44 * const helper = new THREE.CameraHelper(light.shadow.camera);
45 * scene.add(helper);
46 * ```
47 * @see {@link https://threejs.org/docs/index.html#api/en/lights/shadows/DirectionalLightShadow | Official Documentation}
48 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/lights/DirectionalLightShadow.js | Source}
49 */
50export class DirectionalLightShadow extends LightShadow<OrthographicCamera> {
51 /**
52 * Create a new instance of {@link DirectionalLightShadow}
53 */
54 constructor();
55
56 /**
57 * Read-only flag to check if a given object is of type {@link DirectionalLightShadow}.
58 * @remarks This is a _constant_ value
59 * @defaultValue `true`
60 */
61 readonly isDirectionalLightShadow: true;
62
63 /**
64 * The light's view of the world.
65 * @remarks This is used to generate a depth map of the scene; objects behind other objects from the light's perspective will be in shadow.
66 * @defaultValue is an {@link THREE.OrthographicCamera | OrthographicCamera} with
67 * {@link OrthographicCamera.left | left} and {@link OrthographicCamera.bottom | bottom} set to -5,
68 * {@link OrthographicCamera.right | right} and {@link OrthographicCamera.top | top} set to 5,
69 * the {@link OrthographicCamera.near | near} clipping plane at 0.5 and
70 * the {@link OrthographicCamera.far | far} clipping plane at 500.
71 */
72 camera: OrthographicCamera;
73}