Dad72 Posted January 26, 2018 Share Posted January 26, 2018 Hello, 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) http://www.babylonjs-playground.com/#0ESEBT#1 The json to copy to the PG in the attached file: Teste.babylon Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 http://pryme8.github.io/cloneScene/ got you fam. https://github.com/Pryme8/Pryme8.github.io/blob/master/cloneScene/index.html#L82 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2018 Author Share Posted January 26, 2018 You tell me about scene cloning, but my problem here is reloading a scene serialize. The scene serialized does not reload correctly. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2018 Author Share Posted January 26, 2018 2 minutes ago, Pryme8 said: I can load your specific json example if you need? Yes, please, I'm not sure I understand. Thank you Pryme Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2018 Author Share Posted January 26, 2018 I tried with LOD too and it did not work. I think a serialized scene does not load correctly. A bug in the serialization? or reloading? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 It looks like you were double serializing. when its in .babylon format its already serialized. I had the above one I posted working with the .babylon file you sent me. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2018 Author Share Posted January 26, 2018 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted January 26, 2018 Share Posted January 26, 2018 serializedJson = JSON.stringify(BABYLON.SceneSerializer.Serialize(serialized)); the babylon object is already "serialized" so 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. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 26, 2018 Author Share Posted January 26, 2018 Ok, I fix the problem. 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.