Jump to content

scene serialized and reload problem


Recommended Posts


I serialize a scene with a single field and 2, 3 meches, but when I reload this scene serialize, there are problems that I can not understand.

Here is the PG: (I could not record on the PG because the Json is too long so I put it below as an attachment, it will copy the code in the PG)


The json to copy to the PG in the attached file:


Link to comment
Share on other sites

There are a few errors I can see by looking really quick, the major one being a timing issue.  When I get into the office Ill take a look once I get a chance.  I do know it will be hard to make this on the PG, because of timing issues and not having access to the render loop.

Link to comment
Share on other sites

because of timing, you are already returning the "scene" object so its scope is set to the initial return.  You cant overwrite this unless you call the variable outside the scope that it was already returned from.  This shows how to correctly do it, I can load your specific json example if you need?

hmm I just noticed you were using append not load... strike my comment about scope because I think append should overwrite the scene its pointing to.

Link to comment
Share on other sites

var serialized = '';//Past BJS file here.;

var createScene = function () {
    var scene = new BABYLON.Scene(engine);    
    var camera = new BABYLON.FreeCamera("cameraUser", new BABYLON.Vector3(0, 7, -10), scene);
    var serializedJson = JSON.stringify(serialized);
    BABYLON.SceneLoader.Append('', 'data:'+serializedJson, scene, function(newScene) {       
        //scene = newScene;				
    return scene;

now that I saw you were using append.  My bad... I am known to over think things.

Link to comment
Share on other sites

13 minutes ago, Pryme8 said:

It looks like you were double serializing.  when its in .babylon format its already serialized.

What does it mean ? how can double serialization happen?

I think I must be tired right now, I have a hard time understanding a lot of things.

Link to comment
Share on other sites

serializedJson = JSON.stringify(BABYLON.SceneSerializer.Serialize(serialized));

the babylon object is already "serialized"
serializedJson = JSON.stringify(serialized);
You would do 
serializedJson = JSON.stringify(BABYLON.SceneSerializer.Serialize(scene));
to turn a scene into a serialized object then stringify it.

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.

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.


  • Recently Browsing   0 members

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