iiceman Posted January 7, 2016 Share Posted January 7, 2016 Hey guys, I am trying to place some boxes randomly on a heightmap. Easy, eh? Well, therefor I want to determine the current altitude at some random coordinates by casting a ray to see where it intersects with the ground mesh as suggested here: http://www.html5gamedevs.com/topic/2248-retrieve-heightmap-altitude/ That's what I got so far: http://www.babylonjs-playground.com/#HLQ0L#0 But it always returns a hit: false ... I feel like I am missing something here or just doing it wrong but I can't seem to figure out what. Any idea? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 7, 2016 Share Posted January 7, 2016 http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#ground-from-a-height-map I guess you should get the altitudes in the CreateGroundFromHeightMap() callback function. Indeed, it takes some time to download the heightmap image file, so the mesh isn't yet computed when the function CreateGroundFromHeightMap() returns. You could also use the dedicated method getHeightAtCoordinates(x, y) which returns the y value (x, z and y are the coordinates in the ground system).I re-implemented this method yesterday, I don't think the last version is still in the PG. iiceman 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 7, 2016 Author Share Posted January 7, 2016 Sweet! Thanks a lot jerome! http://www.babylonjs-playground.com/#HLQ0L#1 Edit: But it's not always the right position... sometimes they are too low, sometimes to high... am I using it wrong? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 7, 2016 Share Posted January 7, 2016 Hi Ice! http://www.babylonjs-playground.com/#HLQ0L#2 I switched lines 19 and 20. When you called ground.getHeightAtCoordinates(x, z)... z was still undefined/undeclared. Party on! iiceman 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 7, 2016 Share Posted January 7, 2016 Wingut : eagle eyes !can find a bug from 20000 feet high I'm implementing a new method for height maps : getNormalAtCoordinates()This will return you the vector normal to the map at the current (x, z) coordinates.This will be useful for having meshes waving under the surface : y + val only is not efficient when the mesh is moving above a very inclined facet for instance, you may want to shift it along the normal.This will be useful to compute a slope also : dot product (normal, axis Y) if we want to give a mesh a direction according to the ground inclination for instance... almost physics, but without any engine [EDIT] : PRed iiceman and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 7, 2016 Author Share Posted January 7, 2016 Thanks wingy... guess I was too excited and got carried away! @jerome, taht sounds pretty useful indeed. Can we expect to see some examples soon? Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted January 7, 2016 Share Posted January 7, 2016 example as soon as the feature is pushed in the PG Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 7, 2016 Author Share Posted January 7, 2016 Cool. I am currently playing around here: http://www.babylonjs-playground.com/#PSKRF#5 I want to make the selection circle using decals. It seems to work fine so far but the performance when making a selection is pretty bad... I think it's because of the constant ray picking... would your new function help to avoid that? Quote Link to comment Share on other sites More sharing options...
jerome Posted January 7, 2016 Share Posted January 7, 2016 yep, no more ray picking !have a look at this coming in the PG soon : http://www.html5gamedevs.com/topic/15523-getheightatcoordinates-alternative/?p=110642already in the 2.3 Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 7, 2016 Author Share Posted January 7, 2016 So cool! Good job! Especially this one looks so cool: http://www.babylonjs-playground.com/#1QC4YQ#4 We can finally create the ants simulation that we have always dreamed of Quote Link to comment Share on other sites More sharing options...
jerome Posted January 7, 2016 Share Posted January 7, 2016 you've got such weird dreams, nope ? with the getNormalAt(x, z) you'll be able to rotate/orientate the mesh according to the surface also 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.