SpotLightShadow.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:LightShadow] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. 这在SpotLights内部用于计算阴影。
  15. </p>
  16. <h2>代码示例</h2>
  17. <code>
  18. //Create a WebGLRenderer and turn on shadows in the renderer
  19. var renderer = new THREE.WebGLRenderer();
  20. renderer.shadowMap.enabled = true;
  21. renderer.shadowMap.type = THREE.PCFSoftShadowMap; // default THREE.PCFShadowMap
  22. //Create a SpotLight and turn on shadows for the light
  23. var light = new THREE.SpotLight( 0xffffff );
  24. light.castShadow = true; // default false
  25. scene.add( light );
  26. //Set up shadow properties for the light
  27. light.shadow.mapSize.width = 512; // default
  28. light.shadow.mapSize.height = 512; // default
  29. light.shadow.camera.near = 0.5; // default
  30. light.shadow.camera.far = 500 // default
  31. light.shadow.focus = 1; // default
  32. //Create a sphere that cast shadows (but does not receive them)
  33. var sphereGeometry = new THREE.SphereBufferGeometry( 5, 32, 32 );
  34. var sphereMaterial = new THREE.MeshStandardMaterial( { color: 0xff0000 } );
  35. var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
  36. sphere.castShadow = true; //default is false
  37. sphere.receiveShadow = false; //default
  38. scene.add( sphere );
  39. //Create a plane that receives shadows (but does not cast them)
  40. var planeGeometry = new THREE.PlaneBufferGeometry( 20, 20, 32, 32 );
  41. var planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
  42. var plane = new THREE.Mesh( planeGeometry, planeMaterial );
  43. plane.receiveShadow = true;
  44. scene.add( plane );
  45. //Create a helper for the shadow camera (optional)
  46. var helper = new THREE.CameraHelper( light.shadow.camera );
  47. scene.add( helper );
  48. </code>
  49. <h2>构造函数</h2>
  50. <p>构造函数创建一个 [param:PerspectiveCamera PerspectiveCamera] 来管理阴影的世界视图</p>
  51. <h2>属性</h2>
  52. <p>有关常用属性,请参阅基础LightShadow类。</p>
  53. <h3>[property:Camera camera]</h3>
  54. <p>
  55. 在光的世界里。这用于生成场景的深度图;从光的角度来看,其他物体背后的物体将处于阴影中。<br /><br />
  56. 默认值为PerspectiveCamera,近剪裁平面为0.5。 fov将通过更新方法跟踪拥有SpotLight的角度属性。同样,aspect属性将跟踪mapSize的方面。如果设置了灯光的距离属性,则远剪裁平面将跟踪该值,否则默认为500。
  57. </p>
  58. <h3>[property:Number focus]</h3>
  59. <p>
  60. Used to focus the shadow camera. The camera's field of view is set as a percentage of the spotlight's field-of-view. Range is [0, 1]. Default is 1.0.<br/>
  61. </p>
  62. <h2>方法</h2>
  63. <p>有关常用方法,请参阅基础LightShadow类。</p>
  64. <h2>Source</h2>
  65. <p>
  66. [link:https://github.com/mrdoob/three.js/blob/master/src/lights/[name].js src/lights/[name].js]
  67. </p>
  68. </body>
  69. </html>