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

Serialize and load JSON Light .shadow property #9416

Merged
merged 2 commits into from
Aug 4, 2016
Merged

Serialize and load JSON Light .shadow property #9416

merged 2 commits into from
Aug 4, 2016

Conversation

satori99
Copy link
Contributor

  • Add .toJSON() method to LightShadow
  • Light .toJSON() writes .shadow property
  • Parse .shadow property in DirectionLight and Spotlight JSON data

* Add .toJSON() method to LightShadow
* Light .toJSON() writes .shadow property
* Parse .shadow property in DirectionLight and Spotlight JSON data
@satori99
Copy link
Contributor Author

satori99 commented Jul 27, 2016

A DirectionalLight that casts a shadow will be serialized something like this;

{
  "uuid": "24b1e136-e0eb-5fe2-b08b-c2a705bad1c2",
  "type": "DirectionalLight",
  "color": 16777164,
  "intensity": 1.5,
  "castShadow": true,
  "shadow": {
    "mapSize": [512,1024],
    "camera": {
      "type": "OrthographicCamera",
      "top": 7,
      "bottom": -1.5,
      "left": -2.5,
      "right": 2.5,
      "near": 8,
      "far": 32
    }
  },
  "matrix": [1,0,0,0,0,1,0,0,0,0,1,0,8,16,10,1]
}

@@ -50,6 +50,8 @@ Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
if ( this.decay !== undefined ) data.object.decay = this.decay;
if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

if ( this.castShadow && this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if the this.castShadow check is needed. Thinking about the editor case... One could set the shadow parameters but have the castShadow temporarily false. The shadow parameters would then get lost.

@satori99
Copy link
Contributor Author

satori99 commented Jul 27, 2016

The .shadow (LightShadow) property of DirectionalLights and SpotLights is always created by the lights constructor. Even when shadows are not used at all. So this would always be exported I think.

If its acceptable to always export default shadow settings, then I can remove that condition.

alternatively, the camera classes could be altered to only export non-default properties?

@satori99
Copy link
Contributor Author

I removed the castShadow check. I thought about it a bit more, and I think you are right. It doesn't really matter if shadows are used in a scene or not, as that is a renderer setting anyway.

@mrdoob mrdoob merged commit df9a924 into mrdoob:dev Aug 4, 2016
@mrdoob
Copy link
Owner

mrdoob commented Aug 4, 2016

Thanks!

@satori99 satori99 deleted the shadow-json branch August 11, 2016 02:13
aardgoose pushed a commit to aardgoose/three.js that referenced this pull request Oct 7, 2016
* Serialize and load JSON Light .shadow property

* Add .toJSON() method to LightShadow
* Light .toJSON() writes .shadow property
* Parse .shadow property in DirectionLight and Spotlight JSON data

* Remove .castShadow condition when exporting .shadow property to JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants