vahith Posted June 2, 2015 Share Posted June 2, 2015 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 achievethanksvahi Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 2, 2015 Share Posted June 2, 2015 Cannot help you with saving individual meshes but can with loading them. BABYLON.SceneLoader.ImportMesh(....) will load a list of individual meshes. Had problem with this but RanaanW sorted it out. See this topic. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 3, 2015 Share Posted June 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 7, 2015 Share Posted July 7, 2015 @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 changingvar serializedMesh = BABYLON.SceneSerializer.SerializeMesh(box);to saving the whole scenevar 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 7, 2015 Share Posted July 7, 2015 Hi John, I will look into that! Should be working, but hey, we are programmers and we like saying "should be working"... Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 7, 2015 Share Posted July 7, 2015 Hmmm.... Ok, Problem found.I just pushed a fix, it will soon be updated in the playground and in the main JS file.Silly thing - if you want a very quick fix, just addmultiMaterials: []to the scene file. Or check this pull request https://github.com/Cubees/Cubees.github.io/pull/1 :-) Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 7, 2015 Share Posted July 7, 2015 @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? Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 7, 2015 Share Posted July 7, 2015 Shouldn't be a problem.I'll look into that and update here. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 7, 2015 Share Posted July 7, 2015 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 Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 7, 2015 Share Posted July 7, 2015 I already pushed the changes, I'm not sure when dk will update the playground. The only thing that I changed was one line of code in the import mesh function on the loader. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 7, 2015 Share Posted July 7, 2015 Yes, I got that, just was not sure if the 'update' below included those files. Shouldn't be a problem.I'll look into that and update here. Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 7, 2015 Share Posted July 7, 2015 Ah, sorry :-)Well, I haven't checked yet. I will wait for your update before I start. If you commit your changes to a branch in your repo, I can make sure we are not conflicting before committing. Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 8, 2015 Share Posted July 8, 2015 Hey Jeff, is the last PR the one you referred to? Or are there other changes to expect? Give me a heads up here when I can make the changes. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 8, 2015 Share Posted July 8, 2015 Yep, that was it Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 12, 2015 Share Posted July 12, 2015 @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); Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 13, 2015 Share Posted July 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 14, 2015 Share Posted July 14, 2015 @Raanan well done and thank you again. I've accepted that ImportMesh can import multiple meshes and that's been around a while so think SerializeMesh is fully compatible. Quote Link to comment Share on other sites More sharing options...
RaananW Posted July 14, 2015 Share Posted July 14, 2015 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. JohnK 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 16, 2015 Share Posted July 16, 2015 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. Quote Link to comment Share on other sites More sharing options...
masterdon Posted October 9, 2017 Share Posted October 9, 2017 Hi everyone, so whats the syntax for serializing all the meshes for saving and then loading them again in scene? Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 9, 2017 Share Posted October 9, 2017 I assume you are looking for the scene serializer? http://doc.babylonjs.com/classes/3.0/sceneserializer#static-serialize-scene-rarr-any 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.