Jump to content

saving and loading meshes


vahith
 Share

Recommended Posts

hi all,
i can achieve the scene saving and loading, but what i expecting is i want to save the single mesh and its child instead of saving all the scene.then i want to load the saved mesh. how i can achieve this.kindly suggest me some eg and method to achieve



thanks
vahi

Link to comment
Share on other sites

Hi vahith,

 

 

The SceneSerializer doesn't have this functionality. Adding it should not be a problem - but! we are in a code freeze for version 2.1. So, no new features :-)

What you can do however is use the scene serializer, then iterate through all of the meshes and remove the ones you don't need.

If you are looking for a way to load a single mesh, JohnK gave you the best answer - ImportMesh of the scne loader will load a single mesh from an entire babylon file.

I will keep that as a feature for 2.2. Maybe more people are interested in such a functionality.

Link to comment
Share on other sites

  • 1 month later...

@RaananW true to your word I see you have added SerializeMesh to 2.2. Unfortunately I am having problems getting it to work.

 

Using testsave.html I used console.log() to output and copy the JSON string and copied it to testbox.babylon. The using testload.html I tried using ImportMesh to load the mesh and just got a blankscreen.

 

When I modified testsave.html by changing

var serializedMesh = BABYLON.SceneSerializer.SerializeMesh(box);

to saving the whole scene

var serializedMesh = BABYLON.SceneSerializer.Serialize(scene);

and copied the resulting JSON string into testboxscene.babylon and then used testload.html (changing the filename) I obtained the correct mesh.

 

 

Any help would be much appreciated.

 

Over the last few weeks I have been plodding on with my project and have just got to the part when I want to save and open particular meshes so the SerializeMesh function is just what I want, well nearly - but one thing at a time.

Link to comment
Share on other sites

@Ranaan thank you for that - now the cheeky bit. I am creating "models" which are combinations of one or more meshes. So for me it would be very useful if SerializeMesh could take as its first parameter not only a single mesh but also an array of meshes in the same way that ImportMesh can take a single mesh name or an array of mesh names.

 

Would that be too much of a problem?

Link to comment
Share on other sites

Raanan,

I have edits to FileLoader for: Mesh.FreezeWorldMatrix(), Material.checkReadyOnlyOnce, & Camera.setCameraRigMode().  Also AbstractMesh for _waitingFreezeWorldMatrix.

 

Just updated for your MultiMaterials check.  Are you planning to update these in the next day or so?  If so, I probably should PR what I have so far, even without testing yet.  These are new .babylon fields & it is early in alpha, so errors unlikely to impact others.

 

Jeff

Link to comment
Share on other sites

@RaananW

 

I might be a bit slow but I get there in the end. I have worked out how to use SerializeMesh to save an array of meshes.

       var serializedMesh;       var meshes_to_save = {                        "materials": [],                        "geometries":    {    "boxes":[],                                            "spheres":[],                                            "cylinders":[],                                            "toruses":[],                                            "grounds":[],                                            "planes":[],                                            "torusKnots":[],                                            "vertexData":[]                        },                        "meshes": []            };        for(var i = 0; i<meshesArray.length; i++) {            serializedMesh = BABYLON.SceneSerializer.SerializeMesh(meshesArray[i]);                       meshes_to_save["materials"].push(serializedMesh["materials"][0]);            meshes_to_save["geometries"]["vertexData"].push(serializedMesh["geometries"]["vertexData"][0]);            meshes_to_save["meshes"].push(serializedMesh["meshes"][0]);        }        var strMesh = JSON.stringify(meshes_to_save);
Link to comment
Share on other sites

Hi John,

 

I have already implemented a solution, but I am not happy with the result, mainly due to one (silly!) little thing - the name of the function, SerializeMesh hints (clearly :-) ) that it serializes a single mesh. So a new functions should be implemented, SerialzeMeshes. but this is just semantics!... The ImportMesh does exactly the same thing - it can load a few meshes or just one single mesh. It is still called ImportMesh and not ImportMeshes... 

In my new implementation the serialize mesh function accepts either a mesh or an array of meshes. I just need to mentally accept it :-)

I will soon push my changes, I guess later on today.

Link to comment
Share on other sites

Hi John, I just pushed a new version of the SerializeMesh function, extending its functionality. It no accepts either an array of meshes or a single mesh. There is also a flag - withParents (boolean) to add the meshes' parents to the serialization party.

Wait a bit until it is integrated into the main js file and play with it, let me know if its working as you wanted.

Link to comment
Share on other sites

SerializeMesh( meshes_array)  works just as I needed thank you very much. Will be trying out the setting parents option in the next few days when I get to that bit in my project.

 

Thank you again.

Cannot set your previous post as the answer as I did not start the thread.

Link to comment
Share on other sites

  • 2 years later...

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...