BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

Lights aren't exporting in .glb and .gltf formats #104

Closed tylerchurch closed 4 years ago

tylerchurch commented 5 years ago

Hello,

I've tried both the editor on http://editor.babylonjs.com and I have 2.3.0 installed locally, and I noticed that when I export as .glb or .gltf I don't see any lights get loaded when I try to load the scene in the Babylon.js application we've written.

To test the simplest possible case, I did the following:

  1. Went to Project -> New Project
  2. Selected "Yes" when it asked if I wanted to remove the current scene and create a new one.
  3. Clicked Add -> Hemispheric LIght
  4. Clicked Scene -> Download Scene As
  5. Entered a name, selected GLB as the format, and clicked "Ok"

This is what the simple scene looks like:

simple-scene

Opening the resulting .glb file and saw only this at the top:

JSON{"asset":{"generator":"BabylonJS","version":"2.0"}}

Working with a more complex scene that included meshes and other things, I saw this JSON data get populated with the things I had added, so the fact that the lights are missing seems suspect.

I took a peek at the code, and saw this:

            if (Tags.HasTags(n) && Tags.MatchesQuery(n, 'added')) {
                addNodeToProject = true;

                if (n instanceof AbstractMesh)
                    node.serializationObject = SceneSerializer.SerializeMesh(n, false, false);
                else
                    node.serializationObject = (<Camera | Light> n).serialize();
            }

( This is from https://github.com/BabylonJS/Editor/blob/08d1e28cfee20dd486e082129b3c09c203144885/src/editor/scene/scene-exporter.ts#L441 )

And I can't help but wonder if maybe the added tag somehow isn't on the light? I have no idea how this tagging system works though so I'm not really sure how to debug this further.

If I'm doing something wrong or if there's any additional information I can provide, please let me know! Thanks!

julien-moreau commented 5 years ago

Hey thanks for reporting! Basically, the gltf exporter of the editor just uses the gltf serializer available in the babylonjs serializers library. Maybe @bghgary can help?

The tagging system is used only internally by the editor to know what it has to save when you click « Project -> Save Project »

bghgary commented 5 years ago

glTF 2.0 core spec does not support lights. There is an extension being worked on for lights that is implemented in the loader as an experiment. We can add support for exporting lights once the extension is ready. FYI @kcoley

tylerchurch commented 5 years ago

Hey! Thank you so much for the quick response. I will pursue some other way of handling lighting.

julien-moreau commented 5 years ago

Or is there a smart solution I can implement in the editor ?

tylerchurch commented 5 years ago

@julien-moreau It would be helpful if there was some JSON export or just a straight up code export that listed out the lights (and anything else that doesn't fit into GLTF) and then I could process that somehow in the program I have that's loading the scene.

Another thing we're looking at is the Blender plugin http://doc.babylonjs.com/resources/blender and it seems like that has the same issue with lights, for presumably the same reason.

julien-moreau commented 5 years ago

@tylerchurch, just added an option to export the serialized lights in a separate file (lights.json). Then, you'll have to call BABYLON.Light.Parse for each light in the json file. Will deploy ASAP

julien-moreau commented 5 years ago

@tylerchurch deployed! Are you using the windows local version of the OSX one ?

tylerchurch commented 5 years ago

@julien-moreau awesome! Thank you! I'm using the windows local version.

julien-moreau commented 5 years ago

Updated :) If you want to use the feature right now, please re-download the installer. A new update is coming soon also which fixes some other bugs

julien-moreau commented 5 years ago

Deployed :)

torchesburn commented 4 years ago

so it loads lights now?

julien-moreau commented 4 years ago

Pinging @bghgary to know if the GLTF spec has been updated and know if it now supports lights

bghgary commented 4 years ago

The KHR_lights_punctual glTF extension is supported by both the serializer and the loader.