SpotLight.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. When distance is zero, light will attenuate according to inverse-square
  79. law to infinite distance. When distance is non-zero, light will attenuate
  80. according to inverse-square law until near the distance cutoff, where it
  81. will then attenuate quickly and smoothly to `0`. Inherently, cutoffs are
  82. not physically correct.
  83. </p>
  84. <p>Default is `0.0`.</p>
  85. <h3>[property:Float intensity]</h3>
  86. <p>
  87. The light's luminous intensity measured in candela (cd). Default is `1`.
  88. <br /><br />
  89. Changing the intensity will also change the light's power.
  90. </p>
  91. <h3>[property:Boolean isSpotLight]</h3>
  92. <p>Read-only flag to check if a given object is of type [name].</p>
  93. <h3>[property:Float penumbra]</h3>
  94. <p>
  95. Percent of the spotlight cone that is attenuated due to penumbra. Takes
  96. values between zero and `1`. The default is `0.0`.
  97. </p>
  98. <h3>[property:Vector3 position]</h3>
  99. <p>
  100. This is set equal to [page:Object3D.DEFAULT_UP] (0, 1, 0), so that the
  101. light shines from the top down.
  102. </p>
  103. <h3>[property:Float power]</h3>
  104. <p>
  105. The light's power.<br />
  106. Power is the luminous power of the light measured in lumens (lm).
  107. <br /><br />
  108. Changing the power will also change the light's intensity.
  109. </p>
  110. <h3>[property:SpotLightShadow shadow]</h3>
  111. <p>A [page:SpotLightShadow] used to calculate shadows for this light.</p>
  112. <h3>[property:Object3D target]</h3>
  113. <p>
  114. The Spotlight points from its [page:.position position] to
  115. target.position. The default position of the target is `(0, 0, 0)`.<br />
  116. *Note*: For the target's position to be changed to anything other than the
  117. default, it must be added to the [page:Scene scene] using
  118. <code> scene.add( light.target ); </code>
  119. This is so that the target's [page:Object3D.matrixWorld matrixWorld] gets
  120. automatically updated each frame.<br /><br />
  121. It is also possible to set the target to be another object in the scene
  122. (anything with a [page:Object3D.position position] property), like so:
  123. <code>
  124. const targetObject = new THREE.Object3D();
  125. scene.add(targetObject);
  126. light.target = targetObject;
  127. </code>
  128. The spotlight will now track the target object.
  129. </p>
  130. <h3>[property:Texture map]</h3>
  131. <p>
  132. A [page:Texture] used to modulate the color of the light. The spot light
  133. color is mixed with the RGB value of this texture, with a ratio
  134. corresponding to its alpha value. The cookie-like masking effect is
  135. reproduced using pixel values (0, 0, 0, 1-cookie_value). *Warning*:
  136. [page:.map] is disabled if [page:.castShadow] is *false*.
  137. </p>
  138. <h2>Methods</h2>
  139. <p>See the base [page:Light Light] class for common methods.</p>
  140. <h3>[method:undefined dispose]()</h3>
  141. <p>
  142. Frees the GPU-related resources allocated by this instance. Call this
  143. method whenever this instance is no longer used in your app.
  144. </p>
  145. <h3>[method:this copy]( [param:SpotLight source] )</h3>
  146. <p>
  147. Copies value of all the properties from the [page:SpotLight source] to
  148. this SpotLight.
  149. </p>
  150. <p>
  151. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  152. </p>
  153. </body>
  154. </html>