From 078eee18307feb1f07b8603743d51f40a87c81e8 Mon Sep 17 00:00:00 2001 From: Rawr Date: Wed, 5 Aug 2020 19:05:50 +1200 Subject: [PATCH 01/12] src/lights: move to es6 classes --- src/lights/AmbientLight.js | 20 +++---- src/lights/AmbientLightProbe.js | 31 ++++++----- src/lights/DirectionalLight.js | 30 +++++------ src/lights/DirectionalLightShadow.js | 18 +++---- src/lights/HemisphereLight.js | 30 +++++------ src/lights/HemisphereLightProbe.js | 45 ++++++++-------- src/lights/Light.js | 32 ++++++------ src/lights/LightProbe.js | 34 ++++++------ src/lights/LightShadow.js | 78 ++++++++++++++-------------- src/lights/PointLight.js | 47 ++++++++--------- src/lights/PointLightShadow.js | 71 ++++++++++++------------- src/lights/RectAreaLight.js | 32 ++++++------ src/lights/SpotLight.js | 58 ++++++++++----------- src/lights/SpotLightShadow.js | 19 +++---- 14 files changed, 256 insertions(+), 289 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index ac0e3d8fd7412d..5f63ed093f60af 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -1,22 +1,18 @@ 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 ); + this.type = 'AmbientLight'; - this.castShadow = undefined; + this.castShadow = undefined; + this.isAmbientLight = true; -} - -AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: AmbientLight, + } - isAmbientLight: true - -} ); +} export { AmbientLight }; diff --git a/src/lights/AmbientLightProbe.js b/src/lights/AmbientLightProbe.js index a8b514e0613f21..bb411dd8c50675 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 ) ); + this.isAmbientLightProbe = 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,7 @@ AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype } -} ); +} + export { AmbientLightProbe }; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index 724e954f09e9f1..32830d7a4c75ad 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -2,30 +2,26 @@ 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.type = 'DirectionalLight'; - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); - this.target = new Object3D(); + this.target = new Object3D(); - this.shadow = new DirectionalLightShadow(); + this.shadow = new DirectionalLightShadow(); + this.isDirectionalLight = true; -} - -DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: DirectionalLight, - - isDirectionalLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.target = source.target.clone(); @@ -35,7 +31,7 @@ DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { DirectionalLight }; diff --git a/src/lights/DirectionalLightShadow.js b/src/lights/DirectionalLightShadow.js index 027f94aac160ba..11122e5de349bb 100644 --- a/src/lights/DirectionalLightShadow.js +++ b/src/lights/DirectionalLightShadow.js @@ -1,25 +1,23 @@ 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, + this.isDirectionalLightShadow = 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 25df3cbbbdd3fe..fdca5a9ae21cba 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -2,30 +2,28 @@ 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.type = 'HemisphereLight'; - this.castShadow = undefined; + this.castShadow = undefined; - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); - this.groundColor = new Color( groundColor ); + this.groundColor = new Color( groundColor ); -} - -HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), { - - constructor: HemisphereLight, + this.isHemisphereLight = true; - isHemisphereLight: true, + } - copy: function ( source ) { + copy( source ) { - Light.prototype.copy.call( this, source ); + super.copy( source ); this.groundColor.copy( source.groundColor ); @@ -33,7 +31,7 @@ HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { HemisphereLight }; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index 261e7e09c7498e..68c1dfdb5d3dff 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 color1 = new Color().set( skyColor ); + const color2 = new Color().set( groundColor ); - const sky = new Vector3( color1.r, color1.g, color1.b ); - const ground = new Vector3( color2.r, color2.g, color2.b ); + const sky = new Vector3( color1.r, color1.g, color1.b ); + const ground = new Vector3( color2.r, color2.g, color2.b ); - // 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 ); + // 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 ); - this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); - this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); + this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); + this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); -} - -HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), { + this.isHemisphereLightProbe = true; - constructor: HemisphereLightProbe, - - 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,7 @@ HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.protot } -} ); +} + export { HemisphereLightProbe }; diff --git a/src/lights/Light.js b/src/lights/Light.js index fdbb9b1540aa1a..d35a5103aa7cc0 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -1,39 +1,37 @@ import { Object3D } from '../core/Object3D.js'; import { Color } from '../math/Color.js'; -function Light( color, intensity ) { +class Light extends Object3D { - Object3D.call( this ); + constructor( color, intensity ) { - this.type = 'Light'; + super(); - this.color = new Color( color ); - this.intensity = intensity !== undefined ? intensity : 1; + this.type = 'Light'; - this.receiveShadow = undefined; + this.color = new Color( color ); + this.intensity = intensity !== undefined ? intensity : 1; -} - -Light.prototype = Object.assign( Object.create( Object3D.prototype ), { + this.receiveShadow = undefined; - constructor: Light, + this.isLight = true; - 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; @@ -51,7 +49,7 @@ Light.prototype = Object.assign( Object.create( Object3D.prototype ), { } -} ); +} export { Light }; diff --git a/src/lights/LightProbe.js b/src/lights/LightProbe.js index e48aea005c2a99..f9c090cc3f38a4 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.type = 'LightProbe'; - this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); + this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); -} - -LightProbe.prototype = Object.assign( Object.create( Light.prototype ), { + this.isLightProbe = true; - 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,7 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} + export { LightProbe }; diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index b3556452f7b5c8..febbe41e889020 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -4,57 +4,57 @@ 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; + this.camera = camera; - this.mapSize = new Vector2( 512, 512 ); + this.bias = 0; + this.normalBias = 0; + this.radius = 1; - this.map = null; - this.mapPass = null; - this.matrix = new Matrix4(); + this.mapSize = new Vector2( 512, 512 ); - this.autoUpdate = true; - this.needsUpdate = false; + this.map = null; + this.mapPass = null; + this.matrix = new Matrix4(); - this._frustum = new Frustum(); - this._frameExtents = new Vector2( 1, 1 ); + this.autoUpdate = true; + this.needsUpdate = false; - this._viewportCount = 1; + this._frustum = new Frustum(); + this._frameExtents = new Vector2( 1, 1 ); - this._viewports = [ + this._viewportCount = 1; - new Vector4( 0, 0, 1, 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 +82,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 +107,15 @@ Object.assign( LightShadow.prototype, { return this; - }, + } - clone: function () { + clone() { - return new this.constructor().copy( this ); + return new LightShadow().copy( this ); - }, + } - toJSON: function () { + toJSON() { const object = {}; @@ -131,7 +131,7 @@ Object.assign( LightShadow.prototype, { } -} ); +} export { LightShadow }; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 0fc7ef70d7d20a..07eff7845124bc 100644 --- a/src/lights/PointLight.js +++ b/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, decay ) { - this.type = 'PointLight'; + super( color, intensity ); - Object.defineProperty( this, 'power', { - get: function () { + this.type = '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 - 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.isPointLight = true; - } - } ); + } - 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 +47,7 @@ PointLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { PointLight }; diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index 8a9583a43b9db7..86aac0df1ed956 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -4,15 +4,16 @@ import { Vector2 } from '../math/Vector2.js'; import { Vector3 } from '../math/Vector3.js'; import { Vector4 } from '../math/Vector4.js'; -function PointLightShadow() { +class PointLightShadow extends LightShadow { - LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + constructor() { - this._frameExtents = new Vector2( 4, 2 ); + super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + this._frameExtents = new Vector2( 4, 2 ); - this._viewportCount = 6; + this._viewportCount = 6; - this._viewports = [ + this._viewports = [ // These viewports map a cube-map onto a 2D texture with the // following orientation: // @@ -26,39 +27,35 @@ function PointLightShadow() { // 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 ) - ]; + // 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 ) + ]; + + this.isPointLightShadow = true; -} - -PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { - - constructor: PointLightShadow, - - isPointLightShadow: true, + } - updateMatrices: function ( light, viewportIndex ) { + updateMatrices( light, viewportIndex ) { if ( viewportIndex === undefined ) viewportIndex = 0; @@ -84,7 +81,7 @@ PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype } -} ); +} export { PointLightShadow }; diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js index b3c32a4944b631..a429437f581905 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.type = 'RectAreaLight'; - this.width = ( width !== undefined ) ? width : 10; - this.height = ( height !== undefined ) ? height : 10; + this.width = ( width !== undefined ) ? width : 10; + this.height = ( height !== undefined ) ? height : 10; -} - -RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), { + this.isRectAreaLight = true; - constructor: RectAreaLight, - - 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,7 @@ RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} + export { RectAreaLight }; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index da921df3b20e79..a59a4970f510a4 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.type = 'SpotLight'; - this.position.copy( Object3D.DefaultUp ); - this.updateMatrix(); + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); - this.target = new Object3D(); + this.target = new Object3D(); - Object.defineProperty( this, 'power', { - get: function () { + 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. - // 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.shadow = new SpotLightShadow(); - }, - set: function ( power ) { + this.isSpotLight = true; - // 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,7 @@ SpotLight.prototype = Object.assign( Object.create( Light.prototype ), { } -} ); +} export { SpotLight }; diff --git a/src/lights/SpotLightShadow.js b/src/lights/SpotLightShadow.js index eeef01b898a282..72a493de67b1ef 100644 --- a/src/lights/SpotLightShadow.js +++ b/src/lights/SpotLightShadow.js @@ -2,19 +2,16 @@ 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() { -} - -SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { - - constructor: SpotLightShadow, + super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); + this.isSpotLightShadow = true; - isSpotLightShadow: true, + } - updateMatrices: function ( light ) { + updateMatrices( light ) { const camera = this.camera; @@ -31,11 +28,11 @@ SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype } - LightShadow.prototype.updateMatrices.call( this, light ); + super.updateMatrices( light ); } -} ); +} export { SpotLightShadow }; From 3916b5c927aa95d40d92b1a7df34bc605df718d3 Mon Sep 17 00:00:00 2001 From: Rawr Date: Wed, 5 Aug 2020 20:02:46 +1200 Subject: [PATCH 02/12] linting --- src/lights/HemisphereLight.js | 2 +- src/lights/HemisphereLightProbe.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index fdca5a9ae21cba..f48862900cd452 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -7,7 +7,7 @@ class HemisphereLight extends Light { constructor( skyColor, groundColor, intensity ) { super( skyColor, intensity ); - + this.type = 'HemisphereLight'; this.castShadow = undefined; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index 68c1dfdb5d3dff..22301efae03440 100644 --- a/src/lights/HemisphereLightProbe.js +++ b/src/lights/HemisphereLightProbe.js @@ -7,7 +7,7 @@ class HemisphereLightProbe extends LightProbe { constructor( skyColor, groundColor, intensity ) { super( undefined, intensity ); - + const color1 = new Color().set( skyColor ); const color2 = new Color().set( groundColor ); From ac0c76435cf9554380b610e353e5788754f1adea Mon Sep 17 00:00:00 2001 From: Rawr Date: Sat, 15 Aug 2020 12:57:24 +1200 Subject: [PATCH 03/12] is* adjustment --- src/lights/AmbientLight.js | 2 +- src/lights/AmbientLightProbe.js | 3 +-- src/lights/DirectionalLight.js | 2 +- src/lights/DirectionalLightShadow.js | 3 +-- src/lights/HemisphereLight.js | 3 +-- src/lights/HemisphereLightProbe.js | 3 +-- src/lights/Light.js | 3 +-- src/lights/LightProbe.js | 3 +-- src/lights/LightShadow.js | 1 + src/lights/PointLight.js | 3 +-- src/lights/PointLightShadow.js | 3 +-- src/lights/RectAreaLight.js | 3 +-- src/lights/SpotLight.js | 3 +-- src/lights/SpotLightShadow.js | 2 +- 14 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index 5f63ed093f60af..ec595d50fa382d 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -8,11 +8,11 @@ class AmbientLight extends Light { this.type = 'AmbientLight'; this.castShadow = undefined; - this.isAmbientLight = true; } } +AmbientLight.prototype.isAmbientLight = true; export { AmbientLight }; diff --git a/src/lights/AmbientLightProbe.js b/src/lights/AmbientLightProbe.js index bb411dd8c50675..cbd2ac9bcece00 100644 --- a/src/lights/AmbientLightProbe.js +++ b/src/lights/AmbientLightProbe.js @@ -7,8 +7,6 @@ class AmbientLightProbe extends LightProbe { super( undefined, intensity ); - this.isAmbientLightProbe = true; - const color1 = new Color().set( color ); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); @@ -36,5 +34,6 @@ class AmbientLightProbe extends LightProbe { } +AmbientLightProbe.prototype.isAmbientLightProbe = true; export { AmbientLightProbe }; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index 32830d7a4c75ad..f1d75a98206705 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -15,7 +15,6 @@ class DirectionalLight extends Light { this.target = new Object3D(); this.shadow = new DirectionalLightShadow(); - this.isDirectionalLight = true; } @@ -33,5 +32,6 @@ class DirectionalLight extends Light { } +DirectionalLight.prototype.isDirectionalLight = true; export { DirectionalLight }; diff --git a/src/lights/DirectionalLightShadow.js b/src/lights/DirectionalLightShadow.js index 11122e5de349bb..ddaa0069eb75c3 100644 --- a/src/lights/DirectionalLightShadow.js +++ b/src/lights/DirectionalLightShadow.js @@ -7,8 +7,6 @@ class DirectionalLightShadow extends LightShadow { super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); - this.isDirectionalLightShadow = true; - } updateMatrices( light ) { @@ -19,5 +17,6 @@ class DirectionalLightShadow extends LightShadow { } +DirectionalLightShadow.prototype.isDirectionalLightShadow = true; export { DirectionalLightShadow }; diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index f48862900cd452..f7b37f0e431b58 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -17,8 +17,6 @@ class HemisphereLight extends Light { this.groundColor = new Color( groundColor ); - this.isHemisphereLight = true; - } copy( source ) { @@ -33,5 +31,6 @@ class HemisphereLight extends Light { } +HemisphereLight.prototype.isHemisphereLight = true; export { HemisphereLight }; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index 22301efae03440..afd524d1de4969 100644 --- a/src/lights/HemisphereLightProbe.js +++ b/src/lights/HemisphereLightProbe.js @@ -21,8 +21,6 @@ class HemisphereLightProbe extends LightProbe { this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); - this.isHemisphereLightProbe = true; - } copy( source ) { // modifying colors not currently supported @@ -45,5 +43,6 @@ class HemisphereLightProbe extends LightProbe { } +HemisphereLightProbe.prototype.isHemisphereLightProbe = true; export { HemisphereLightProbe }; diff --git a/src/lights/Light.js b/src/lights/Light.js index d35a5103aa7cc0..1fe4da09ff42d4 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -14,8 +14,6 @@ class Light extends Object3D { this.receiveShadow = undefined; - this.isLight = true; - } copy( source ) { @@ -51,5 +49,6 @@ class Light extends Object3D { } +Light.prototype.isLight = true; export { Light }; diff --git a/src/lights/LightProbe.js b/src/lights/LightProbe.js index f9c090cc3f38a4..1a97f369131186 100644 --- a/src/lights/LightProbe.js +++ b/src/lights/LightProbe.js @@ -10,8 +10,6 @@ class LightProbe extends Light { this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); - this.isLightProbe = true; - } copy( source ) { @@ -45,5 +43,6 @@ class LightProbe extends Light { } +LightProbe.prototype.isLightProbe = true; export { LightProbe }; diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index febbe41e889020..a5449d7aa666ba 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -133,5 +133,6 @@ class LightShadow { } +LightShadow.prototype.isLightShadow = true; export { LightShadow }; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 07eff7845124bc..5781a3a8ea4fa0 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -14,8 +14,6 @@ class PointLight extends Light { this.shadow = new PointLightShadow(); - this.isPointLight = true; - } get power() { @@ -49,5 +47,6 @@ class PointLight extends Light { } +PointLight.prototype.isPointLight = true; export { PointLight }; diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index 86aac0df1ed956..7b4996f8e67b92 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -51,8 +51,6 @@ class PointLightShadow extends LightShadow { new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 ) ]; - this.isPointLightShadow = true; - } updateMatrices( light, viewportIndex ) { @@ -83,5 +81,6 @@ class PointLightShadow extends LightShadow { } +PointLightShadow.prototype.isPointLightShadow = true; export { PointLightShadow }; diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js index a429437f581905..449e9ca2a32e9b 100644 --- a/src/lights/RectAreaLight.js +++ b/src/lights/RectAreaLight.js @@ -10,8 +10,6 @@ class RectAreaLight extends Light { this.width = ( width !== undefined ) ? width : 10; this.height = ( height !== undefined ) ? height : 10; - this.isRectAreaLight = true; - } copy( source ) { @@ -38,5 +36,6 @@ class RectAreaLight extends Light { } +RectAreaLight.prototype.isRectAreaLight = true; export { RectAreaLight }; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index a59a4970f510a4..9e7dd1b4daaa11 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -21,8 +21,6 @@ class SpotLight extends Light { this.shadow = new SpotLightShadow(); - this.isSpotLight = true; - } get power() { @@ -60,5 +58,6 @@ class SpotLight extends Light { } +SpotLight.prototype.isSpotLight = true; export { SpotLight }; diff --git a/src/lights/SpotLightShadow.js b/src/lights/SpotLightShadow.js index 72a493de67b1ef..3ad37ae9b09993 100644 --- a/src/lights/SpotLightShadow.js +++ b/src/lights/SpotLightShadow.js @@ -7,7 +7,6 @@ class SpotLightShadow extends LightShadow { constructor() { super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); - this.isSpotLightShadow = true; } @@ -34,5 +33,6 @@ class SpotLightShadow extends LightShadow { } +SpotLightShadow.prototype.isSpotLightShadow = true; export { SpotLightShadow }; From e6f307ed2480e953ba2f7b82c6557a5d566c3c24 Mon Sep 17 00:00:00 2001 From: Rawr Date: Sat, 15 Aug 2020 13:14:40 +1200 Subject: [PATCH 04/12] _* for unit tests --- src/lights/PointLightShadow.js | 81 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index 7b4996f8e67b92..ea583cb0fb804c 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -9,47 +9,6 @@ class PointLightShadow extends LightShadow { constructor() { super( 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 ) - ]; } @@ -82,5 +41,45 @@ class PointLightShadow extends LightShadow { } PointLightShadow.prototype.isPointLightShadow = true; +PointLightShadow.prototype._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 ) +]; +PointLightShadow.prototype._frameExtents = new Vector2( 4, 2 ); + +PointLightShadow.prototype._viewportCount = 6; + +PointLightShadow.prototype._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 ) +]; + +PointLightShadow.prototype._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 ) +]; export { PointLightShadow }; From 502b2265aba460c20f1b0258433d8fbeb9ebd97e Mon Sep 17 00:00:00 2001 From: Rawr Date: Tue, 18 Aug 2020 14:56:01 +1200 Subject: [PATCH 05/12] _frameExtents adjustment. --- src/lights/PointLightShadow.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index ea583cb0fb804c..674a7a254910e9 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -10,6 +10,8 @@ class PointLightShadow extends LightShadow { super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + this._frameExtents = new Vector2( 4, 2 ); + } updateMatrices( light, viewportIndex ) { @@ -45,10 +47,7 @@ PointLightShadow.prototype._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 ) ]; -PointLightShadow.prototype._frameExtents = new Vector2( 4, 2 ); - PointLightShadow.prototype._viewportCount = 6; - PointLightShadow.prototype._viewports = [ // These viewports map a cube-map onto a 2D texture with the // following orientation: @@ -76,7 +75,6 @@ PointLightShadow.prototype._viewports = [ // negative Y new Vector4( 1, 0, 1, 1 ) ]; - PointLightShadow.prototype._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 ) From a63391aeaf56bdddff1ee1e64a0a806bf2014171 Mon Sep 17 00:00:00 2001 From: Rawr Date: Wed, 19 Aug 2020 15:59:37 +1200 Subject: [PATCH 06/12] Object.defineProperty() --- src/lights/AmbientLight.js | 4 ++-- src/lights/AmbientLightProbe.js | 3 +-- src/lights/DirectionalLight.js | 4 ++-- src/lights/DirectionalLightShadow.js | 4 ++-- src/lights/HemisphereLight.js | 3 +-- src/lights/HemisphereLightProbe.js | 4 ++-- src/lights/Light.js | 3 +-- src/lights/LightProbe.js | 4 ++-- src/lights/LightShadow.js | 3 +-- src/lights/PointLight.js | 3 +-- src/lights/PointLightShadow.js | 3 ++- src/lights/RectAreaLight.js | 4 ++-- src/lights/SpotLight.js | 4 ++-- src/lights/SpotLightShadow.js | 4 ++-- 14 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index ec595d50fa382d..a1ed24e16d05a0 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -5,7 +5,9 @@ class AmbientLight extends Light { constructor( color, intensity ) { super( color, intensity ); + this.type = 'AmbientLight'; + Object.defineProperty( this, 'isAmbientLight', true ); this.castShadow = undefined; @@ -13,6 +15,4 @@ class AmbientLight extends Light { } -AmbientLight.prototype.isAmbientLight = true; - export { AmbientLight }; diff --git a/src/lights/AmbientLightProbe.js b/src/lights/AmbientLightProbe.js index cbd2ac9bcece00..378eda1caac222 100644 --- a/src/lights/AmbientLightProbe.js +++ b/src/lights/AmbientLightProbe.js @@ -7,6 +7,7 @@ class AmbientLightProbe extends LightProbe { super( undefined, intensity ); + Object.defineProperty( this, 'isAmbientLightProbe', true ); const color1 = new Color().set( color ); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); @@ -34,6 +35,4 @@ class AmbientLightProbe extends LightProbe { } -AmbientLightProbe.prototype.isAmbientLightProbe = true; - export { AmbientLightProbe }; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index f1d75a98206705..a2cf9355ac6eea 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -7,7 +7,9 @@ class DirectionalLight extends Light { constructor( color, intensity ) { super( color, intensity ); + this.type = 'DirectionalLight'; + Object.defineProperty( this, 'isDirectionalLight', true ); this.position.copy( Object3D.DefaultUp ); this.updateMatrix(); @@ -32,6 +34,4 @@ class DirectionalLight extends Light { } -DirectionalLight.prototype.isDirectionalLight = true; - export { DirectionalLight }; diff --git a/src/lights/DirectionalLightShadow.js b/src/lights/DirectionalLightShadow.js index ddaa0069eb75c3..8904dc9daf86e2 100644 --- a/src/lights/DirectionalLightShadow.js +++ b/src/lights/DirectionalLightShadow.js @@ -7,6 +7,8 @@ class DirectionalLightShadow extends LightShadow { super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); + Object.defineProperty( this, 'isDirectionalLightShadow', true ); + } updateMatrices( light ) { @@ -17,6 +19,4 @@ class DirectionalLightShadow extends LightShadow { } -DirectionalLightShadow.prototype.isDirectionalLightShadow = true; - export { DirectionalLightShadow }; diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index f7b37f0e431b58..a180b8bec94433 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -9,6 +9,7 @@ class HemisphereLight extends Light { super( skyColor, intensity ); this.type = 'HemisphereLight'; + Object.defineProperty( this, 'isHemisphereLight', true ); this.castShadow = undefined; @@ -31,6 +32,4 @@ class HemisphereLight extends Light { } -HemisphereLight.prototype.isHemisphereLight = true; - export { HemisphereLight }; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index afd524d1de4969..112a35b62598bf 100644 --- a/src/lights/HemisphereLightProbe.js +++ b/src/lights/HemisphereLightProbe.js @@ -8,6 +8,8 @@ class HemisphereLightProbe extends LightProbe { super( undefined, intensity ); + Object.defineProperty( this, 'isHemisphereLightProbe', true ); + const color1 = new Color().set( skyColor ); const color2 = new Color().set( groundColor ); @@ -43,6 +45,4 @@ class HemisphereLightProbe extends LightProbe { } -HemisphereLightProbe.prototype.isHemisphereLightProbe = true; - export { HemisphereLightProbe }; diff --git a/src/lights/Light.js b/src/lights/Light.js index 1fe4da09ff42d4..317dfceae5edc0 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -8,6 +8,7 @@ class Light extends Object3D { super(); this.type = 'Light'; + Object.defineProperty( this, 'isLight', true ); this.color = new Color( color ); this.intensity = intensity !== undefined ? intensity : 1; @@ -49,6 +50,4 @@ class Light extends Object3D { } -Light.prototype.isLight = true; - export { Light }; diff --git a/src/lights/LightProbe.js b/src/lights/LightProbe.js index 1a97f369131186..b903dfe4999778 100644 --- a/src/lights/LightProbe.js +++ b/src/lights/LightProbe.js @@ -6,7 +6,9 @@ class LightProbe extends Light { constructor( sh, intensity ) { super( undefined, intensity ); + this.type = 'LightProbe'; + Object.defineProperty( this, 'isLightProbe', true ); this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); @@ -43,6 +45,4 @@ class LightProbe extends Light { } -LightProbe.prototype.isLightProbe = true; - export { LightProbe }; diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index a5449d7aa666ba..72719325715809 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -8,6 +8,7 @@ class LightShadow { constructor( camera ) { + Object.defineProperty( this, 'isLightShadow', true ); this.camera = camera; this.bias = 0; @@ -133,6 +134,4 @@ class LightShadow { } -LightShadow.prototype.isLightShadow = true; - export { LightShadow }; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 5781a3a8ea4fa0..864fa3af83b187 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -8,6 +8,7 @@ class PointLight extends Light { super( color, intensity ); this.type = 'PointLight'; + Object.defineProperty( this, 'isPointLight', true ); this.distance = ( distance !== undefined ) ? distance : 0; this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. @@ -47,6 +48,4 @@ class PointLight extends Light { } -PointLight.prototype.isPointLight = true; - export { PointLight }; diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index ea583cb0fb804c..d3bc7dc5a46789 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -10,6 +10,8 @@ class PointLightShadow extends LightShadow { super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + Object.defineProperty( this, 'isPointLightShadow', true ); + } updateMatrices( light, viewportIndex ) { @@ -40,7 +42,6 @@ class PointLightShadow extends LightShadow { } -PointLightShadow.prototype.isPointLightShadow = true; PointLightShadow.prototype._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 ) diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js index 449e9ca2a32e9b..68a3027b4019ae 100644 --- a/src/lights/RectAreaLight.js +++ b/src/lights/RectAreaLight.js @@ -5,7 +5,9 @@ class RectAreaLight extends Light { constructor( color, intensity, width, height ) { super( color, intensity ); + this.type = 'RectAreaLight'; + Object.defineProperty( this, 'isRectAreaLight', true ); this.width = ( width !== undefined ) ? width : 10; this.height = ( height !== undefined ) ? height : 10; @@ -36,6 +38,4 @@ class RectAreaLight extends Light { } -RectAreaLight.prototype.isRectAreaLight = true; - export { RectAreaLight }; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index 9e7dd1b4daaa11..2fb977fa35a7bc 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -7,7 +7,9 @@ class SpotLight extends Light { constructor( color, intensity, distance, angle, penumbra, decay ) { super( color, intensity ); + this.type = 'SpotLight'; + Object.defineProperty( this, 'isSpotLight', true ); this.position.copy( Object3D.DefaultUp ); this.updateMatrix(); @@ -58,6 +60,4 @@ class SpotLight extends Light { } -SpotLight.prototype.isSpotLight = true; - export { SpotLight }; diff --git a/src/lights/SpotLightShadow.js b/src/lights/SpotLightShadow.js index 3ad37ae9b09993..ecf93f6ad460d2 100644 --- a/src/lights/SpotLightShadow.js +++ b/src/lights/SpotLightShadow.js @@ -8,6 +8,8 @@ class SpotLightShadow extends LightShadow { super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); + Object.defineProperty( this, 'isSpotLightShadow', true ); + } updateMatrices( light ) { @@ -33,6 +35,4 @@ class SpotLightShadow extends LightShadow { } -SpotLightShadow.prototype.isSpotLightShadow = true; - export { SpotLightShadow }; From ecafe5fc79a5665d74b195d0ecedc2cc4517b5bb Mon Sep 17 00:00:00 2001 From: Rawr Date: Wed, 19 Aug 2020 16:02:57 +1200 Subject: [PATCH 07/12] linting --- src/lights/PointLightShadow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index d769b5992b9249..570344778139d0 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -11,7 +11,7 @@ class PointLightShadow extends LightShadow { super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); Object.defineProperty( this, 'isPointLightShadow', true ); - + this._frameExtents = new Vector2( 4, 2 ); } From 1c91cbe222317c259eba526407046c472d03a853 Mon Sep 17 00:00:00 2001 From: Rawr Date: Wed, 19 Aug 2020 16:45:06 +1200 Subject: [PATCH 08/12] incorrect descriptors --- src/lights/AmbientLight.js | 2 +- src/lights/AmbientLightProbe.js | 3 +- src/lights/DirectionalLight.js | 2 +- src/lights/DirectionalLightShadow.js | 2 +- src/lights/HemisphereLight.js | 2 +- src/lights/HemisphereLightProbe.js | 2 +- src/lights/Light.js | 2 +- src/lights/LightProbe.js | 2 +- src/lights/LightShadow.js | 3 +- src/lights/PointLight.js | 2 +- src/lights/PointLightShadow.js | 77 ++++++++++++++-------------- src/lights/RectAreaLight.js | 2 +- src/lights/SpotLight.js | 2 +- src/lights/SpotLightShadow.js | 2 +- 14 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index a1ed24e16d05a0..46e91c28a20884 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -7,7 +7,7 @@ class AmbientLight extends Light { super( color, intensity ); this.type = 'AmbientLight'; - Object.defineProperty( this, 'isAmbientLight', true ); + Object.defineProperty( this, 'isAmbientLight', { value: true } ); this.castShadow = undefined; diff --git a/src/lights/AmbientLightProbe.js b/src/lights/AmbientLightProbe.js index 378eda1caac222..fa1a64c1a893ea 100644 --- a/src/lights/AmbientLightProbe.js +++ b/src/lights/AmbientLightProbe.js @@ -7,7 +7,8 @@ class AmbientLightProbe extends LightProbe { super( undefined, intensity ); - Object.defineProperty( this, 'isAmbientLightProbe', true ); + Object.defineProperty( this, 'isAmbientLightProbe', { value: true } ); + const color1 = new Color().set( color ); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index a2cf9355ac6eea..88d44487d7664d 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -9,7 +9,7 @@ class DirectionalLight extends Light { super( color, intensity ); this.type = 'DirectionalLight'; - Object.defineProperty( this, 'isDirectionalLight', true ); + Object.defineProperty( this, 'isDirectionalLight', { value: true } ); this.position.copy( Object3D.DefaultUp ); this.updateMatrix(); diff --git a/src/lights/DirectionalLightShadow.js b/src/lights/DirectionalLightShadow.js index 8904dc9daf86e2..cc5a347d1b94fa 100644 --- a/src/lights/DirectionalLightShadow.js +++ b/src/lights/DirectionalLightShadow.js @@ -7,7 +7,7 @@ class DirectionalLightShadow extends LightShadow { super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); - Object.defineProperty( this, 'isDirectionalLightShadow', true ); + Object.defineProperty( this, 'isDirectionalLightShadow', { value: true } ); } diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index a180b8bec94433..3f12a98da97ad5 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -9,7 +9,7 @@ class HemisphereLight extends Light { super( skyColor, intensity ); this.type = 'HemisphereLight'; - Object.defineProperty( this, 'isHemisphereLight', true ); + Object.defineProperty( this, 'isHemisphereLight', { value: true } ); this.castShadow = undefined; diff --git a/src/lights/HemisphereLightProbe.js b/src/lights/HemisphereLightProbe.js index 112a35b62598bf..14eb446790dd00 100644 --- a/src/lights/HemisphereLightProbe.js +++ b/src/lights/HemisphereLightProbe.js @@ -8,7 +8,7 @@ class HemisphereLightProbe extends LightProbe { super( undefined, intensity ); - Object.defineProperty( this, 'isHemisphereLightProbe', true ); + Object.defineProperty( this, 'isHemisphereLightProbe', { value: true } ); const color1 = new Color().set( skyColor ); const color2 = new Color().set( groundColor ); diff --git a/src/lights/Light.js b/src/lights/Light.js index 317dfceae5edc0..18a537d5a284af 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -8,7 +8,7 @@ class Light extends Object3D { super(); this.type = 'Light'; - Object.defineProperty( this, 'isLight', true ); + Object.defineProperty( this, 'isLight', { value: true } ); this.color = new Color( color ); this.intensity = intensity !== undefined ? intensity : 1; diff --git a/src/lights/LightProbe.js b/src/lights/LightProbe.js index b903dfe4999778..0fbb660e9f14bf 100644 --- a/src/lights/LightProbe.js +++ b/src/lights/LightProbe.js @@ -8,7 +8,7 @@ class LightProbe extends Light { super( undefined, intensity ); this.type = 'LightProbe'; - Object.defineProperty( this, 'isLightProbe', true ); + Object.defineProperty( this, 'isLightProbe', { value: true } ); this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index 72719325715809..0feb73e6018a83 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -8,7 +8,8 @@ class LightShadow { constructor( camera ) { - Object.defineProperty( this, 'isLightShadow', true ); + Object.defineProperty( this, 'isLightShadow', { value: true } ); + this.camera = camera; this.bias = 0; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 864fa3af83b187..afebaaac316f9b 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -8,7 +8,7 @@ class PointLight extends Light { super( color, intensity ); this.type = 'PointLight'; - Object.defineProperty( this, 'isPointLight', true ); + Object.defineProperty( this, 'isPointLight', { value: true } ); this.distance = ( distance !== undefined ) ? distance : 0; this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. diff --git a/src/lights/PointLightShadow.js b/src/lights/PointLightShadow.js index 570344778139d0..69ae593708bccf 100644 --- a/src/lights/PointLightShadow.js +++ b/src/lights/PointLightShadow.js @@ -10,8 +10,44 @@ class PointLightShadow extends LightShadow { super( new PerspectiveCamera( 90, 1, 0.5, 500 ) ); - Object.defineProperty( this, 'isPointLightShadow', true ); - + 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 ); } @@ -44,41 +80,4 @@ class PointLightShadow extends LightShadow { } -PointLightShadow.prototype._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 ) -]; -PointLightShadow.prototype._viewportCount = 6; -PointLightShadow.prototype._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 ) -]; -PointLightShadow.prototype._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 ) -]; - export { PointLightShadow }; diff --git a/src/lights/RectAreaLight.js b/src/lights/RectAreaLight.js index 68a3027b4019ae..979e25aabcabf9 100644 --- a/src/lights/RectAreaLight.js +++ b/src/lights/RectAreaLight.js @@ -7,7 +7,7 @@ class RectAreaLight extends Light { super( color, intensity ); this.type = 'RectAreaLight'; - Object.defineProperty( this, 'isRectAreaLight', true ); + Object.defineProperty( this, 'isRectAreaLight', { value: true } ); this.width = ( width !== undefined ) ? width : 10; this.height = ( height !== undefined ) ? height : 10; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index 2fb977fa35a7bc..922e61b096f8ac 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -9,7 +9,7 @@ class SpotLight extends Light { super( color, intensity ); this.type = 'SpotLight'; - Object.defineProperty( this, 'isSpotLight', true ); + Object.defineProperty( this, 'isSpotLight', { value: true } ); this.position.copy( Object3D.DefaultUp ); this.updateMatrix(); diff --git a/src/lights/SpotLightShadow.js b/src/lights/SpotLightShadow.js index ecf93f6ad460d2..e6ac153ddb4630 100644 --- a/src/lights/SpotLightShadow.js +++ b/src/lights/SpotLightShadow.js @@ -8,7 +8,7 @@ class SpotLightShadow extends LightShadow { super( new PerspectiveCamera( 50, 1, 0.5, 500 ) ); - Object.defineProperty( this, 'isSpotLightShadow', true ); + Object.defineProperty( this, 'isSpotLightShadow', { value: true } ); } From a8d86865f273c8fd8500f04443bc0eb0e2100054 Mon Sep 17 00:00:00 2001 From: Rawr Date: Fri, 21 Aug 2020 10:54:25 +1200 Subject: [PATCH 09/12] reverted class constructor syntax --- src/lights/LightShadow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lights/LightShadow.js b/src/lights/LightShadow.js index 0feb73e6018a83..2a05d1b2dcac80 100644 --- a/src/lights/LightShadow.js +++ b/src/lights/LightShadow.js @@ -113,7 +113,7 @@ class LightShadow { clone() { - return new LightShadow().copy( this ); + return new this.constructor().copy( this ); } From b2c7fb885c91ec0b57251ebda1f15f808b34670d Mon Sep 17 00:00:00 2001 From: DefinitelyMaybe Date: Wed, 3 Feb 2021 13:39:31 +1300 Subject: [PATCH 10/12] removed castShadow --- src/lights/AmbientLight.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index 46e91c28a20884..31425c0fa1f41e 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -9,8 +9,6 @@ class AmbientLight extends Light { this.type = 'AmbientLight'; Object.defineProperty( this, 'isAmbientLight', { value: true } ); - this.castShadow = undefined; - } } From 384a005de95918dd47c8c3efd2d932270dbf43ef Mon Sep 17 00:00:00 2001 From: DefinitelyMaybe Date: Wed, 3 Feb 2021 13:40:54 +1300 Subject: [PATCH 11/12] remove castShadow --- src/lights/HemisphereLight.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lights/HemisphereLight.js b/src/lights/HemisphereLight.js index 3f12a98da97ad5..f0b1a684e7bb40 100644 --- a/src/lights/HemisphereLight.js +++ b/src/lights/HemisphereLight.js @@ -11,8 +11,6 @@ class HemisphereLight extends Light { this.type = 'HemisphereLight'; Object.defineProperty( this, 'isHemisphereLight', { value: true } ); - this.castShadow = undefined; - this.position.copy( Object3D.DefaultUp ); this.updateMatrix(); From 932a69e06165623537d82d1430fdc9a79399955b Mon Sep 17 00:00:00 2001 From: DefinitelyMaybe Date: Wed, 3 Feb 2021 13:41:40 +1300 Subject: [PATCH 12/12] remove receiveShadow --- src/lights/Light.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lights/Light.js b/src/lights/Light.js index 493a558a334004..710b822c3cd644 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -13,8 +13,6 @@ class Light extends Object3D { this.color = new Color( color ); this.intensity = intensity; - this.receiveShadow = undefined; - } copy( source ) {