Last active
October 12, 2022 14:08
-
-
Save Sumechoo/18ae90f299eccc58a90b442cfd5c787c 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