three-game-engine
Version:
Simple light-weight game engine using three.js, three-mesh-ui and rapier
26 lines (25 loc) • 1.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRapierWorld = exports.initRAPIER = void 0;
const rapier3d_compat_1 = require("@dimforge/rapier3d-compat");
let rapierInitialized = false;
// Initialize RAPIER physics library, if not already done
const initRAPIER = async () => {
// init the rapier library, only needs to be done once ever.
if (!rapierInitialized) {
console.log('Game: initializing RAPIER physics library...');
await rapier3d_compat_1.default.init();
rapierInitialized = true;
}
};
exports.initRAPIER = initRAPIER;
const createRapierWorld = (gravity) => {
if (['x', 'y', 'z'].some(prop => typeof gravity[prop] !== 'number')) {
// This check is here is because elsewise funky thing start happening inside Rapier,
// when given bad values such as undefined x/y/z values. This include behavior
// such as colliders consistently adopting NaN translation() values.
throw new Error(`createRapierWorld: a rapier world must be initialized with a gravity vector, containing a numer x, y, and z value. given: ${gravity}`);
}
return new rapier3d_compat_1.default.World(gravity);
};
exports.createRapierWorld = createRapierWorld;
;