SpotLight.js 1.6 KB

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