Webpack-compliant imports for Cannon.js

Thank you! This pointed me in the right direction. There was still a different issue to solve (“CANNON” is not defined), but I managed that too.

My next attempt was combining this with the answer from Cannon.js NPM "CANNON is not defined" in v4.0.0-alpha.21 but works in v4.0.0-alpha.16

Now the relevant lines look like this (the code has also been updated on gitlab):

import * as cannon from "cannon";
import { CannonJSPlugin } from "babylonjs"
// ...
scene.enablePhysics(null, new CannonJSPlugin(true, 10, cannon));

I also had to reinstall cannon somehow (npm install --save-dev cannon) or it would complain how it couldn’t find it, but now it works!

Thank you all! I hope this will help someone else in the future.

2 Likes