Jump to content

Elevation of terrain


juanmajr93
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

 

Captura.PNG

Captura2.PNG

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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));

 

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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?

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