Skip to content

Commit 39104f3

Browse files
committed
HemisphereLightProbe: Convert to ES6 class
1 parent 006c128 commit 39104f3

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

src/lights/HemisphereLightProbe.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,29 @@ import { Color } from '../math/Color.js';
22
import { Vector3 } from '../math/Vector3.js';
33
import { LightProbe } from './LightProbe.js';
44

5-
function HemisphereLightProbe( skyColor, groundColor, intensity ) {
5+
class HemisphereLightProbe extends LightProbe {
66

7-
LightProbe.call( this, undefined, intensity );
7+
constructor( skyColor, groundColor, intensity = 1 ) {
88

9-
const color1 = new Color().set( skyColor );
10-
const color2 = new Color().set( groundColor );
9+
super( undefined, intensity );
1110

12-
const sky = new Vector3( color1.r, color1.g, color1.b );
13-
const ground = new Vector3( color2.r, color2.g, color2.b );
11+
Object.defineProperty( this, 'isHemisphereLightProbe', { value: true } );
1412

15-
// without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
16-
const c0 = Math.sqrt( Math.PI );
17-
const c1 = c0 * Math.sqrt( 0.75 );
13+
const color1 = new Color().set( skyColor );
14+
const color2 = new Color().set( groundColor );
1815

19-
this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
20-
this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
16+
const sky = new Vector3( color1.r, color1.g, color1.b );
17+
const ground = new Vector3( color2.r, color2.g, color2.b );
2118

22-
}
23-
24-
HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
25-
26-
constructor: HemisphereLightProbe,
27-
28-
isHemisphereLightProbe: true,
29-
30-
copy: function ( source ) { // modifying colors not currently supported
31-
32-
LightProbe.prototype.copy.call( this, source );
19+
// without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
20+
const c0 = Math.sqrt( Math.PI );
21+
const c1 = c0 * Math.sqrt( 0.75 );
3322

34-
return this;
35-
36-
},
37-
38-
toJSON: function ( meta ) {
39-
40-
const data = LightProbe.prototype.toJSON.call( this, meta );
41-
42-
// data.sh = this.sh.toArray(); // todo
43-
44-
return data;
23+
this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
24+
this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
4525

4626
}
4727

48-
} );
28+
}
4929

5030
export { HemisphereLightProbe };

0 commit comments

Comments
 (0)