Jump to content

How to serialize a scene ?


Ingo Chou
 Share

Recommended Posts

Hello,

How to serialize a scene ?

My scene is modified by the code.

I want to serialize my scene and save the JSON file for next time loading.

I use this code :

var jsFile = BABYLON.SceneSerializer.Serialize(myScene);


but it does not work. 

Thanks for your reply and help.

Link to comment
Share on other sites

Hello,

The following is my code, and I make sure 'myScene' is my scene object. 

var saveToJS = function () {
        var jsFile = BABYLON.SceneSerializer.Serialize(myScene);   //alert('ok')
        var js = JSON.stringify(jsFile);
        return js;
    }


 

I cannot get the results of the serialize function.

The website will crash when call this function:

var jsFile = BABYLON.SceneSerializer.Serialize(myScene);

The alert('ok') function in my code is not called.

Debug result is:

locate:   ambientColor.asArray() in function Serialize()

desc:   JavaScript runtime error: Unable to get property 'asArray' of undefined or null reference

Must I set the ambient color for every object? 

I just added several meshes and  lines.

It can serialize if the scene is empty.

Thanks for your help.

 

 

 

Link to comment
Share on other sites

I had this similar error a while back in serializing a scene. I had to modify the babylonjs code to put checks in to not serialize parts of materials that weren't there. However in the latest version of babylon this is fixed. Try using one of these babylonjs files to see if it fixes the problem

https://github.com/BabylonJS/Babylon.js/tree/master/dist/preview release

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...