|
13 | 13 | <h1>[name]</h1> |
14 | 14 |
|
15 | 15 | <div class="desc"> |
16 | | - Affects objects using [page:MeshLambertMaterial] or [page:MeshPhongMaterial]. |
| 16 | + A light that gets emitted in a specific direction. This light will behave as though it is |
| 17 | + infinitely far away and the rays produced from it are all parallel. The common use case |
| 18 | + for this is to simulate daylight; the sun is far enough away that its position can be |
| 19 | + considered to be infinite, and all light rays coming from it are parallel.<br /><br /> |
| 20 | + |
| 21 | + This light can cast shadows - see the [page:DirectionalLightShadow] page for details. |
| 22 | + </div> |
| 23 | + |
| 24 | + <h2>A Note about Position, Target and rotation</h2> |
| 25 | + <div> |
| 26 | + A common point of confusion for directional lights is that setting the rotation has no effect. |
| 27 | + This is because Three's DirectionalLight is the equivalent to what is often called a 'Target |
| 28 | + Direct Light' in other applications.<br /><br /> |
| 29 | + |
| 30 | + This means that its direction is calculated as pointing |
| 31 | + from the light's [page:Object3D.position position] to the [page:.target target]'s position |
| 32 | + (as opposed to a a 'Free Direct Light' that just has a rotation component).<br /><br /> |
| 33 | + |
| 34 | + The reason for this is to allow the light to cast shadows - the [page:.shadow shadow] |
| 35 | + camera needs a position to calculate shadows from.<br /><br /> |
| 36 | + |
| 37 | + See the [page:.target target] property below for details on updating the target. |
17 | 38 | </div> |
18 | 39 |
|
19 | 40 |
|
20 | 41 | <h2>Example</h2> |
21 | | - <div>[example:canvas_morphtargets_horse morphtargets / horse ]</div> |
22 | | - <div>[example:misc_controls_fly controls / fly ]</div> |
23 | | - <div>[example:misc_lights_test lights / test ]</div> |
24 | | - <div>[example:vr_cubes cubes ]</div> |
25 | | - <div>[example:webgl_effects_parallaxbarrier effects / parallaxbarrier ]</div> |
26 | | - <div>[example:webgl_effects_stereo effects / stereo ]</div> |
27 | | - <div>[example:webgl_geometry_extrude_splines geometry / extrude / splines ]</div> |
28 | | - <div>[example:webgl_materials_bumpmap materials / bumpmap ]</div> |
29 | | - <div>[example:webgl_materials_cubemap_balls_reflection materials / cubemap / balls / reflection ]</div> |
30 | | - |
31 | | - <code>// White directional light at half intensity shining from the top. |
| 42 | + <div> |
| 43 | + [example:canvas_morphtargets_horse morphtargets / horse ]<br /> |
| 44 | + [example:misc_controls_fly controls / fly ]<br /> |
| 45 | + [example:misc_lights_test lights / test ]<br /> |
| 46 | + [example:vr_cubes cubes ]<br /> |
| 47 | + [example:webgl_effects_parallaxbarrier effects / parallaxbarrier ]<br /> |
| 48 | + [example:webgl_effects_stereo effects / stereo ]<br /> |
| 49 | + [example:webgl_geometry_extrude_splines geometry / extrude / splines ]<br /> |
| 50 | + [example:webgl_materials_bumpmap materials / bumpmap ]<br /> |
| 51 | + [example:webgl_materials_cubemap_balls_reflection materials / cubemap / balls / reflection ] |
| 52 | + </div> |
32 | 53 |
|
| 54 | + <code> |
| 55 | +// White directional light at half intensity shining from the top. |
33 | 56 | var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 ); |
34 | 57 | directionalLight.position.set( 0, 1, 0 ); |
35 | | -scene.add( directionalLight );</code> |
| 58 | +scene.add( directionalLight ); |
| 59 | + </code> |
36 | 60 |
|
37 | 61 |
|
38 | 62 | <h2>Constructor</h2> |
39 | 63 |
|
40 | 64 | <h3>[name]( [page:Integer hex], [page:Float intensity] )</h3> |
41 | 65 | <div> |
42 | | - [page:Integer hex] -- Numeric value of the RGB component of the color. <br /> |
43 | | - [page:Float intensity] -- Numeric value of the light's strength/intensity. |
44 | | - </div> |
45 | | - <div> |
46 | | - Creates a light that shines from a specific direction not from a specific position. This light will behave |
47 | | - as though it is infinitely far away and the rays produced from it are all parallel. The best |
48 | | - analogy would be a light source that acts like the sun: the sun is so far away that all sunlight |
49 | | - hitting objects comes from the same angle. |
| 66 | + [page:Integer color] - (optional) hexadecimal color of the light. Default is 0xffffff (white).<br /> |
| 67 | + [page:Float intensity] - (optional) numeric value of the light's strength/intensity. Default is 1.<br /><br /> |
| 68 | + |
| 69 | + Creates a new [name]. |
50 | 70 | </div> |
51 | 71 |
|
52 | 72 | <h2>Properties</h2> |
53 | 73 |
|
54 | 74 | See the base [page:Light Light] class for common properties. |
55 | 75 |
|
56 | | - <h3>[property:Object3D target]</h3> |
| 76 | + <h3>[property:Boolean castShadow]</h3> |
57 | 77 | <div> |
58 | | - Target used for shadow camera orientation. |
| 78 | + If set to *true* light will cast dynamic shadows. *Warning*: This is expensive and |
| 79 | + requires tweaking to get shadows looking right. See the [page:DirectionalLightShadow] for details. |
| 80 | + The default is *false*. |
| 81 | + </div> |
| 82 | + |
| 83 | + <h3>[property:Boolean isDirectionalLight]</h3> |
| 84 | + <div> |
| 85 | + Used to check whether this or derived classes are dircrectional lights. Default is *true*.<br /><br /> |
| 86 | + |
| 87 | + You should not change this, as it used internally for optimisation. |
| 88 | + </div> |
| 89 | + |
| 90 | + |
| 91 | + <h3>[property:Vector3 position]</h3> |
| 92 | + <div> |
| 93 | + This is set equal to [page:Object3D.DefaultUp] (0, 1, 0), so that the light shines from the top down. |
59 | 94 | </div> |
60 | 95 |
|
61 | 96 | <h3>[property:DirectionalLightShadow shadow]</h3> |
62 | 97 | <div> |
63 | | - This property stores all relevant information for rendering the shadow of the light.<br /> |
| 98 | + A [page:DirectionalLightShadow] used to calculate shadows for this light. |
64 | 99 | </div> |
65 | 100 |
|
66 | | - <h3>[property:Boolean castShadow]</h3> |
| 101 | + <h3>[property:Object3D target]</h3> |
67 | 102 | <div> |
68 | | - If set to *true* light will cast dynamic shadows. *Warning*: This is expensive and requires tweaking to get shadows looking right.<br /> |
69 | | - Default — *false*. |
| 103 | + The DirectionalLight points from its [page:.position position] to target.position. The default |
| 104 | + position of the target is *(0, 0, 0)*.<br /> |
| 105 | + |
| 106 | + *Note*: For the the target's position to be changed to anything other than the default, |
| 107 | + it must be added to the [page:Scene scene] using |
| 108 | + <code> |
| 109 | + scene.add( light.target ); |
| 110 | + </code> |
| 111 | + |
| 112 | + This is so that the target's [page:Object3D.matrixWorld matrixWorld] gets automatically |
| 113 | + updated each frame.<br /><br /> |
| 114 | + |
| 115 | + It is also possible to set the target to be another object in the scene (anything with a |
| 116 | + [page:Object3D.position position] property), like so: |
| 117 | + <code> |
| 118 | + var targetObject = new THREE.Object3D(); |
| 119 | + scene.add(targetObject); |
| 120 | + |
| 121 | + light.target = targetObject; |
| 122 | + </code> |
| 123 | + The directionalLight will now track the target object. |
70 | 124 | </div> |
71 | 125 |
|
| 126 | + |
| 127 | + |
72 | 128 | <h2>Methods</h2> |
73 | 129 |
|
74 | 130 | See the base [page:Light Light] class for common methods. |
75 | 131 |
|
76 | 132 | <h3>[method:DirectionalLight copy]( [page:DirectionalLight source] )</h3> |
77 | 133 | <div> |
78 | | - <br /> |
79 | | - Copies value of *source* to this DirectionalLight object. |
| 134 | + Copies value of all the properties from the [page:DirectionalLight source] to this |
| 135 | + DirectionalLight. |
80 | 136 | </div> |
81 | 137 |
|
82 | 138 | <h2>Source</h2> |
|
0 commit comments