Hello,
I want to use heightmaps with the stack of BabylonJS on the client and cannon-es running on the server and being responsible for the physics.
My ideal workflow would be:
create heightmaps images (eg. with some editor)
use it with the BabylonJS on the client (which is simple with CreateGroundFromHeightMap)
create heightfield for the cannon to take care about the physics
I’m having trouble with the latter.
I haven’t found any example of using the image for heightfield creation.
I’m thinking maybe I should take the Uint8ClampedArray of the heightmap image (which can be done with loading the image to the canvas and getting it from the canvas context) and somehow convert it into the heightfield that cannon understands?
The Uint8ClampedArray is one-dimentional array where every 4 entries defines one pixel, like [0, 0, 0, 255, 0, 0, 0, 255, ... ] defines two pixels.
The bonus question On the other way around, if I would like to create the heightmap programatically then should I use DynamicTerrain?
I’ll be thankful for any idea and pushing me in the right direction.
Did you try to use a static mesh impostor instead? It may use a bit more memory but performance should be the same…and you could use another Physics Engine.
Youp, I think I’ve seen all the examples existing in the nearest Internet
I don’t think I’m following you with the static mesh impostor idea. Could you explain in more details?
I use BabylonJS to render heightmap only on the client - not for the physics.
I’ve been going through the BabylonJS implementation and the CreateGroundFromHeightMap is using CreateGroundFromHeightMapVertexData so maybe I can use it or at least some parts of its implementation
If you are asking how to pass the data to cannon, you will need to pass the mesh’s positions (from the vertex data) to the cannon heightmap. We are doing it here - Babylon.js/cannonJSPlugin.ts at master · BabylonJS/Babylon.js (github.com)
It is a grid (plane) with height definition on each defined point.
Hey @RaananW
Sorry for not responding for a while but a lot is going on in my private life.
That’s definitely very interesting but I’m not 100% sure if that’s what I need.
I will try to experiment and let you know
Hey @Cedric! Sorry for leaving this for so long but I’ve got a lot of family stuff going on.
I see now that Havok is the new player in the game and I’m thinking if the best way for my simple multiplayer car game would be using Havok with NullEngine on the server and then render it on the client with BabylonJS? Can you confirm that it’s good idea (as opposed to trying to make it work with cannon-es)
I haven’t checked for a while but I don’t think heightfield support has been merged in Havok yet. I think you can use tri mesh for that. perf should be reasonably the same. Quality and performance will be much better than Ammo anyways.
@Cedric if I may have one more question. What would you recommend to build the simplest vehicle with Havok?
I’ve seen
But 1100 lines doesn’t seem to be ‘simple’ to me.
Is there another way or is it better to wait until the proper vehicle support will be implemented in Havok plugin?
It will take months before having a production ready vehicle implementation in Babylon.js
So, I recommend for now to use your own implementation.
I think it can be less than 1K LoC but I didn’t try to do 1.
Thanks for your reply.
1K LoC isn’t really that much.
I am nowhere close to be able to implement it by myself so I guess I will try to utilize the @Raggar code.
I hope I won’t drift much from the later official API
You can try my arcade-style simple vehicle. It uses simple springs for suspension and pretty much nothing else. Low center of mass and forces applied under the vehicle gives it great stability and enables sharp turns without rolling over.
If I have time this weekend, it should be done in a few days