Browse Source

PointLight: Convert to ES6

Mr.doob 4 năm trước cách đây
mục cha
commit
32172e1cf2
1 tập tin đã thay đổi với 22 bổ sung26 xóa
  1. 22 26
      src/lights/PointLight.js

+ 22 - 26
src/lights/PointLight.js

@@ -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;
@@ -50,7 +47,6 @@ PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
 
 	}
 
-} );
-
+}
 
 export { PointLight };