Use Ammo js debug drawer interface

@arcman7 thanks… i will go thru this code. But it looks alot like the Ammo.js example for terrain except for the way you calculate min and max heights and calculate resolution.

Here is my create terrain shape

And as you can see i get MOST of the terrain data like width, depth and resolution from Unity exported terrain data… The problem i had was with the heights…

But it look like you loop thru all the meshes and get the Bounding box info and use that to mark the min and max heights of the meshes for the bounding box… I was going to try and loop thru all the vertices and use the Y value to track min and max… but the bound box seems like less work… I will try that.

Thanks, i let you know how it goes :slight_smile:

1 Like

YO @arcman7 … One more question… Are you drawing a debug representation of your terrain ? And How… are just making your own mesh and aligning it where you THINK it should go or are you using some kind of ammo debug drawer info to show where ammo actually has that terrain ?

It’s a literal representation of the physics bodies using the Ammo debug drawer interface. Ammo js provides the vertices data, and then I render it using the Babylon.js point cloud system - I linked everything you need in a gist above ^

You mean this here Ammo Debug Drawer Interface Implementation · GitHub

I will study that… thanks again man :slight_smile:

1 Like

Np, I hope you find it useful. If you learn anything new please share! And feel free to make improvements, I’ll update that gist or just point it towards whatever you make if you decide to.

Yo @arcman7 … Sorry i lied … got another question… Where are you getting your heightmap data from ?

In unity, i was exporting the terrain heights as a flat number array. then just loading that into a Float32Array.

heightmapData = new Float32Array(terraindata.heightdata);

Where are your heights coming from … them Mesh Vertices Position Y, at runtime ?

Check out this thread:

I specifically used the code here:

to generate an 800x800 hmap overnight while I slept. If you can get that shader version of the playground/script (something I was working on towards the end of the thread) working, then this could be near instant for any resolution on any sized model.

So all of that was to get the heights from the mesh… Well heck… I would be better off just using the raw heights array i get from Unity TerrainData.GetHeights function

Yeah, in your case you definitely should. Any chance you could generate a 1400 by 1400 heightmap for me?? :smiley:

Unity only generates these fixed heightmap sizes

Screen Shot 2022-08-05 at 2.52.52 PM

1025 or 2049 is what what i can do for you… And What a heightmap of what terrain, from what unity scene… Or just any HILLY terrain example i can find ?

1 Like

Oh awesome!

I’ll take the 1025x1025 dimensions with the map model here:
https://colossus-asdkjfhasldkfhsdlkj.s3.amazonaws.com/maps/mountain_range_1/scene_merged.gltf

Still taking a look at your playground, it seems like there might be some problem with the exported height data. Give me a min though.

Note: I can only make heightmap of actual unity terrains… So it would have to be a Unity scene with an actual Unity Terrain for me to export the heightmap

Ah gotcha, so you can’t actually import gltf files?

But you could browse the Unity asset store for a free terrain or environment with a terrain… send me that link, i can download that Unity scene and export the height map data for you…

Oh yeah… how did you want that heightmap data?
Do you want is as a 16Bit encoded png heightmap image or a json with the heightmap float number array ?

There actually wasn’t any issue with your exported height map data. I just forgot the x,y,z format that it’s in when you pull it out of the babylon mesh via the getVerticesData call.

So if I could find a way to import a gltf file into Unity, I can just pass you a link to the resulting scene?

I found a mesh to terrain utility… let me player with that and see if i can convert you gltf to a terrain and then export the heightmap… How you want the heightmap data ?

Json or Png

1 Like

Height map as a json file plz! Thank you!!

1 Like

If you are trying to get a heightmap from a mesh couldn’t you just do a rtt capture of depth of the mesh from above in whatever size you want and then convert the range?

You could also sample the vertex data and just convert the xz coords into a normalized space then interpolate the pixels on your buffer from that data?

Usually you make a mesh from a heightmap and not vice versa but if y’all really need a fast/nearly instant way to generate that the rtt method is probably the best.

1 Like

That’s what I was trying to figure out how to do towards the end of that thread. I think I was just missing a few steps or inputting the correct values. I eventually will swing back to it, but in the mean time letting my slow method run over night solves the need that I have lol. I do want to use this for more maps later with quicker iterations.

I’ll post an example if I get a chance. There is no reason to have to take a night to process simple height values. :heart:

If my daughters cooperate for nap time ill see if I can help you.

1 Like