DirectionalLight.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.DirectionalLight = function ( color, intensity ) {
  6. THREE.Light.call( this, color );
  7. this.type = 'DirectionalLight';
  8. this.position.set( 0, 1, 0 );
  9. this.target = new THREE.Object3D();
  10. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  11. this.castShadow = false;
  12. this.onlyShadow = false;
  13. //
  14. this.shadowCameraNear = 50;
  15. this.shadowCameraFar = 5000;
  16. this.shadowCameraLeft = - 500;
  17. this.shadowCameraRight = 500;
  18. this.shadowCameraTop = 500;
  19. this.shadowCameraBottom = - 500;
  20. this.shadowCameraVisible = false;
  21. this.shadowBias = 0;
  22. this.shadowDarkness = 0.5;
  23. this.shadowMapWidth = 512;
  24. this.shadowMapHeight = 512;
  25. //
  26. this.shadowCascade = false;
  27. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
  28. this.shadowCascadeCount = 2;
  29. this.shadowCascadeBias = [ 0, 0, 0 ];
  30. this.shadowCascadeWidth = [ 512, 512, 512 ];
  31. this.shadowCascadeHeight = [ 512, 512, 512 ];
  32. this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
  33. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  34. this.shadowCascadeArray = [];
  35. //
  36. this.shadowMap = null;
  37. this.shadowMapSize = null;
  38. this.shadowCamera = null;
  39. this.shadowMatrix = null;
  40. };
  41. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  42. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  43. THREE.DirectionalLight.prototype.clone = function () {
  44. var light = new THREE.DirectionalLight();
  45. THREE.Light.prototype.clone.call( this, light );
  46. light.target = this.target.clone();
  47. light.intensity = this.intensity;
  48. light.castShadow = this.castShadow;
  49. light.onlyShadow = this.onlyShadow;
  50. //
  51. light.shadowCameraNear = this.shadowCameraNear;
  52. light.shadowCameraFar = this.shadowCameraFar;
  53. light.shadowCameraLeft = this.shadowCameraLeft;
  54. light.shadowCameraRight = this.shadowCameraRight;
  55. light.shadowCameraTop = this.shadowCameraTop;
  56. light.shadowCameraBottom = this.shadowCameraBottom;
  57. light.shadowCameraVisible = this.shadowCameraVisible;
  58. light.shadowBias = this.shadowBias;
  59. light.shadowDarkness = this.shadowDarkness;
  60. light.shadowMapWidth = this.shadowMapWidth;
  61. light.shadowMapHeight = this.shadowMapHeight;
  62. //
  63. light.shadowCascade = this.shadowCascade;
  64. light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
  65. light.shadowCascadeCount = this.shadowCascadeCount;
  66. light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
  67. light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
  68. light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
  69. light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
  70. light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
  71. return light;
  72. };
  73. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  74. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  75. data.object.color = this.color.getHex();
  76. data.object.intensity = this.intensity;
  77. return data;
  78. };
粤ICP备19079148号