How to convert ammo.js to es6 module?

I’m facing a situation that can only import es6 module, can not use <script> tag.

How to convert ammo.js to es6 module?

If can’t convert, is there a way to wrap it in an es6 loader, and load it like what DRACOLoader loading draco_decoder.wasm?

I suggest you use the JS version instead of wasm (because wasm is a pain to wrap and performance difference with ammo specifically is quite low)

  1. make a local copy (or clone repo)
  2. go to the bottom of the file and add an export statement
  3. profit?
1 Like

Oh! There’s an ammo.js file in the official ammo.js repo.

( I consider EMScripten can only produce .wasm not .js before, and three.js repo only has ammo.wasm.js and ammo.wasm.wasm files too. )

Thanks a lot! I’ll try.

1 Like


I found need one more step: delete this.Ammo=b; in ammo.js, otherwise will cause an error.
Seems to work fine:




Hello, @gonnavis! I have a problem. Maybe did you have it too? Three.js and Ammo-ES. Error: ammo-es.js:37 Uncaught TypeError: ia[J[((J[(a >> 2)] + 8) >> 2)]] is not a function

Sorry that I chose to use cannon-es and PhysX wasm later.
So no more use of ammo.

1 Like

Thank you very much for reply. I use cannon-es too but I hear about physx-js at first time. It needs for me to have the same physics engine on Web and Desktop (C++ client) for multiplayer game: Ammo.js and Bullet Physics. I must have the same physics engine on the client and server side for client predictions. It seems I can have physx-js for Web and PhysX for Desktop. I read that PhysX is free now. Can I use physx-js as ES6 module? I have the problem: physx-js as ES6 module · Issue #15 · ashconnell/physx-js · GitHub

We are using a customized PhysX wasm.
Not full-featured yet, but expose functions for our project’s needs specifically.

1 Like

Thanks a lot! Maybe I will try it later. I will use cannon-es with TypeScript and Parcel for a while.