PointLight.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Light } from './Light.js';
  2. import { PointLightShadow } from './PointLightShadow.js';
  3. class PointLight extends Light {
  4. constructor( color, intensity, distance = 0, decay = 1 ) {
  5. super( color, intensity );
  6. this.type = 'PointLight';
  7. this.distance = distance;
  8. this.decay = decay; // for physically correct lights, should be 2.
  9. this.shadow = new PointLightShadow();
  10. }
  11. get power() {
  12. // compute the light's luminous power (in lumens) from its intensity (in candela)
  13. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  14. return this.intensity * 4 * Math.PI;
  15. }
  16. set power( power ) {
  17. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  18. this.intensity = power / ( 4 * Math.PI );
  19. }
  20. dispose() {
  21. this.shadow.dispose();
  22. }
  23. copy( source ) {
  24. super.copy( source );
  25. this.distance = source.distance;
  26. this.decay = source.decay;
  27. this.shadow = source.shadow.clone();
  28. return this;
  29. }
  30. }
  31. PointLight.prototype.isPointLight = true;
  32. export { PointLight };