juanmajr93 Posted December 29, 2016 Share Posted December 29, 2016 Hi, I have a new question about how can I get a elevation of terrain. Now I am using this function:CreateGroundFromHeightMap() and I use a png as parameter. However, I dont get the accuracy that I would like having. I have 1 height by each 2meters so I consider that I should use this data to calculate the height of terrain instead of the intensity of color. Do you know how could I do it? Thanks JMJR Quote Link to comment Share on other sites More sharing options...
jerome Posted December 29, 2016 Share Posted December 29, 2016 I don't really get what you mean ... http://doc.babylonjs.com/classes/2.5/MeshBuilder#static-creategroundfromheightmap-name-url-options-scene-rarr-groundmesh-classes-2-5-groundmesh- Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 29, 2016 Share Posted December 29, 2016 exemple elevation: http://www.babylonjs.com/Scenes/Worldmonger/index.html multi-texture: http://doc.babylonjs.com/extensions/Terrain Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 29, 2016 Author Share Posted December 29, 2016 Well I have an elevation of terrain in GLOBAL MAPPER, it is a software to load differents type of files. I get this elevation using ortographic information. When I export this to png for using in BabylonJS I dont get the same accuracy. My question is if you know other way to elevate terrain using height data directly instead of image. Theese are the captures of elevation of terrain and heigh map in GLOBAL MAPPER The format of the height's file is: Latitud, Longitud, Altura 431001,4183099,433.692 431001,4183097,433.408 431001,4183095,433.208 431001,4183093,433.115 431001,4183091,432.998 Thanks JMJR Quote Link to comment Share on other sites More sharing options...
jerome Posted December 29, 2016 Share Posted December 29, 2016 yes, you can. Just create an updatable ground (not a ground from heightmap) and then update each vertex y coordinate accordiling to your altitude data. You'll find plenty of examples in this forum about how to do this. Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 Hi again, finally I got the acuracy that I wanted exporting an image with png 24bits format. I solved this problem. However I have the next question. How could I get the height coordinate of ground after heightmap is applied? Thanks and HAPPY NEW YEAR!! Quote Link to comment Share on other sites More sharing options...
jerome Posted January 3, 2017 Share Posted January 3, 2017 http://doc.babylonjs.com/classes/2.5/GroundMesh#getheightatcoordinates-x-z-rarr-number Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 yes this function is exactly that I need. However this is my code and it doesnt work... var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "assets/textures/map.png", _width, _height, 1000, 0, 150, scene, false); console.log(ground.getHeightAtCoordinates(0, 0)); Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 I am confused because when I print the number of vertices i get 0... console.log(ground.getTotalVertices()); Quote Link to comment Share on other sites More sharing options...
jerome Posted January 3, 2017 Share Posted January 3, 2017 you need to wait for your ground to be created once the heightmap is downloaded... so call any method on a heighmap terrain only in the callback function http://doc.babylonjs.com/classes/2.5/MeshBuilder#static-creategroundfromheightmap-name-url-options-scene-rarr-groundmesh-classes-2-5-groundmesh- have a look at the parameter "onReady" Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 ok thanks jerome but how can i use this callback coud you show me and example? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 3, 2017 Share Posted January 3, 2017 something like this : var callbackFunction = function(mesh) { var h = mesh.getHeightAtCoordinates(x, z); }; var options = {width: width, height: height, subdivisions: subdivisions, minHeight: 0, maxHeight: 60, onReady: callbackFunction}; var ground = BABYLON.MeshBuilder.CreateGroundFromHeightMap("ground", "http://www.babylonjs-playground.com/textures/heightMap.png", options, scene); Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 @jerome This solution is perfect! I have tested it and I get a height. The last question is the follow. what are all vertices of mesh ?¿width*height ? I wil have to visit all of them and get their height... Thanks! Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 3, 2017 Author Share Posted January 3, 2017 I have made this iteration: var callbackFunction = function(mesh) { var vertex_data = BABYLON.VertexData.ExtractFromMesh(mesh); var h; for (var i = 0; i < vertex_data.positions.length; i+=3) { h = mesh.getHeightAtCoordinates(vertex_data.positions[i],vertex_data.positions[i+1]); console.log(h); } }; is it well? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 3, 2017 Share Posted January 3, 2017 In this case, simply retrieve the vertex positions : positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind); positions -> x positions[i + 1] -> y (height) positions[i + 2] -> z Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 4, 2017 Author Share Posted January 4, 2017 @jerome yes it is well and I store all vertices of ground to array. However, I can not solve my problem by this way. I have different objects(tubes) and I have to get the height of (x,y) coordinates of ground wich are under this object exactly to set his height. Firstly, I don't know what are the vertices of ground under theese objects. Maybe, I consider that a solution can be use a ray to get the vertex under each point of tubes.... I hope your help Thanks Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted January 4, 2017 Author Share Posted January 4, 2017 I have just solved my problem. I was importing another version of babylonjs to my project and I get strange heights of vertices. I dont know the reason, maybe some update of framework. Now I am using this import: <script src="http://www.babylonjs.com/babylon.js"></script> is it always the last version of BabylonJS? Quote Link to comment Share on other sites More sharing options...
adam Posted January 4, 2017 Share Posted January 4, 2017 You should use the cdn. http://cdn.babylonjs.com/2-5/babylon.js http://cdn.babylonjs.com/2-5/babylon.max.js If you need the preview release: for production: https://cdn.rawgit.com/BabylonJS/Babylon.js/master/dist/preview release/babylon.js for development: https://rawgit.com/BabylonJS/Babylon.js/master/dist/preview release/babylon.js 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.