Skip to content

Commit d26c835

Browse files
authored
Merge pull request #18966 from Mugen87/dev48
LightProbe: Add support for serialization/deserialization.
2 parents 66cbb3c + c079016 commit d26c835

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/lights/LightProbe.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export class LightProbe extends Light {
88
readonly isLightProbe: true;
99
sh: SphericalHarmonics3;
1010

11+
fromJSON( json: object ): LightProbe;
12+
1113
}

src/lights/LightProbe.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function LightProbe( sh, intensity ) {
1111

1212
Light.call( this, undefined, intensity );
1313

14+
this.type = 'LightProbe';
15+
1416
this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
1517

1618
}
@@ -26,7 +28,15 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
2628
Light.prototype.copy.call( this, source );
2729

2830
this.sh.copy( source.sh );
29-
this.intensity = source.intensity;
31+
32+
return this;
33+
34+
},
35+
36+
fromJSON: function ( json ) {
37+
38+
this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
39+
this.sh.fromArray( json.sh );
3040

3141
return this;
3242

@@ -36,7 +46,7 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
3646

3747
var data = Light.prototype.toJSON.call( this, meta );
3848

39-
// data.sh = this.sh.toArray(); // todo
49+
data.object.sh = this.sh.toArray();
4050

4151
return data;
4252

src/loaders/ObjectLoader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { PointLight } from '../lights/PointLight.js';
4040
import { DirectionalLight } from '../lights/DirectionalLight.js';
4141
import { AmbientLight } from '../lights/AmbientLight.js';
4242
import { RectAreaLight } from '../lights/RectAreaLight.js';
43+
import { LightProbe } from '../lights/LightProbe.js';
4344
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
4445
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
4546
import { Scene } from '../scenes/Scene.js';
@@ -817,6 +818,12 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
817818

818819
break;
819820

821+
case 'LightProbe':
822+
823+
object = new LightProbe().fromJSON( data );
824+
825+
break;
826+
820827
case 'SkinnedMesh':
821828

822829
console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );

0 commit comments

Comments
 (0)