Light.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Object3D } from '../core/Object3D.js';
  2. import { Color } from '../math/Color.js';
  3. class Light extends Object3D {
  4. constructor( color, intensity = 1 ) {
  5. super();
  6. this.isLight = true;
  7. this.type = 'Light';
  8. this.color = new Color( color );
  9. this.intensity = intensity;
  10. }
  11. dispose() {
  12. // Empty here in base class; some subclasses override.
  13. }
  14. copy( source ) {
  15. super.copy( source );
  16. this.color.copy( source.color );
  17. this.intensity = source.intensity;
  18. return this;
  19. }
  20. toJSON( meta ) {
  21. const data = super.toJSON( meta );
  22. data.object.color = this.color.getHex();
  23. data.object.intensity = this.intensity;
  24. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  25. if ( this.distance !== undefined ) data.object.distance = this.distance;
  26. if ( this.angle !== undefined ) data.object.angle = this.angle;
  27. if ( this.decay !== undefined ) data.object.decay = this.decay;
  28. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  29. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  30. return data;
  31. }
  32. }
  33. export { Light };
粤ICP备19079148号