Skip to content

Commit 84be1bd

Browse files
committed
LightProbe: Add support for serialization/deserialization.
1 parent 902fa09 commit 84be1bd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/lights/LightProbe.js

Lines changed: 3 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,6 @@ 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;
3031

3132
return this;
3233

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

3738
var data = Light.prototype.toJSON.call( this, meta );
3839

39-
// data.sh = this.sh.toArray(); // todo
40+
data.object.sh = this.sh.toArray();
4041

4142
return data;
4243

src/loaders/ObjectLoader.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../constants.js';
2222
import { BufferAttribute } from '../core/BufferAttribute.js';
2323
import { Color } from '../math/Color.js';
24+
import { SphericalHarmonics3 } from '../math/SphericalHarmonics3.js';
2425
import { Object3D } from '../core/Object3D.js';
2526
import { Group } from '../objects/Group.js';
2627
import { InstancedMesh } from '../objects/InstancedMesh.js';
@@ -40,6 +41,7 @@ import { PointLight } from '../lights/PointLight.js';
4041
import { DirectionalLight } from '../lights/DirectionalLight.js';
4142
import { AmbientLight } from '../lights/AmbientLight.js';
4243
import { RectAreaLight } from '../lights/RectAreaLight.js';
44+
import { LightProbe } from '../lights/LightProbe.js';
4345
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
4446
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
4547
import { Scene } from '../scenes/Scene.js';
@@ -817,6 +819,13 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
817819

818820
break;
819821

822+
case 'LightProbe':
823+
824+
var sh = new SphericalHarmonics3().fromArray( data.sh );
825+
object = new LightProbe( sh, data.intensity );
826+
827+
break;
828+
820829
case 'SkinnedMesh':
821830

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

0 commit comments

Comments
 (0)