SpotLight.html 6.5 KB

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