Heightmap on NullEngine with Havok

Hey,
I’m trying to use heightmap on NullEngine with Havok.
Is this

still way to go?
Using basic CreateGroundFromHeightMap doesn’t work ofc

dev:*serve] BJS - [13:16:56]: Babylon.js v6.25.0 - Null engine
[dev:*serve] node_modules/@babylonjs/core/Misc/webRequest.js:9
[dev:*serve]         return new XMLHttpRequest();
[dev:*serve]         ^
[dev:*serve] 
[dev:*serve] ReferenceError: XMLHttpRequest is not defined

Hmmm we should probably try to polyfill the XMLHttpRequest @RaananW ?

Not entirely trivial, but happily already done for us by a wonderful open source project:

You should load it (using wither require or import, depending on your architecture) and set globalThis.XMLHttpRequest to be the exported object

2 Likes

Thanks @carolhmj and @RaananW :slight_smile:
I will try to use this today or tomorrow.
Just a thought, Raanan, shouldn’t the BabylonJS handle it somehow differently? Eg. maybe it could check the context of function being called, like in this example it is node environment, and then instead of doing XML HTTP Request do something else, eg. try to do fs.readFile() or whatever is an node-like substitute?

if you pass a URL babylon will try downloading it. Instead of that you might want to load the file beforehand and convert it to a base64 data URL. Passing a data URL will avoid using any network requests.

Okey, thank you for your reply :slight_smile:
That sounds better for me, I’ll try that :pray:

2 Likes

I can confirm that reading it beforehand and passing as base64 data works fine.
Thanks @RaananW! :bowing_man:

1 Like

EDIT:
Okay, I’ve found out that I was missing sphereAggregate and groundAggregate on the server so it’s better but still it behaves differently. I’ll investigate futher

After successfully making working Havok with the NullEngine (I mean having no errors) I added heightmap on the client and it looks like the physics is not working properly on the server.
@RaananW can you look at this maybe?


The sphere should bounce from the mountain (let’s call it that way) but it goes throught it.
The code for the server is here:

and for the client is here:

Have you managed to get havok to work on the server? Is it a heightmap issue, or a physics issue?

I managed to get havok working on the server in terms that it runs without errors. I try to make client and server havok instances identical to be sure if there is some server related issue, at least it looks like that to me at this point. But I could make some error in the code so I’ll prepare that identical client and server instances and verify it.

1 Like

Hey @RaananW,
I managed to prepare demo.
The code is here:

All server code is in here

It looks like this:

The issue here is the lack of support for image loading in babylon when using the null engine in node.js. As node is missing a few functions that Babylon needs to process the image.
I tried working with node-canvas and others, but seems to be a little bigger than that.

We can look into that in the future, but for now we sadly don’t support it.

Thanks for diving into this.
Is it something that I can work on and contribute or it’s Babylon core thing to be done?

I have created an issue for this - Support LoadImage in Node.js environment · Issue #14610 · BabylonJS/Babylon.js (github.com).

We LOVE community PRs :slight_smile: You can look into it and of course suggest a difference solution

Thanks @RaananW.
If I’ll have some time I’ll try to work on this but currently my velocity is very low :smiley: (thanks to two little daughters :crazy_face: )

2 Likes