Skip to content

Commit 4eb500d

Browse files
committed
LightShadow: Convert to ES6 class
1 parent 31545b9 commit 4eb500d

File tree

1 file changed

+46
-52
lines changed

1 file changed

+46
-52
lines changed

src/lights/LightShadow.js

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,68 @@ import { Vector3 } from '../math/Vector3.js';
44
import { Vector4 } from '../math/Vector4.js';
55
import { Frustum } from '../math/Frustum.js';
66

7-
function LightShadow( camera ) {
7+
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
8+
const _lightPositionWorld = /*@__PURE__*/ new Vector3();
9+
const _lookTarget = /*@__PURE__*/ new Vector3();
810

9-
this.camera = camera;
11+
class LightShadow {
1012

11-
this.bias = 0;
12-
this.normalBias = 0;
13-
this.radius = 1;
13+
constructor( camera ) {
1414

15-
this.mapSize = new Vector2( 512, 512 );
15+
this.camera = camera;
1616

17-
this.map = null;
18-
this.mapPass = null;
19-
this.matrix = new Matrix4();
17+
this.bias = 0;
18+
this.normalBias = 0;
19+
this.radius = 1;
2020

21-
this.autoUpdate = true;
22-
this.needsUpdate = false;
21+
this.mapSize = new Vector2( 512, 512 );
2322

24-
this._frustum = new Frustum();
25-
this._frameExtents = new Vector2( 1, 1 );
23+
this.map = null;
24+
this.mapPass = null;
25+
this.matrix = new Matrix4();
2626

27-
this._viewportCount = 1;
27+
this.autoUpdate = true;
28+
this.needsUpdate = false;
2829

29-
this._viewports = [
30+
this._frustum = new Frustum();
31+
this._frameExtents = new Vector2( 1, 1 );
3032

31-
new Vector4( 0, 0, 1, 1 )
33+
this._viewportCount = 1;
3234

33-
];
35+
this._viewports = [
3436

35-
}
36-
37-
Object.assign( LightShadow.prototype, {
37+
new Vector4( 0, 0, 1, 1 )
3838

39-
_projScreenMatrix: new Matrix4(),
39+
];
4040

41-
_lightPositionWorld: new Vector3(),
42-
43-
_lookTarget: new Vector3(),
41+
}
4442

45-
getViewportCount: function () {
43+
getViewportCount() {
4644

4745
return this._viewportCount;
4846

49-
},
47+
}
5048

51-
getFrustum: function () {
49+
getFrustum() {
5250

5351
return this._frustum;
5452

55-
},
53+
}
5654

57-
updateMatrices: function ( light ) {
55+
updateMatrices( light ) {
5856

59-
const shadowCamera = this.camera,
60-
shadowMatrix = this.matrix,
61-
projScreenMatrix = this._projScreenMatrix,
62-
lookTarget = this._lookTarget,
63-
lightPositionWorld = this._lightPositionWorld;
57+
const shadowCamera = this.camera;
58+
const shadowMatrix = this.matrix;
6459

65-
lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
66-
shadowCamera.position.copy( lightPositionWorld );
60+
_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
61+
shadowCamera.position.copy( _lightPositionWorld );
6762

68-
lookTarget.setFromMatrixPosition( light.target.matrixWorld );
69-
shadowCamera.lookAt( lookTarget );
63+
_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
64+
shadowCamera.lookAt( _lookTarget );
7065
shadowCamera.updateMatrixWorld();
7166

72-
projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
73-
this._frustum.setFromProjectionMatrix( projScreenMatrix );
67+
_projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
68+
this._frustum.setFromProjectionMatrix( _projScreenMatrix );
7469

7570
shadowMatrix.set(
7671
0.5, 0.0, 0.0, 0.5,
@@ -82,21 +77,21 @@ Object.assign( LightShadow.prototype, {
8277
shadowMatrix.multiply( shadowCamera.projectionMatrix );
8378
shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
8479

85-
},
80+
}
8681

87-
getViewport: function ( viewportIndex ) {
82+
getViewport( viewportIndex ) {
8883

8984
return this._viewports[ viewportIndex ];
9085

91-
},
86+
}
9287

93-
getFrameExtents: function () {
88+
getFrameExtents() {
9489

9590
return this._frameExtents;
9691

97-
},
92+
}
9893

99-
copy: function ( source ) {
94+
copy( source ) {
10095

10196
this.camera = source.camera.clone();
10297

@@ -107,15 +102,15 @@ Object.assign( LightShadow.prototype, {
107102

108103
return this;
109104

110-
},
105+
}
111106

112-
clone: function () {
107+
clone() {
113108

114109
return new this.constructor().copy( this );
115110

116-
},
111+
}
117112

118-
toJSON: function () {
113+
toJSON() {
119114

120115
const object = {};
121116

@@ -131,7 +126,6 @@ Object.assign( LightShadow.prototype, {
131126

132127
}
133128

134-
} );
135-
129+
}
136130

137131
export { LightShadow };

0 commit comments

Comments
 (0)