SpotLight.js 1.4 KB

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