SpotLight.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. [page:Object3D] &rarr; [page:Light] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. This light gets emitted from a single point in one direction, along a cone
  14. that increases in size the further from the light it gets. <br /><br />
  15. This light can cast shadows - see the [page:SpotLightShadow] page for
  16. details.
  17. </p>
  18. <h2>Code Example</h2>
  19. <code>
  20. // white spotlight shining from the side, modulated by a texture, casting a shadow
  21. const spotLight = new THREE.SpotLight( 0xffffff );
  22. spotLight.position.set( 100, 1000, 100 );
  23. spotLight.map = new THREE.TextureLoader().load( url );
  24. spotLight.castShadow = true;
  25. spotLight.shadow.mapSize.width = 1024;
  26. spotLight.shadow.mapSize.height = 1024;
  27. spotLight.shadow.camera.near = 500;
  28. spotLight.shadow.camera.far = 4000;
  29. spotLight.shadow.camera.fov = 30;
  30. scene.add( spotLight );
  31. </code>
  32. <h2>Examples</h2>
  33. <p>
  34. [example:webgl_lights_spotlight lights / spotlight ]<br />
  35. [example:webgl_lights_spotlights lights / spotlights ]
  36. </p>
  37. <h2>Constructor</h2>
  38. <h3>
  39. [name]( [param:Integer color], [param:Float intensity], [param:Float distance], [param:Radians angle], [param:Float penumbra], [param:Float decay] )
  40. </h3>
  41. <p>
  42. [page:Integer color] - (optional) hexadecimal color of the light. Default
  43. is 0xffffff (white).<br />
  44. [page:Float intensity] - (optional) numeric value of the light's
  45. strength/intensity. Default is `1`.<br />
  46. [page:Float distance] - Maximum range of the light. Default is `0` (no
  47. limit).<br />
  48. [page:Radians angle] - Maximum angle of light dispersion from its
  49. direction whose upper bound is Math.PI/2.<br />
  50. [page:Float penumbra] - Percent of the spotlight cone that is attenuated
  51. due to penumbra. Takes values between zero and `1`. Default is zero.<br />
  52. [page:Float decay] - The amount the light dims along the distance of the
  53. light.<br /><br />
  54. Creates a new [name].
  55. </p>
  56. <h2>Properties</h2>
  57. <p>See the base [page:Light Light] class for common properties.</p>
  58. <h3>[property:Float angle]</h3>
  59. <p>
  60. Maximum extent of the spotlight, in radians, from its direction. Should be
  61. no more than `Math.PI/2`. The default is `Math.PI/3`.
  62. </p>
  63. <h3>[property:Boolean castShadow]</h3>
  64. <p>
  65. If set to `true` light will cast dynamic shadows. *Warning*: This is
  66. expensive and requires tweaking to get shadows looking right. See the
  67. [page:SpotLightShadow] for details. The default is `false`.
  68. </p>
  69. <h3>[property:Float decay]</h3>
  70. <p>
  71. The amount the light dims along the distance of the light. Default is
  72. `2`.<br />
  73. In context of physically-correct rendering the default value should not be
  74. changed.
  75. </p>
  76. <h3>[property:Float distance]</h3>
  77. <p>
  78. `Default mode` — When distance is zero, light does not attenuate. When
  79. distance is non-zero, light will attenuate linearly from maximum intensity
  80. at the light's position down to zero at this distance from the light.
  81. </p>
  82. <p>
  83. When [page:WebGLRenderer.useLegacyLights legacy lighting mode] is disabled —
  84. When distance is zero, light will attenuate according to inverse-square
  85. law to infinite distance. When distance is non-zero, light will attenuate
  86. according to inverse-square law until near the distance cutoff, where it
  87. will then attenuate quickly and smoothly to `0`. Inherently, cutoffs are
  88. not physically correct.
  89. </p>
  90. <p>Default is `0.0`.</p>
  91. <h3>[property:Float intensity]</h3>
  92. <p>
  93. The light's intensity. Default is `1`.<br />
  94. When [page:WebGLRenderer.useLegacyLights legacy lighting mode] is disabled,
  95. intensity is the luminous intensity of the light measured in candela
  96. (cd).<br /><br />
  97. Changing the intensity will also change the light's power.
  98. </p>
  99. <h3>[property:Boolean isSpotLight]</h3>
  100. <p>Read-only flag to check if a given object is of type [name].</p>
  101. <h3>[property:Float penumbra]</h3>
  102. <p>
  103. Percent of the spotlight cone that is attenuated due to penumbra. Takes
  104. values between zero and `1`. The default is `0.0`.
  105. </p>
  106. <h3>[property:Vector3 position]</h3>
  107. <p>
  108. This is set equal to [page:Object3D.DEFAULT_UP] (0, 1, 0), so that the
  109. light shines from the top down.
  110. </p>
  111. <h3>[property:Float power]</h3>
  112. <p>
  113. The light's power.<br />
  114. When [page:WebGLRenderer.useLegacyLights legacy lighting mode] is disabled,
  115. power is the luminous power of the light measured in lumens (lm).
  116. <br /><br />
  117. Changing the power will also change the light's intensity.
  118. </p>
  119. <h3>[property:SpotLightShadow shadow]</h3>
  120. <p>A [page:SpotLightShadow] used to calculate shadows for this light.</p>
  121. <h3>[property:Object3D target]</h3>
  122. <p>
  123. The Spotlight points from its [page:.position position] to
  124. target.position. The default position of the target is `(0, 0, 0)`.<br />
  125. *Note*: For the target's position to be changed to anything other than the
  126. default, it must be added to the [page:Scene scene] using
  127. <code> scene.add( light.target ); </code>
  128. This is so that the target's [page:Object3D.matrixWorld matrixWorld] gets
  129. automatically updated each frame.<br /><br />
  130. It is also possible to set the target to be another object in the scene
  131. (anything with a [page:Object3D.position position] property), like so:
  132. <code>
  133. const targetObject = new THREE.Object3D();
  134. scene.add(targetObject);
  135. light.target = targetObject;
  136. </code>
  137. The spotlight will now track the target object.
  138. </p>
  139. <h3>[property:Texture map]</h3>
  140. <p>
  141. A [page:Texture] used to modulate the color of the light. The spot light
  142. color is mixed with the RGB value of this texture, with a ratio
  143. corresponding to its alpha value. The cookie-like masking effect is
  144. reproduced using pixel values (0, 0, 0, 1-cookie_value). *Warning*:
  145. [param:SpotLight map] is disabled if [param:SpotLight castShadow] is
  146. *false*.
  147. </p>
  148. <h2>Methods</h2>
  149. <p>See the base [page:Light Light] class for common methods.</p>
  150. <h3>[method:undefined dispose]()</h3>
  151. <p>
  152. Frees the GPU-related resources allocated by this instance. Call this
  153. method whenever this instance is no longer used in your app.
  154. </p>
  155. <h3>[method:this copy]( [param:SpotLight source] )</h3>
  156. <p>
  157. Copies value of all the properties from the [page:SpotLight source] to
  158. this SpotLight.
  159. </p>
  160. <p>
  161. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  162. </p>
  163. </body>
  164. </html>