-
-
Save 8Observer8/8f75a562174be720ce65b60d8c866940 to your computer and use it in GitHub Desktop.
Class for simplified usage of typed Ammo.js API inside ES6 modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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