Create HeightmapImpostor setup for Ammo.js

Yo @Cedric and @sebavan i was thing about setting up BABYLON.PhysicsImpostor.HeightmapImpostor support for Ammo.js but i am not quite sure what the deal behind the clean of physics impostors.

To support heightmaps from meshes, i need to store the Ammo._malloc result on the impostor.object or basically the ground mesh. I do that like this:

What is the best place to place clean up code for Ammo.js heap memory we allocated at runtime and what do we use to free that memory. I dont see a Ammo._free … But i do think i could add the to the Ammo.js exported functions just like _malloc

I am just not sure because i dont see any Ammo.js example where they FREE the memory they allocated for the heightmap… Like once you created that memory on the heap… it stays on the heap until a new page is loaded

How should i handle clean up if i went ahead and added heightmap impostor support like we have for cannon.js

@Cedric being in vacation for a bit, let s see if @RaananW is familiar with those in ammo ?

Sorry, we’ll have to wait for @Cedric

FYI @Cedric … Looks like kripken is saying is better to reinitialize Ammo rather than rely on malloc and free

Shit :frowning:

Yes, it makes sense to reinitialize the heap once in a while. For example when no physics objects are being active. With fixed memory size, it 's possible to not be able to allocate memory because of fragmentation. I guess, it’s possible to mitigate this effect with dynamic allocation… with the price of less performance and more memory allocated.

So @Cedric how should i handle this: Create HeightmapImpostor setup for Ammo.js

Unfortunately, there is no other way than doing allocation/destruction with malloc and free everything in Babylon.js/ammoJSPlugin.ts at 209855cb589e59645f45596928d4243701f221f8 · BabylonJS/Babylon.js · GitHub

If many objects get allocated/destoyed, at some point, it won’t be possible a allocate for a heightmap unless ammo is reinitialized.