Using Oimo with Typescript + CommonJS

I am using NullEngine() with Node.js and want to use Oimo as physics engine. With v4.* I have to install it separately. So I included oimo in my package.json. Now I am stuck on how to expose OIMO to babylon.js. Right now, the transpiling works, but I get an error when running the js files:

ReferenceError: OIMO is not defined

Strangely I can not even get rid of the error if I add “const OIMO = require(“oimo”);” before every require(‘babylonjs’) by hand into the js files. Guess I am missing some understanding on how node modules are working…

Any idea how I can get this running?

pinging our overlord of modules @sebavan

You can pass the oimo import as a parameter of the oimoJSPlugin:

const OIMO = require(“oimo”);
new BABYLON.OimoJSPlugin(undefined, OIMO);

Dependency Injection here prevents the need of global scope known OIMO variable.


That did the trick! Thanks!