2
0

DirectionalLight.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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. 平行光是沿着特定方向发射的光。这种光的表现像是无限远,从它发出的光线都是平行的。常常用平行光来模拟太阳光
  14. 的效果; 太阳足够远,因此我们可以认为太阳的位置是无限远,所以我们认为从太阳发出的光线也都是平行的。<br /><br />
  15. 平行光可以投射阴影 - 跳转至 [page:DirectionalLightShadow] 查看更多细节。
  16. </p>
  17. <h2>关于位置、目标和旋转说明</h2>
  18. <p>
  19. Three.js 的平行光常见的困惑是设置旋转没有效果。这是因为 three.js 的平行光类似与其他引擎的"目标平行光"。
  20. <br /><br />
  21. 这意味着它的方向是从一个平行光的位置 [page:Object3D.position position] 到 [page:.target target]的位置。
  22. (而不是一个只有旋转分量的'自由平行光')。<br /><br />
  23. 这样做的原因是为了让光线投射阴影。[page:.shadow shadow]摄像机需要一个位置来计算阴影。<br /><br />
  24. 有关更新目标的详细信息,请参阅 [page:.target target] 下面的目标属性。
  25. </p>
  26. <h2>代码示例</h2>
  27. <code>
  28. // White directional light at half intensity shining from the top.
  29. const directionalLight = new THREE.DirectionalLight( 0xffffff, 0.5 );
  30. scene.add( directionalLight );
  31. </code>
  32. <h2>例子</h2>
  33. <p>
  34. [example:misc_controls_fly controls / fly ]<br />
  35. [example:webgl_effects_parallaxbarrier effects / parallaxbarrier ]<br />
  36. [example:webgl_effects_stereo effects / stereo ]<br />
  37. [example:webgl_geometry_extrude_splines geometry / extrude / splines ]<br />
  38. [example:webgl_materials_bumpmap materials / bumpmap ]
  39. </p>
  40. <h2>构造器</h2>
  41. <h3>[name]( [param:Integer color], [param:Float intensity] )</h3>
  42. <p>
  43. [page:Integer color] - (可选参数) 16进制表示光的颜色。 缺省值为 0xffffff (白色)。<br />
  44. [page:Float intensity] - (可选参数) 光照的强度。缺省值为1。<br /><br />
  45. 创建一个新的 [name]。
  46. </p>
  47. <h2>属性</h2>
  48. <p>公共属性请查看基类 [page:Light Light]。</p>
  49. <h3>[property:Boolean castShadow]</h3>
  50. <p>
  51. 如果设置为 *true* 该平行光会产生动态阴影。 警告: 这样做的代价比较高而且需要一直调整到阴影看起来正确.
  52. 查看 [page:DirectionalLightShadow] 了解详细信息。该属性默认为 *false*。
  53. </p>
  54. <h3>[property:Boolean isDirectionalLight]</h3>
  55. <p>
  56. Read-only flag to check if a given object is of type [name].
  57. </p>
  58. <h3>[property:Vector3 position]</h3>
  59. <p>
  60. 假如这个值设置等于 [page:Object3D.DefaultUp] (0, 1, 0),那么光线将会从上往下照射。
  61. </p>
  62. <h3>[property:DirectionalLightShadow shadow]</h3>
  63. <p>
  64. 这个 [page:DirectionalLightShadow] 对象用来计算该平行光产生的阴影。
  65. </p>
  66. <h3>[property:Object3D target]</h3>
  67. <p>
  68. 平行光的方向是从它的位置到目标位置。默认的目标位置为原点 *(0,0,0)*。<br />
  69. 注意: 对于目标的位置,要将其更改为除缺省值之外的任何位置,它必须被添加到 [page:Scene scene]
  70. 场景中去。
  71. </p>
  72. <code>
  73. scene.add( light.target );
  74. </code>
  75. <p>
  76. 这使得属性target中的 [page:Object3D.matrixWorld matrixWorld] 会每帧自动更新。
  77. <br /><br />
  78. 它也可以设置target为场景中的其他对象(任意拥有 [page:Object3D.position position] 属性的对象), 示例如下:
  79. </p>
  80. <code>
  81. const targetObject = new THREE.Object3D();
  82. scene.add(targetObject);
  83. light.target = targetObject;
  84. </code>
  85. <p>
  86. 完成上述操作后,平行光现在就可以追踪到目标对像了。
  87. </p>
  88. <h2>方法</h2>
  89. <p>公共方法请查看基类 [page:Light Light]。</p>
  90. <h3>[method:this copy]( [param:DirectionalLight source] )</h3>
  91. <p>
  92. 复制 source 的值到这个平行光源对象。
  93. </p>
  94. <h2>源码</h2>
  95. <p>
  96. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  97. </p>
  98. </body>
  99. </html>