I am looking for a good strategy or built-in method that can take a runtime scene and convert it to a JSON document that can be saved and loaded in at another time. We’d like to use this as a runtime level editor that saves off and recalls unique instances of a scene.
I’ve seen conversations on this topic from a couple years ago, but they’ve since been lost to time. So, I thought I’d revive the topic as I’m certain others might be interested in a good strategy for this use case.
Any advice on where to start? Should we be using SceneHandler to write/read the scene as JSON?
(edit - looks like SceneHandler cannot write, so what would make sense here?)
We’d be looking to store a custom scene hierarchy, custom template/entity properties, and references to external resources like images, videos, models etc. (all from a blob storage container)
These would be applied at runtime to restore the scene to the editor’s last save state.
Appreciate any clues or leads on this - it’s fundamental to what we’re aiming to deliver with our product.
Another way of doing it, you could export the whole scene as GLB at runtime and then just load it back.
The GLB its self would be your scene.
Thanks for your response and idea.
I’ve considered glb as the container, but would prefer a text based solution over a binary one. We could experiment with the binary if the glb would be able to work with referenced elements over embedded ones.
Have you worked on this flow before?
Thanks again for sharing your suggestion!
GLB file is a container. The main part is text based (json file) which represents the hierarchy, and references either embedded binary data for meshes / textures, or references those as external resources. The limitation here is that this cannot represent complete PlayCanvas scene - only hierarchy with meshes / lights / cameras, but even those don’t store all properties PlayCanvas exposes. But what glb definitely does not have is our components / scripts / their attributes - for this you’d need to write some extension and store those there, but nothing like this is build in.
Hey, it really depends where you are going to store the meshes and files? In that case I would still export as glb with other Json file called something like
scene-configuration.json that holds references to Playcanvas specific stuff like
scripts, lighting, rendering, etc.
@mvaligursky @Lukas_31 - Thanks for the replies.
I think we’ll try and move forward with a blended approach that includes mesh, texture, and scene information as GLB (we mostly wanted this for compatibility with other external 3D editors) and some form of JSON to handle the unique components and template instances that will make up the remaining aspects of our custom level instances. We’ll run that all through a handy scene constructor/serializer to achieve an initial result we can build up.
Always nice to ask if there’s an easier way to do it before writing up your own
Appreciate the rapid response - you are awesome!