Jump to content

Saving and Loading a Scene


iiceman
 Share

Recommended Posts

Hey there folks,

 

I am still playing around with my very simple mesh editor and I got to a point where I want to save the scene that I have created and later on load it again. I thought I can use the SceneSerializer (found here: http://www.html5gamedevs.com/topic/6039-exporting-a-babylon-scene-to-a-file/) and stringify my scene and then use the SceneLoader to load it again (because thats the only way I could think of to get my scene back) from that string.

 

I ended up with an error that tells me I have no camera defined when reloading the saved scene. So I check and it seems to be true: after serializing the scene there is no camera.

var serializedScene = BABYLON.SceneSerializer.Serialize(scene);var strScene = JSON.stringify(serializedScene);console.log(scene.cameras, serializedScene.cameras);

The console shows a camera for scene.cameras but serializedScene.cameras is just an empty array. Am I doing something wrong here or is it just not how I am supposed to do it?

 

Here is the current version of the editor: http://localhost/babylondev/mapEditor/  Edit: http://p215008.mittwaldserver.info/mapEditor/ (load and save buttons are in the file menu at the top)

 

By the way: right mouse button to select a mesh.

 

Hope you guys can help me out once again here :D

Link to comment
Share on other sites

@Vousk-prodm, thanks for telling me, I'll check that out. It worked in chrome so I thought it was okay :-/

 

@Deltakosh, yeah, looking forward to that. Not sure when I'll have time to try it out, but can't wait :D

 

@RaananW, I used your material editor to prepare the materials. I thought about making it dynamic somehow so that people can create materials with your editor on the fly and use them right away.

 

About the ArcRotateCamera... well, could I just initialize a new camera after loading? But then the problem is that it doesn't even finish loading without the camera, right? I assume that there is a reason why the acr camera gets ignored.... well, if not.. if it's really that easy... would be great if somebody could fix that for me (not sure I can :-/ )

Link to comment
Share on other sites

:-)

If I find the time later today I'll add the ArcRotateCamera to the serializer. I don't see a problem, but will let you know if I find one.

 

About the Material editor - please let me know if you need any help with changing it. I have created a "save" and "load" functionality which stores all images and the serialized babylon material, look at these implementations, maybe they can be handy.

Link to comment
Share on other sites

@RaananW: Thanks! :D

 

@benoit-1842: it's still work in progress and the question that I asked was just about that loading problem. Thanks to RaananW it should be fixed very soon (as soon as I have time to update to the new 2.1 version of Babylon - maybe tonight :D )

Link to comment
Share on other sites

@DK - You know they will just keep on coming  :)

 

@Benoit - Do you mean scenes that were extracted using the serializer? or just a general scene? the never-ending spinning circle usually means that something went wrong suring the scene's loading. Check your console log, or maybe upload the scene here (if possible) and allow it to be debugged.

Link to comment
Share on other sites

Okay, I tried it out now and got only half of a success that I can report. It seems I can now serialize the scene including the camera (good job raanan!) but I am still having trouble loading it back. You can see the error here http://p215008.mittwaldserver.info/mapEditor/ when you just save and then load a scene. In the console it loads the serialized string but says:

 

 

babylon.2.1-alpha.debug.js:7438 - Uncaught TypeError: Cannot read property 'position' of null
ArcRotateCamera.prototype._getTargetPosition = function () {    return this.target.position || this.target;};

It seems that it has something to do with the target of the ArcRotateCamera. I couldn't find the target property in the serialized camera object when I looked for it. Could it be that this is a bug in the newly added code for the ArcRotateCamera serialization or any idea what else might go wrong here?

Link to comment
Share on other sites

Looks like the target is not set. I'll find the possible and push a fix later today.
In the meantime try setting the target manually and see if it works and that this is the only problem.

 

Edit - https://github.com/BabylonJS/Babylon.js/pull/425 , the target property in the ArcRotate camera types has a different name than the rest :-) should be fine now. If yo ucan paste the scene so I can test with the serialized scene it would be great.

Edited by RaananW
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...