Dad72 Posted December 8, 2013 Share Posted December 8, 2013 Hello,How to save a terrain change. I used WORLDMONGER scene of example and I would like to save the terrain in a file .babylon, .json or other. How it is happening?This feature does not seem available. We can import a HeightMap but not export or save in a json file. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 Hello there is no built-in support for saving but you can save mesh's normals and vertices to a .json file and to the inverse code for loading Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 8, 2013 Author Share Posted December 8, 2013 It would be possible for you to make an example in the near future. I am not about to know the ways to do so.This could be a supplement to WORLMONGER.Thank you Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 It can be something like that:var vb = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);var nm = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind); // save VB and nm with a JSON.stringify To reload you can create a mesh and then call these functions:newMesh.setVerticesData(savedPosition, BABYLON.VertexBuffer.PositionKind, false);newMesh.setVerticesData(savedNormal, BABYLON.VertexBuffer.NormalKind, false); Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 8, 2013 Author Share Posted December 8, 2013 Thank you very much. I will try to do something with your example. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 8, 2013 Author Share Posted December 8, 2013 This me returns nothing. the ground is not displayed. What have I done wrong? I saved like this:$("#img_save").on('click', function() { var vb = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind); var nm = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind); $.ajax({ url:'Data/Noyau/Fonctions/Save_terrain.fonction.php', type:'post', data:"vb=" + JSON.stringify(vb) + "&nm=" + JSON.stringify(nm) + "&terrainName=" + terrainName, success:function(data){ } }); }); And load like this:function openTerrain(TerrainName){ $.ajax({ url:'Data/Noyau/Fonctions/Open_terrain.fonction.php', type:'post', data: "terrainName=" + TerrainName, success:function(data){ data = data.split(";"); var savedPosition = new Array(data[0]); var savedNormal = new Array(data[1]); LoadTerrain(savedPosition, savedNormal); } });}savedPosition = [-50,0,50,-49.130434782608695,0,50,-48.26086956521739,0,50,-47.391304347826086,0,50, ....]savedNormal = [0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1, ...]I reloaded the terrain as this:function LoadTerrain(savedPosition, savedNormal){ // Code..... // .... ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 115, scene, true); ground.setVerticesData(savedPosition, BABYLON.VertexBuffer.PositionKind, false); ground.setVerticesData(savedNormal, BABYLON.VertexBuffer.NormalKind, false); var groundMaterial = new WORLDMONGER.GroundMaterial("ground", scene, sun); ground.material = groundMaterial; ground.position.y = -2.0; // Code..... // ....} Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 Is the new ground the same definition as the previous one? (position, vertices count, etc..) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 8, 2013 Author Share Posted December 8, 2013 I am not on understand what you want to say.You want to say if it has the same dimension.In made if i fact:(use CreateGround)ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 115, scene, true); ground.setVerticesData(savedPosition, BABYLON.VertexBuffer.PositionKind, false);ground.setVerticesData(savedNormal, BABYLON.VertexBuffer.NormalKind, false);The terrain not displayed. If i done : (use CreateGroundFromHeightMap)ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "Terrain/heightMap/heightMap.png", 100, 100, 115, 0, 14, scene, true);ground.setVerticesData(savedPosition, BABYLON.VertexBuffer.PositionKind, false);ground.setVerticesData(savedNormal, BABYLON.VertexBuffer.NormalKind, false);The ground remains with the values of the heightmap. The changes are not taken into account. PS: No problem in the console. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 8, 2013 Author Share Posted December 8, 2013 I found the problem I had to convert Json in Array => $.parseJSON();I have therefore done:ground.setVerticesData($.parseJSON(savedPosition), BABYLON.VertexBuffer.PositionKind, true);ground.setVerticesData($.parseJSON(savedNormal), BABYLON.VertexBuffer.NormalKind, true);It must be also correct thisError (new Array)var savedPosition = new Array(data[0]);var savedNormal = new Array(data[1]);Fixevar savedPosition = data[0];var savedNormal = data[1]; It works correctly Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 11, 2013 Author Share Posted December 11, 2013 I've add in the file ElevationControl.js of WorlMonger this code to supplement the engine. I share my contribution. WORLDMONGER.Ground = function (meshGround, savedPosition, savedNormal) { this.meshGround = meshGround; this.savedPosition = savedPosition; this.savedNormal = savedNormal; this.VerticesPosition = 0; this.VerticesNormal = 0; }; WORLDMONGER.Ground.prototype.Save = function () { this.VerticesPosition = JSON.stringify(this.meshGround.getVerticesData(BABYLON.VertexBuffer.PositionKind)); this.VerticesNormal = JSON.stringify(this.meshGround.getVerticesData(BABYLON.VertexBuffer.NormalKind)); }; WORLDMONGER.Ground.prototype.Load = function () { this.meshGround.setVerticesData($.parseJSON(this.savedPosition), BABYLON.VertexBuffer.PositionKind, true); this.meshGround.setVerticesData($.parseJSON(this.savedNormal), BABYLON.VertexBuffer.NormalKind, true); }; Use Save :var buffer = new WORLDMONGER.Ground(ground);buffer.Save(); var vb = buffer.VerticesPosition;var nm= buffer.VerticesNormal;$.ajax({ url: "Save_terrain.function.php", type:'post', data:"vb=" + vb + "&nm=" + mn }); //Create the file, but you can do otherwiseUse Load :$.ajax({url:'Open_terrain.function.php', type:'post', success:function(data){ // Load the file saved, but you can do otherwise data = data.split(";"); var savedPosition = data[0]; var savedNormal = data[1]; LoadTerrain(savedPosition, savedNormal);}});function LoadTerrain(savedPosition, savedNormal){ //Other code (Create engin, scene, cam, light ...) ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 115, scene, true); var buffer = new WORLDMONGER.Ground(ground, savedPosition, savedNormal); buffer.Load(); //Other code (Create material, water...)} Ragash and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
bentwonk Posted March 27, 2017 Share Posted March 27, 2017 thank you for this Dad72 Dad72 1 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.