Use Ammo js debug drawer interface

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

I have so much respect these days for every coder who’s also a parent :joy:

Okay I’ll be on today working on my project, so let me know if there’s anything I can do to help!

reverse this algo.

/* Fit plane to frustrum algo. */
var c = scene.activeCamera;
c.position.z = -1;
var fov = c.fov;
var aspectRatio = engine.getAspectRatio(c);
var d = c.position.length();
var y = 2 * d * Math.tan(fov / 2);
var x = y * aspectRatio;
var output = BABYLON.MeshBuilder.CreatePlane("output-plane", {width: x, height:y}, scene);

We need to do it in the opposite direction. We will know the xy but need to establish the cameras z offset to “Frame” the terrain. I’m pretty sure I know how but am not being allowed to touch the keyboard it seems.

Once I can place the camera perfectly above the terrain the next step will be easy!

If I get a moment Im pretty sure this can be accomplished by the all mighty pythagoras theorem.

We know side a and angle a’s radians (fov * 0.5) so it should be fairly simple to do.

1 Like

Just so that I understand the problem you’re solving here does the z, x and y values represented in this image:

Correspond correctly to z, x and y variables in your code snippet?

Once I can place the camera perfectly above the terrain the next step will be easy!

Also, the slow algo I use just samples the height at every grid step. The grid step is what’s used to determine the cameras x and z coordinate positions. So I determine the location of the camera like so:

const bb = mesh.getBoundingInfo.boundingBox
const dims = bb.extendedSizeWorld
const min = bb.minimumWorld
const width = dims.x
const depth = dims.z
const subdivisions = 1400
const camPosition = new Vector3(0, 0, 0)
const dx = width / subdivisions
const dz = depth / subdivisions
const heightmapData = Array(1400)
for (let i  = 0; i < subdivisions; i++) {
    heightmapData[i] = Array(1400).fill(0)

/* just need to make sure camera is always above every vertice of the map mesh */
const y = min.y + dims.y + 1
let x
let z
for (let i = 0; i < subdivisions; i++) {
    x = (i * dx) + min.x
    for (let j = 0; j < subdivisions; j++) {
        z = (i * dz) + min.z

       console.log('NOW WE HAVE CAM POSITION: ', new Vector3(x, y, z))

Oh, im dumb yeah that’s what I was talking about doing but I was thinking perspective camera (which is wrong). An orthographic camera makes this way easy!

Now its just capturing the depth pass, then passing that to a proceduralTexture that modifies the depths from logarithmic to linear!

Lol! No, you’re good - this is a lot of mental context.

So regarding that approach here’s what I had so far:

I just slapped one together really sloppy like, but this is kind of the idea. It would need some refinement and seemingly more accuracy though.

The girls are 100% not about me programing today though, so this is as far I can can go <3

This is in linear space too which is wrong.

1 Like

All this extras to get the heights from the mesh… seems like alot of work just to get the heights… that is what makes me want to use the Unity supplied raw heights instead.


Andy ill talk to you about it a bit more tomorrow at work

FYI… Me and @Pryme8 work together at MVRK :slight_smile:


All this extras to get the heights from the mesh… seems like alot of work just to get the heights… that is what makes me want to use the Unity supplied raw heights instead.

Well, remember, Babylon.js offers a game caliber rendering framework for those not experienced with the traditional tools such as Unity and Unreal. Also consider the operability of not needing to import a gltf model into unity to be able to generate a height map. It is super useful that unity can provide height map generation (and presumably your tool kit as well) but I think having the option of doing it in a framework that literally runs in a browser tab is huge; I can be doing game development on my gf’s 14’ Mac bookpro running on an M1 Pro chip when I’m at her place watching Friends :smiley:

@arcman7 so my approach of generating the terrain mesh at design time in Unity using the Terrain Building tools and all its features (With no 65,535 vertices limit on exported meshes anymore) and creating the Bullet/Ammo btHeightfieldTerrainShape at runtime using the actual heights from the Mesh (so i dont need to duplicate the heights in a raw float array or png texture, I take them right from mesh i am providing collision for)

But it is working smooth… all right from the Unity Editor, Out-The-Box with no extra coding or setup… Just make your terrains in Unity using ANY terrain tool from the Unity Eco System that works with the native Unity Terrain System

Freakin sweet… Take a look at this:

1 Like

Looks really good! I’m also going to try out those ready player me avatars, that’s just too cool to pass up.

I’m going to be using the toolkit in building out the next map that I’m adding to my game world. I see the sweet spot for my workflow being getting as much polish as I can out of the unity tools editor (character controllers, setting up the collisions, etc.) and porting that directly into my babylon.js project.

To that end I was wondering, if you had any thoughts as to a particular set of features in the toolkit that a babylon.js user would get the most value from. For example the character controllers are a big one. I haven’t tried setting up colliders with various meshes in Unity yet, but that feature seems to have a big potential as well. I just don’t know enough about Unity yet; tips here would be greatly appreciated.

For example is there a way to do object shattering in Unity? In my case I want to set up rocks as destructible objects that shatter into smaller pieces.

I am going to try and make a Unity Starter Assets video (soon)

It demonstrates so many out-of-the-box features you get with the toolkit:

  • High Dynamic Range Baked Image Based Lighting
  • Playground Scene and level prototyping Unity Prefabs
  • Complete physics system using Unity Collider components
  • A fully rigged and animated Default Character Armature using a Humanoid rig
  • A Third Person Physics Based Kinematic Character Controller
  • Unity Mechanim Animation Controllers
  • And so much more


I am not ready to release the pro version yet. I still have to finish hammering on the final release candidate builds. I also still have not fully decided on the pricing model for my Pro Tools Developer License and the web site that will be used to generate those licenses.

So there is still alot of work I have to do to get the pro version ready for release and its only me trying to do all this development. In my spare time. I have a full time job and a baby now so I dont have nowhere near the time I had before to work all this other stuff i need to be in place for the release

So everyone still has to use the A63 alpha build until I get the new pro version ready for release.


If your talking about those Colyseus Network Player Avatars. That is really apart of the Premium Addons Package that will be available for Pro Developers. They are still in beta and not quite ready for release yet.

If you are talking about characters that you can download into Unity and use as regular characters in your project with full support for player controllers and animation controllers, etc. I made a special build of the ready player me plugin (design to play nice with the new Babylon Toolkit) you can grab here

Manually only of course. We never really run Unity at runtime. We only ever export content as GLTF