Light.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.Light = function ( color ) {
  6. THREE.Object3D.call( this );
  7. this.type = 'Light';
  8. this.color = new THREE.Color( color );
  9. };
  10. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  11. THREE.Light.prototype.constructor = THREE.Light;
  12. Object.defineProperties( THREE.Light.prototype, {
  13. castShadow: {
  14. get: function () {
  15. if ( this.shadow === undefined ) return false;
  16. return this.shadow.enabled;
  17. },
  18. set: function ( value ) {
  19. if ( this.shadow === undefined ) return;
  20. this.shadow.enabled = value;
  21. }
  22. },
  23. onlyShadow: {
  24. set: function ( value ) {
  25. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  26. }
  27. },
  28. shadowCamera: {
  29. get: function () {
  30. return this.shadow.camera;
  31. }
  32. },
  33. shadowCameraFov: {
  34. get: function () {
  35. return this.shadow.camera.fov;
  36. },
  37. set: function ( value ) {
  38. this.shadow.camera.fov = value;
  39. }
  40. },
  41. shadowCameraLeft: {
  42. get: function () {
  43. return this.shadow.camera.left;
  44. },
  45. set: function ( value ) {
  46. this.shadow.camera.left = value;
  47. }
  48. },
  49. shadowCameraRight: {
  50. get: function () {
  51. return this.shadow.camera.right;
  52. },
  53. set: function ( value ) {
  54. this.shadow.camera.right = value;
  55. }
  56. },
  57. shadowCameraTop: {
  58. get: function () {
  59. return this.shadow.camera.top;
  60. },
  61. set: function ( value ) {
  62. this.shadow.camera.top = value;
  63. }
  64. },
  65. shadowCameraBottom: {
  66. get: function () {
  67. return this.shadow.camera.bottom;
  68. },
  69. set: function ( value ) {
  70. this.shadow.camera.bottom = value;
  71. }
  72. },
  73. shadowCameraNear: {
  74. get: function () {
  75. return this.shadow.camera.near;
  76. },
  77. set: function ( value ) {
  78. this.shadow.camera.near = value;
  79. }
  80. },
  81. shadowCameraFar: {
  82. get: function () {
  83. return this.shadow.camera.far;
  84. },
  85. set: function ( value ) {
  86. this.shadow.camera.far = value;
  87. }
  88. },
  89. shadowCameraVisible: {
  90. set: function ( value ) {
  91. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow ) instead.' );
  92. }
  93. },
  94. shadowBias: {
  95. get: function () {
  96. return this.shadow.bias;
  97. },
  98. set: function ( value ) {
  99. this.shadow.bias = value;
  100. }
  101. },
  102. shadowDarkness: {
  103. get: function () {
  104. return this.shadow.darkness;
  105. },
  106. set: function ( value ) {
  107. this.shadow.darkness = value;
  108. }
  109. },
  110. shadowMap: {
  111. get: function () {
  112. return this.shadow.map;
  113. },
  114. set: function ( value ) {
  115. this.shadow.map = value;
  116. }
  117. },
  118. shadowMapSize: {
  119. get: function () {
  120. return this.shadow.mapSize;
  121. }
  122. },
  123. shadowMapWidth: {
  124. get: function () {
  125. return this.shadow.mapSize.x;
  126. },
  127. set: function ( value ) {
  128. this.shadow.mapSize.x = value;
  129. }
  130. },
  131. shadowMapHeight: {
  132. get: function () {
  133. return this.shadow.mapSize.y;
  134. },
  135. set: function ( value ) {
  136. this.shadow.mapSize.y = value;
  137. }
  138. },
  139. shadowMatrix: {
  140. get: function () {
  141. return this.shadow.matrix;
  142. },
  143. set: function ( value ) {
  144. this.shadow.matrix = value;
  145. }
  146. }
  147. } );
  148. THREE.Light.prototype.copy = function ( source ) {
  149. THREE.Object3D.prototype.copy.call( this, source );
  150. this.color.copy( source.color );
  151. return this;
  152. };
  153. THREE.Light.prototype.toJSON = function ( meta ) {
  154. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  155. data.object.color = this.color.getHex();
  156. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  157. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  158. if ( this.distance !== undefined ) data.object.distance = this.distance;
  159. if ( this.angle !== undefined ) data.object.angle = this.angle;
  160. if ( this.decay !== undefined ) data.object.decay = this.decay;
  161. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  162. return data;
  163. };