Skip to content

Commit

Permalink
PointLight: Convert to ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Feb 9, 2021
1 parent ab1ed6c commit 32172e1
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/lights/PointLight.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
import { Light } from './Light.js';
import { PointLightShadow } from './PointLightShadow.js';

function PointLight( color, intensity, distance, decay ) {
class PointLight extends Light {

Light.call( this, color, intensity );
constructor( color, intensity, distance = 0, decay = 1 ) {

this.type = 'PointLight';
super( color, intensity );

Object.defineProperty( this, 'power', {
get: function () {
Object.defineProperty( this, 'isPointLight', { value: true } );

// intensity = power per solid angle.
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
return this.intensity * 4 * Math.PI;
this.type = 'PointLight';

},
set: function ( power ) {
this.distance = distance;
this.decay = decay; // for physically correct lights, should be 2.

// intensity = power per solid angle.
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
this.intensity = power / ( 4 * Math.PI );
this.shadow = new PointLightShadow();

}
} );
}

this.distance = ( distance !== undefined ) ? distance : 0;
this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
get power() {

this.shadow = new PointLightShadow();
// intensity = power per solid angle.
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
return this.intensity * 4 * Math.PI;

}
}

PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
set power( power ) {

constructor: PointLight,
// intensity = power per solid angle.
// ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
this.intensity = power / ( 4 * Math.PI );

isPointLight: true,
}

copy: function ( source ) {
copy( source ) {

Light.prototype.copy.call( this, source );
super.copy( source );

this.distance = source.distance;
this.decay = source.decay;
Expand All @@ -50,7 +47,6 @@ PointLight.prototype = Object.assign( Object.create( Light.prototype ), {

}

} );

}

export { PointLight };

0 comments on commit 32172e1

Please sign in to comment.