SpotLight.html 6.5 KB

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