I found a solution how to use Ammo.js with Browserify:
npm install kripken/ammo.js
main.js
const Ammo = require("ammo.js");
let physicsWorld = null;
function main()
{
Ammo().then(start);
function start(Ammo)
{
console.log("start");
setupPhysicsWorld(Ammo);
console.log("gravity =", physicsWorld.getGravity().y());
}
function setupPhysicsWorld(Ammo)
{
let collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(),
dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration),
overlappingPairCache = new Ammo.btDbvtBroadphase(),
solver = new Ammo.btSequentialImpulseConstraintSolver();
physicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
physicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));
}
}
window.onload = main();
For example you have this project structure:
public/index.html
public/js
src/client/main.js
src/server
Install Browserify and UglifyJS globally:
npm i browserify uglify-js -g
You can add this commands in package.json for release and debug modes:
"scripts": {
"clear": "del /f /q /s .\\public\\js\\*.*",
"del-bundle": "del /f /q /s .\\src\\bundle.js",
"bundle-debug": "browserify --debug src/client/main.js -o public/js/bundle.js",
"bundle-release": "browserify src/client/main.js -o src/client/bundle.js",
"uglify": "uglifyjs src/client/bundle.js -o public/js/bundle.min.js",
"debug": "npm run bundle-debug",
"release": "npm run clear && npm run bundle-release && npm run uglify && npm run del-bundle"
},
npm run debug
npm run release
bundle.js and bundle.min.js will be generated. Comment/Uncomment recently lines in index.html for debug and release:
<script src="js/bundle.js"></script>
<!-- <script src="js/bundle.min.js"></script> -->