SpotLight.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Light } from './Light.js';
  2. import { SpotLightShadow } from './SpotLightShadow.js';
  3. import { Object3D } from '../core/Object3D.js';
  4. /**
  5. * @author alteredq / http://alteredqualia.com/
  6. */
  7. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  8. Light.call( this, color, intensity );
  9. this.type = 'SpotLight';
  10. this.position.copy( Object3D.DefaultUp );
  11. this.updateMatrix();
  12. this.target = new Object3D();
  13. Object.defineProperty( this, 'power', {
  14. get: function () {
  15. // intensity = power per solid angle.
  16. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  17. return this.intensity * Math.PI;
  18. },
  19. set: function ( power ) {
  20. // intensity = power per solid angle.
  21. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22. this.intensity = power / Math.PI;
  23. }
  24. } );
  25. this.distance = ( distance !== undefined ) ? distance : 0;
  26. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  27. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  28. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  29. this.shadow = new SpotLightShadow();
  30. }
  31. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  32. constructor: SpotLight,
  33. isSpotLight: true,
  34. copy: function ( source ) {
  35. Light.prototype.copy.call( this, source );
  36. this.distance = source.distance;
  37. this.angle = source.angle;
  38. this.penumbra = source.penumbra;
  39. this.decay = source.decay;
  40. this.target = source.target.clone();
  41. this.shadow = source.shadow.clone();
  42. return this;
  43. }
  44. } );
  45. export { SpotLight };