Ammo.js webpack issues

That seems to have done the trick. Adding this to the docs would be a great idea! That way the next poor soul doesn’t have to muck about trying to get this working.

Thanks a million @sebavan!

1 Like

I installed from npm i --save-dev kripken/ammo.js, added that node: { fs: 'empty' } and used the import statement described here. No luck, I get this in the import statement:

Naturally, it suggest that I try to install type definitions though the obvious choice for types here doesn’t exist in npm.

There is not much we can do if they do not provide the typings, Could you not cast as any for this one ? I know it is not ideal but without typings, it does not leave a lot of options.

I turned off noImplicitAny but then received advice on casting to any which I wasn’t aware of. Thanks!

1 Like

i did exactly what you said and end up now with an error after using my webpacked app:

Uncaught TypeError: b.asm is undefined
_emscripten_bind_btSoftBodyRigidBodyCollisionConfiguration_btSoftBodyRigidBodyCollisionConfiguration_0 ammo.js:533
uC ammo.js:917
e babylon.js:16
Game game.js:39
App app.js:16
js index.js:3
Webpack 5
webpack_require
0
webpack_require


ammo.js:533:11
_emscripten_bind_btSoftBodyRigidBodyCollisionConfiguration_btSoftBodyRigidBodyCollisionConfiguration_0 ammo.js:533
uC ammo.js:917
e babylon.js:16
Game game.js:39
App app.js:16
js index.js:3
Webpack 5

If one wants to try it out:
https://github.com/to5ta/js_zero
the physics_controller branch…

Anyone has an idea or integrated the ammo engine sucessfully using webpack recently? :slight_smile:

i hard-copied the ammo.js from the dist/ in babylonjs-4.2 repo locally to my sources, bundling takes now very long but its kinda working for me currently…

If i understand this post right, its an issue caused by the most recent build of ammo?..

Yup, exactly, i ll try to have a way to integrate asap

1 Like

Did you try the latest ammo.js build from kripken/ammojs GitHub account ?

Yeah, i installed it through: npm i --save-dev kripken/ammo.js

Actually i forgot to update, babylonjs and babylonjs-loaders were on version 4.1.0, also file-loader and css-loader outdated. Updating them didnt change anything, see / try out this branch for reproduction.

Cannon package integration /injection works as described. (thanks for updating the documentation btw!)

Ammo still fails with the error described earlier, using the local copy of ammo still works.

Does anyone want to invest the time to clone the repo and run

npm install
npm run dev

and tell if the same error occurs?

btw. i wont be using physics now as i had a hard time building up a reasonable character controller that interacts with pyhsics…

@to5ta this is expected at the moment and will be fixed by the changes from the other thread

1 Like

allright then, happy coding :slight_smile:

1 Like

What problems are you having ?

I am currently using using the bullet kinematic character controller as the underlying backbone to the BABYLON.CharacterController script component. I works great :slight_smile:

2 Likes

thanks for mentioning, ill give it a try :slight_smile:

@MackeyK24 which one do you mean exactly? ^^

Do you mean this controller?

I kind of did the same approach, but it does not use an physics engine afaik, only basic raycasting and intersection stuff… but i think this topic is maybe worth starting a new thread eventually.

Nope… I use the Unity Style Approach To Character Controllers. So in unity you setup the character with the CharacterController component and use script to move around: character.move() function

In webpack5, looks like they want us to use fallback instead of node, as mentioned here: Node | webpack

I got it to build with ammo like so:

webpack.config.js:

module.exports = {
  ...
  resolve: {
    fallback: {
      'fs': false,
      'path': false, // ammo.js seems to also use path
    }
  }
}

With that, I can enable physics like so:

import Ammo from 'ammo.js'
...
const ammo = await Ammo()
scene.enablePhysics(new Vector3(0,-9.81,0), new AmmoJSPlugin(true, ammo))

That builds and enabling physics call doesn’t fail, and I can do a simple softbody demo yay!

@sebavan should a note be added to Babylon.js ES6 support with Tree Shaking | Babylon.js Documentation about webpack5 change? Also npm install kripken / ammo.js should be npm install kripken/ammo.js (no spaces). Let me know if you’d like me to submit a PR for that update.

4 Likes

This would be amazing !!!

Cool, PR submitted to update documentation: Update ammo.js instructions for webpack v5 by JohnnyFun · Pull Request #180 · BabylonJS/Documentation · GitHub

1 Like

I can see it has been merged thanks a lot !!!

1 Like