Ingo Chou Posted January 17, 2016 Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 17, 2016 Share Posted January 17, 2016 Hello, What exactly is not working ? Did you try to use : var strScene = JSON.stringify(serializedScene); in order to save your json file ? Can you show us an example where your problem appears? Thanks Quote Link to comment Share on other sites More sharing options...
Ingo Chou Posted January 17, 2016 Author Share Posted January 17, 2016 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 17, 2016 Share Posted January 17, 2016 I guess the error is in your variable "myScene". Try (Maybe this will help) : var js = JSON.stringify(jsFile); js = encodeURIComponent(js); Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 17, 2016 Share Posted January 17, 2016 The problem seems to be in your code... Did you set an ambient color for the scene? Are you sure you set a Color3? Can you show us your code ? Quote Link to comment Share on other sites More sharing options...
ChrisR Posted January 17, 2016 Share Posted January 17, 2016 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 Quote Link to comment Share on other sites More sharing options...
Ingo Chou Posted January 18, 2016 Author Share Posted January 18, 2016 Hello, Thanks for all the replies. The scene can be serialized after I updated to the latest version. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.