Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightProbe: Add support for serialization/deserialization. #18966

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lights/LightProbe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export class LightProbe extends Light {
readonly isLightProbe: true;
sh: SphericalHarmonics3;

fromJSON( json: object ): LightProbe;

}
14 changes: 12 additions & 2 deletions src/lights/LightProbe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function LightProbe( sh, intensity ) {

Light.call( this, undefined, intensity );

this.type = 'LightProbe';

this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();

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

this.sh.copy( source.sh );
this.intensity = source.intensity;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intensity is already copied in Light.copy().

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a FYI, seems like @WestLangley is thinking of removing that inheritance. #18371 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing, good to know! Should I keep the code as it is now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so -- for now.


return this;

},

fromJSON: function ( json ) {

this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
this.sh.fromArray( json.sh );

return this;

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

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

// data.sh = this.sh.toArray(); // todo
data.object.sh = this.sh.toArray();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data.object.sh?

Copy link
Collaborator Author

@Mugen87 Mugen87 Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, check out Light.toJSON():

data.object.intensity = this.intensity;


return data;

Expand Down
7 changes: 7 additions & 0 deletions src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { PointLight } from '../lights/PointLight.js';
import { DirectionalLight } from '../lights/DirectionalLight.js';
import { AmbientLight } from '../lights/AmbientLight.js';
import { RectAreaLight } from '../lights/RectAreaLight.js';
import { LightProbe } from '../lights/LightProbe.js';
import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
import { Scene } from '../scenes/Scene.js';
Expand Down Expand Up @@ -817,6 +818,12 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

break;

case 'LightProbe':

object = new LightProbe().fromJSON( data );

break;

case 'SkinnedMesh':

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