Use wasm version of ammo.js

Hello !
I can’t get the faster wasm version of ammo.js to work properly.

I have a very basic project that uses node, express and parcel. It works well with the asm.js version of ammo.js.

I have replaced the reference from ammo.js to ammo.wasm.js. Then I’ve put the ammo.wasm.wasm file in the dist directory to make it available to the browser.

Tis what I get :

And when I re-instantiate my Game class in the console, it works well !

I removed the warning messages by adding this to express :

app.get(’/ammo.wasm.wasm’, function (request, response) {
response.sendFile(path.join(__dirname, ‘ammo.wasm.wasm’));
});

But the problem stays.

I don’t know where the problem comes from.
I’ve tried to use webpack, and I have tried to load the Ammo library in different ways.

Have anybody achieved to get it working ?
Thanks !

I do not think we tried that before. That may be a question for the Ammo folksa ctually. Maybe there is some additional steps to make ammo wasm work like regular ammo

It seems the error is that the browser doesn’t simply want to compile locally the downloaded wasm bytecode, because it needs to trust to received mime type… and in your case, the webserver seems to NOT associate the expected mime type (application/wasm) to the downloaded wasm file.
This has to be changed server side.

2 Likes

Okaaay I have a hacky workaround !
As I suspected, babylon doesn’t wait for wasm Ammo to load.

I previously tried to do it as in the ammo.wasm.js example here, but not correctly.

For now I’m happy with Ammo being global :

window.addEventListener("DOMContentLoaded", () => {
  Ammo().then((AmmoLoaded: any) => {
    (window as any).Ammo = AmmoLoaded;
    new Game("renderCanvas");
  });
});

I’m sure there are way better way to do this, but it works for me.

I’m having better results with the wasm version, you should check it out !

2 Likes

Yo @Numer … I am very interested in the wasm version as an option for the Babylon Toolkit.

Can you please give details or show your html page that loads the wasm version so I can add the kind of support to exporter

Nevermind… I get em…

This works for me in BOTH regular js and wasm mode of AMMO

        // ************************************************************************ //
        // DEFAULT LOADER - Initialize Default Scene Loading                        //
        // ************************************************************************ //
        window.addEventListener("DOMContentLoaded", function() {
            if (enablephysics === true && window.Ammo !== undefined) {
                Ammo().then(function() { defaultSceneLoader(scenepath, scenename); });
            } else {
                defaultSceneLoader(scenepath, scenename);
            }
        });

2 Likes