diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index 5dff03bba78ccf..31425c0fa1f41e 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -1,20 +1,16 @@ import { Light } from './Light.js'; -function AmbientLight( color, intensity ) { +class AmbientLight extends Light { - Light.call( this, color, intensity ); + constructor( color, intensity ) { - this.type = 'AmbientLight'; + super( color, intensity ); -} - -AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: AmbientLight, + this.type = 'AmbientLight'; + Object.defineProperty( this, 'isAmbientLight', { value: true } ); - isAmbientLight: true - -} ); + } +} export { AmbientLight }; diff --git a/src/lights/AmbientLightProbe.js b/src/lights/AmbientLightProbe.js index a8b514e0613f21..fa1a64c1a893ea 100644 --- a/src/lights/AmbientLightProbe.js +++ b/src/lights/AmbientLightProbe.js @@ -1,34 +1,32 @@ import { Color } from '../math/Color.js'; import { LightProbe } from './LightProbe.js'; -function AmbientLightProbe( color, intensity ) { +class AmbientLightProbe extends LightProbe { - LightProbe.call( this, undefined, intensity ); + constructor( color, intensity ) { - const color1 = new Color().set( color ); + super( undefined, intensity ); - // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); - this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) ); + Object.defineProperty( this, 'isAmbientLightProbe', { value: true } ); -} - -AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), { + const color1 = new Color().set( color ); - constructor: AmbientLightProbe, + // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); + this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) ); - isAmbientLightProbe: true, + } - copy: function ( source ) { // modifying color not currently supported + copy( source ) { // modifying color not currently supported - LightProbe.prototype.copy.call( this, source ); + super.copy( source ); return this; - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { - const data = LightProbe.prototype.toJSON.call( this, meta ); + const data = super.toJSON( meta ); // data.sh = this.sh.toArray(); // todo @@ -36,6 +34,6 @@ AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype } -} ); +} export { AmbientLightProbe }; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index 724e954f09e9f1..88d44487d7664d 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -2,30 +2,27 @@ import { Light } from './Light.js'; import { DirectionalLightShadow } from './DirectionalLightShadow.js'; import { Object3D } from '../core/Object3D.js'; -function DirectionalLight( color, intensity ) { +class DirectionalLight extends Light { - Light.call( this, color, intensity ); + constructor( color, intensity ) { - this.type = 'DirectionalLight'; + super( color, intensity ); - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.type = 'DirectionalLight'; + Object.defineProperty( this, 'isDirectionalLight', { value: true } ); - this.target = new Object3D(); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); - this.shadow = new DirectionalLightShadow(); + this.target = new Object3D(); -} - -DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: DirectionalLight, + this.shadow = new DirectionalLightShadow(); - isDirectionalLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.target = source.target.clone(); @@ -35,7 +32,6 @@ DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); - +} export { DirectionalLight }; diff --git a/src/lights/DirectionalLightShadow.js b/src/lights/DirectionalLightShadow.js index 027f94aac160ba..cc5a347d1b94fa 100644 --- a/src/lights/DirectionalLightShadow.js +++ b/src/lights/DirectionalLightShadow.js @@ -1,25 +1,22 @@ import { LightShadow } from './LightShadow.js'; import { OrthographicCamera } from '../cameras/OrthographicCamera.js'; -function DirectionalLightShadow() { +class DirectionalLightShadow extends LightShadow { - LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); + constructor() { -} - -DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { + super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); - constructor: DirectionalLightShadow, + Object.defineProperty( this, 'isDirectionalLightShadow', { value: true } ); - isDirectionalLightShadow: true, + } - updateMatrices: function ( light ) { + updateMatrices( light ) { - LightShadow.prototype.updateMatrices.call( this, light ); + super.updateMatrices( light ); } -} ); - +} export { DirectionalLightShadow }; diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index 1343df9179596a..f0b1a684e7bb40 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -2,28 +2,25 @@ import { Light } from './Light.js'; import { Color } from '../math/Color.js'; import { Object3D } from '../core/Object3D.js'; -function HemisphereLight( skyColor, groundColor, intensity ) { +class HemisphereLight extends Light { - Light.call( this, skyColor, intensity ); + constructor( skyColor, groundColor, intensity ) { - this.type = 'HemisphereLight'; + super( skyColor, intensity ); - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.type = 'HemisphereLight'; + Object.defineProperty( this, 'isHemisphereLight', { value: true } ); - this.groundColor = new Color( groundColor ); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); -} - -HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: HemisphereLight, + this.groundColor = new Color( groundColor ); - isHemisphereLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.groundColor.copy( source.groundColor ); @@ -31,7 +28,6 @@ HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); - +} export { HemisphereLight }; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index 261e7e09c7498e..14eb446790dd00 100644 --- a/src/lights/HemisphereLightProbe.js +++ b/src/lights/HemisphereLightProbe.js @@ -2,42 +2,40 @@ import { Color } from '../math/Color.js'; import { Vector3 } from '../math/Vector3.js'; import { LightProbe } from './LightProbe.js'; -function HemisphereLightProbe( skyColor, groundColor, intensity ) { +class HemisphereLightProbe extends LightProbe { - LightProbe.call( this, undefined, intensity ); + constructor( skyColor, groundColor, intensity ) { - const color1 = new Color().set( skyColor ); - const color2 = new Color().set( groundColor ); + super( undefined, intensity ); - const sky = new Vector3( color1.r, color1.g, color1.b ); - const ground = new Vector3( color2.r, color2.g, color2.b ); + Object.defineProperty( this, 'isHemisphereLightProbe', { value: true } ); - // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI ); - const c0 = Math.sqrt( Math.PI ); - const c1 = c0 * Math.sqrt( 0.75 ); + const color1 = new Color().set( skyColor ); + const color2 = new Color().set( groundColor ); - this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); - this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); + const sky = new Vector3( color1.r, color1.g, color1.b ); + const ground = new Vector3( color2.r, color2.g, color2.b ); -} - -HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), { + // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI ); + const c0 = Math.sqrt( Math.PI ); + const c1 = c0 * Math.sqrt( 0.75 ); - constructor: HemisphereLightProbe, + this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); + this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); - isHemisphereLightProbe: true, + } - copy: function ( source ) { // modifying colors not currently supported + copy( source ) { // modifying colors not currently supported - LightProbe.prototype.copy.call( this, source ); + super.copy( source ); return this; - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { - const data = LightProbe.prototype.toJSON.call( this, meta ); + const data = super.toJSON( meta ); // data.sh = this.sh.toArray(); // todo @@ -45,6 +43,6 @@ HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.protot } -} ); +} export { HemisphereLightProbe }; diff --git a/src/lights/Light.js b/src/lights/Light.js index efa6e5eae9d84f..710b822c3cd644 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -1,37 +1,34 @@ import { Object3D } from '../core/Object3D.js'; import { Color } from '../math/Color.js'; -function Light( color, intensity = 1 ) { +class Light extends Object3D { - Object3D.call( this ); + constructor( color, intensity = 1 ) { - this.type = 'Light'; + super(); - this.color = new Color( color ); - this.intensity = intensity; + this.type = 'Light'; + Object.defineProperty( this, 'isLight', { value: true } ); -} - -Light.prototype = Object.assign( Object.create( Object3D.prototype ), { + this.color = new Color( color ); + this.intensity = intensity; - constructor: Light, - - isLight: true, + } - copy: function ( source ) { + copy( source ) { - Object3D.prototype.copy.call( this, source ); + super.copy( source ); this.color.copy( source.color ); this.intensity = source.intensity; return this; - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { - const data = Object3D.prototype.toJSON.call( this, meta ); + const data = super.toJSON( meta ); data.object.color = this.color.getHex(); data.object.intensity = this.intensity; @@ -49,7 +46,6 @@ Light.prototype = Object.assign( Object.create( Object3D.prototype ), { } -} ); - +} export { Light }; diff --git a/src/lights/LightProbe.js b/src/lights/LightProbe.js index e48aea005c2a99..0fbb660e9f14bf 100644 --- a/src/lights/LightProbe.js +++ b/src/lights/LightProbe.js @@ -1,44 +1,41 @@ import { SphericalHarmonics3 } from '../math/SphericalHarmonics3.js'; import { Light } from './Light.js'; -function LightProbe( sh, intensity ) { +class LightProbe extends Light { - Light.call( this, undefined, intensity ); + constructor( sh, intensity ) { - this.type = 'LightProbe'; + super( undefined, intensity ); - this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); + this.type = 'LightProbe'; + Object.defineProperty( this, 'isLightProbe', { value: true } ); -} - -LightProbe.prototype = Object.assign( Object.create( Light.prototype ), { + this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); - constructor: LightProbe, - - isLightProbe: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.sh.copy( source.sh ); return this; - }, + } - fromJSON: function ( json ) { + fromJSON( json ) { this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON(); this.sh.fromArray( json.sh ); return this; - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { - const data = Light.prototype.toJSON.call( this, meta ); + const data = super.toJSON( meta ); data.object.sh = this.sh.toArray(); @@ -46,6 +43,6 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { LightProbe }; diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index b3556452f7b5c8..2a05d1b2dcac80 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -4,57 +4,59 @@ import { Vector3 } from '../math/Vector3.js'; import { Vector4 } from '../math/Vector4.js'; import { Frustum } from '../math/Frustum.js'; -function LightShadow( camera ) { +class LightShadow { - this.camera = camera; + constructor( camera ) { - this.bias = 0; - this.normalBias = 0; - this.radius = 1; + Object.defineProperty( this, 'isLightShadow', { value: true } ); - this.mapSize = new Vector2( 512, 512 ); + this.camera = camera; - this.map = null; - this.mapPass = null; - this.matrix = new Matrix4(); + this.bias = 0; + this.normalBias = 0; + this.radius = 1; - this.autoUpdate = true; - this.needsUpdate = false; + this.mapSize = new Vector2( 512, 512 ); - this._frustum = new Frustum(); - this._frameExtents = new Vector2( 1, 1 ); + this.map = null; + this.mapPass = null; + this.matrix = new Matrix4(); - this._viewportCount = 1; + this.autoUpdate = true; + this.needsUpdate = false; - this._viewports = [ + this._frustum = new Frustum(); + this._frameExtents = new Vector2( 1, 1 ); - new Vector4( 0, 0, 1, 1 ) + this._viewportCount = 1; - ]; + this._viewports = [ -} + new Vector4( 0, 0, 1, 1 ) + + ]; -Object.assign( LightShadow.prototype, { + this._projScreenMatrix = new Matrix4(); - _projScreenMatrix: new Matrix4(), + this._lightPositionWorld = new Vector3(); - _lightPositionWorld: new Vector3(), + this._lookTarget = new Vector3(); - _lookTarget: new Vector3(), + } - getViewportCount: function () { + getViewportCount() { return this._viewportCount; - }, + } - getFrustum: function () { + getFrustum() { return this._frustum; - }, + } - updateMatrices: function ( light ) { + updateMatrices( light ) { const shadowCamera = this.camera, shadowMatrix = this.matrix, @@ -82,21 +84,21 @@ Object.assign( LightShadow.prototype, { shadowMatrix.multiply( shadowCamera.projectionMatrix ); shadowMatrix.multiply( shadowCamera.matrixWorldInverse ); - }, + } - getViewport: function ( viewportIndex ) { + getViewport( viewportIndex ) { return this._viewports[ viewportIndex ]; - }, + } - getFrameExtents: function () { + getFrameExtents() { return this._frameExtents; - }, + } - copy: function ( source ) { + copy( source ) { this.camera = source.camera.clone(); @@ -107,15 +109,15 @@ Object.assign( LightShadow.prototype, { return this; - }, + } - clone: function () { + clone() { return new this.constructor().copy( this ); - }, + } - toJSON: function () { + toJSON() { const object = {}; @@ -131,7 +133,6 @@ Object.assign( LightShadow.prototype, { } -} ); - +} export { LightShadow }; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 0fc7ef70d7d20a..afebaaac316f9b 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -1,45 +1,41 @@ 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, decay ) { - this.type = 'PointLight'; + super( color, intensity ); - Object.defineProperty( this, 'power', { - get: function () { + this.type = 'PointLight'; + 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.distance = ( distance !== undefined ) ? distance : 0; + this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. - }, - set: function ( 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 - this.intensity = power / ( 4 * Math.PI ); - - } - } ); + } - 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( value ) { - 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 = value / ( 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 +46,6 @@ PointLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); - +} export { PointLight }; diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index 44366e52f9d324..4637a7ac33d917 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -4,61 +4,55 @@ import { Vector2 } from '../math/Vector2.js'; import { Vector3 } from '../math/Vector3.js'; import { Vector4 } from '../math/Vector4.js'; -function PointLightShadow() { - - LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) ); - - this._frameExtents = new Vector2( 4, 2 ); - - this._viewportCount = 6; - - this._viewports = [ - // These viewports map a cube-map onto a 2D texture with the - // following orientation: - // - // xzXZ - // y Y - // - // X - Positive x direction - // x - Negative x direction - // Y - Positive y direction - // y - Negative y direction - // Z - Positive z direction - // z - Negative z direction - - // positive X - new Vector4( 2, 1, 1, 1 ), - // negative X - new Vector4( 0, 1, 1, 1 ), - // positive Z - new Vector4( 3, 1, 1, 1 ), - // negative Z - new Vector4( 1, 1, 1, 1 ), - // positive Y - new Vector4( 3, 0, 1, 1 ), - // negative Y - new Vector4( 1, 0, 1, 1 ) - ]; - - this._cubeDirections = [ - new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ), - new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 ) - ]; - - this._cubeUps = [ - new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), - new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 ) - ]; +class PointLightShadow extends LightShadow { + + constructor() { + + super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + + Object.defineProperty( this, 'isPointLightShadow', { value: true } ); + + this._cubeDirections = [ + new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ), + new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 ) + ]; + this._viewportCount = 6; + this._viewports = [ + // These viewports map a cube-map onto a 2D texture with the + // following orientation: + // + // xzXZ + // y Y + // + // X - Positive x direction + // x - Negative x direction + // Y - Positive y direction + // y - Negative y direction + // Z - Positive z direction + // z - Negative z direction + + // positive X + new Vector4( 2, 1, 1, 1 ), + // negative X + new Vector4( 0, 1, 1, 1 ), + // positive Z + new Vector4( 3, 1, 1, 1 ), + // negative Z + new Vector4( 1, 1, 1, 1 ), + // positive Y + new Vector4( 3, 0, 1, 1 ), + // negative Y + new Vector4( 1, 0, 1, 1 ) + ]; + this._cubeUps = [ + new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), + new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 ) + ]; + this._frameExtents = new Vector2( 4, 2 ); -} - -PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { - - constructor: PointLightShadow, - - isPointLightShadow: true, + } - updateMatrices: function ( light, viewportIndex = 0 ) { + updateMatrices( light, viewportIndex = 0 ) { const camera = this.camera, shadowMatrix = this.matrix, @@ -82,7 +76,6 @@ PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype } -} ); - +} export { PointLightShadow }; diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js index b3c32a4944b631..979e25aabcabf9 100644 --- a/src/lights/RectAreaLight.js +++ b/src/lights/RectAreaLight.js @@ -1,36 +1,33 @@ import { Light } from './Light.js'; -function RectAreaLight( color, intensity, width, height ) { +class RectAreaLight extends Light { - Light.call( this, color, intensity ); + constructor( color, intensity, width, height ) { - this.type = 'RectAreaLight'; + super( color, intensity ); - this.width = ( width !== undefined ) ? width : 10; - this.height = ( height !== undefined ) ? height : 10; + this.type = 'RectAreaLight'; + Object.defineProperty( this, 'isRectAreaLight', { value: true } ); -} - -RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: RectAreaLight, + this.width = ( width !== undefined ) ? width : 10; + this.height = ( height !== undefined ) ? height : 10; - isRectAreaLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.width = source.width; this.height = source.height; return this; - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { - const data = Light.prototype.toJSON.call( this, meta ); + const data = super.toJSON( meta ); data.object.width = this.width; data.object.height = this.height; @@ -39,6 +36,6 @@ RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { RectAreaLight }; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index da921df3b20e79..922e61b096f8ac 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -2,52 +2,48 @@ import { Light } from './Light.js'; import { SpotLightShadow } from './SpotLightShadow.js'; import { Object3D } from '../core/Object3D.js'; -function SpotLight( color, intensity, distance, angle, penumbra, decay ) { +class SpotLight extends Light { - Light.call( this, color, intensity ); + constructor( color, intensity, distance, angle, penumbra, decay ) { - this.type = 'SpotLight'; + super( color, intensity ); - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.type = 'SpotLight'; + Object.defineProperty( this, 'isSpotLight', { value: true } ); - this.target = new Object3D(); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); - Object.defineProperty( this, 'power', { - get: function () { + this.target = new Object3D(); - // intensity = power per solid angle. - // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf - return this.intensity * Math.PI; + this.distance = ( distance !== undefined ) ? distance : 0; + this.angle = ( angle !== undefined ) ? angle : Math.PI / 3; + this.penumbra = ( penumbra !== undefined ) ? penumbra : 0; + this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. - }, - set: function ( power ) { + this.shadow = new SpotLightShadow(); - // intensity = power per solid angle. - // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf - this.intensity = power / Math.PI; - - } - } ); + } - this.distance = ( distance !== undefined ) ? distance : 0; - this.angle = ( angle !== undefined ) ? angle : Math.PI / 3; - this.penumbra = ( penumbra !== undefined ) ? penumbra : 0; - this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. + get power() { - this.shadow = new SpotLightShadow(); + // intensity = power per solid angle. + // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + return this.intensity * Math.PI; -} + } -SpotLight.prototype = Object.assign( Object.create( Light.prototype ), { + set power( value ) { - constructor: SpotLight, + // intensity = power per solid angle. + // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + this.intensity = value / Math.PI; - isSpotLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.distance = source.distance; this.angle = source.angle; @@ -62,7 +58,6 @@ SpotLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); - +} export { SpotLight }; diff --git a/src/lights/SpotLightShadow.js b/src/lights/SpotLightShadow.js index 908f93402dc4dc..fc93f61842b98f 100644 --- a/src/lights/SpotLightShadow.js +++ b/src/lights/SpotLightShadow.js @@ -2,21 +2,19 @@ import { LightShadow } from './LightShadow.js'; import { MathUtils } from '../math/MathUtils.js'; import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js'; -function SpotLightShadow() { +class SpotLightShadow extends LightShadow { - LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) ); + constructor() { - this.focus = 1; + super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); -} - -SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { + this.focus = 1; - constructor: SpotLightShadow, + Object.defineProperty( this, 'isSpotLightShadow', { value: true } ); - isSpotLightShadow: true, + } - updateMatrices: function ( light ) { + updateMatrices( light ) { const camera = this.camera; @@ -33,11 +31,10 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype } - LightShadow.prototype.updateMatrices.call( this, light ); + super.updateMatrices( light ); } -} ); - +} export { SpotLightShadow };