PointLight.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Light } from './Light.js';
  2. import { PointLightShadow } from './PointLightShadow.js';
  3. /**
  4. * @author mrdoob / http://mrdoob.com/
  5. */
  6. function PointLight( color, intensity, distance, decay ) {
  7. Light.call( this, color, intensity );
  8. this.type = 'PointLight';
  9. Object.defineProperty( this, 'power', {
  10. get: function () {
  11. // intensity = power per solid angle.
  12. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  13. return this.intensity * 4 * Math.PI;
  14. },
  15. set: function ( power ) {
  16. // intensity = power per solid angle.
  17. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  18. this.intensity = power / ( 4 * Math.PI );
  19. }
  20. } );
  21. this.distance = ( distance !== undefined ) ? distance : 0;
  22. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23. this.shadow = new PointLightShadow();
  24. }
  25. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  26. constructor: PointLight,
  27. isPointLight: true,
  28. copy: function ( source ) {
  29. Light.prototype.copy.call( this, source );
  30. this.distance = source.distance;
  31. this.decay = source.decay;
  32. this.shadow = source.shadow.clone();
  33. return this;
  34. }
  35. } );
  36. export { PointLight };