Light.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Object3D } from '../core/Object3D.js';
  2. import { Color } from '../math/Color.js';
  3. function Light( color, intensity ) {
  4. Object3D.call( this );
  5. this.type = 'Light';
  6. this.color = new Color( color );
  7. this.intensity = intensity !== undefined ? intensity : 1;
  8. this.receiveShadow = undefined;
  9. }
  10. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  11. constructor: Light,
  12. isLight: true,
  13. copy: function ( source ) {
  14. Object3D.prototype.copy.call( this, source );
  15. this.color.copy( source.color );
  16. this.intensity = source.intensity;
  17. return this;
  18. },
  19. toJSON: function ( meta ) {
  20. const data = Object3D.prototype.toJSON.call( this, meta );
  21. data.object.color = this.color.getHex();
  22. data.object.intensity = this.intensity;
  23. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  24. if ( this.distance !== undefined ) data.object.distance = this.distance;
  25. if ( this.angle !== undefined ) data.object.angle = this.angle;
  26. if ( this.decay !== undefined ) data.object.decay = this.decay;
  27. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  28. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  29. return data;
  30. }
  31. } );
  32. export { Light };
粤ICP备19079148号