Skip to content

Instantly share code, notes, and snippets.

@8Observer8
Forked from Sumechoo/AmmoProvider.ts
Created October 12, 2022 14:08
Show Gist options
  • Save 8Observer8/8f75a562174be720ce65b60d8c866940 to your computer and use it in GitHub Desktop.
Save 8Observer8/8f75a562174be720ce65b60d8c866940 to your computer and use it in GitHub Desktop.
Class for simplified usage of typed Ammo.js API inside ES6 modules
import Ammo from 'ammojs-typed';
export class AmmoProvider {
private static api: typeof Ammo;
public static async getApi() {
if (!AmmoProvider.api) {
AmmoProvider.api = await Ammo();;
}
return AmmoProvider.api;
}
}
export const createWorld = async () => {
const api = await AmmoProvider.getApi();
const collisionConfiguration = new api.btDefaultCollisionConfiguration();
const dispatcher = new api.btCollisionDispatcher( collisionConfiguration );
const broadphase = new api.btDbvtBroadphase();
const solver = new api.btSequentialImpulseConstraintSolver();
const world = new api.btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
world.setGravity( new api.btVector3( 0, -9.82, 0 ) );
return world;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment