babylon.physicsEngine.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var PhysicsEngine = (function () {
  4. function PhysicsEngine(plugin) {
  5. this._currentPlugin = plugin || new BABYLON.OimoJSPlugin();
  6. }
  7. PhysicsEngine.prototype._initialize = function (gravity) {
  8. this._currentPlugin.initialize();
  9. this._setGravity(gravity);
  10. };
  11. PhysicsEngine.prototype._runOneStep = function (delta) {
  12. if (delta > 0.1) {
  13. delta = 0.1;
  14. }
  15. else if (delta <= 0) {
  16. delta = 1.0 / 60.0;
  17. }
  18. this._currentPlugin.runOneStep(delta);
  19. };
  20. PhysicsEngine.prototype._setGravity = function (gravity) {
  21. this.gravity = gravity || new BABYLON.Vector3(0, -9.807, 0);
  22. this._currentPlugin.setGravity(this.gravity);
  23. };
  24. PhysicsEngine.prototype._getGravity = function () {
  25. return this._currentPlugin.getGravity();
  26. };
  27. PhysicsEngine.prototype._registerMesh = function (mesh, impostor, options) {
  28. return this._currentPlugin.registerMesh(mesh, impostor, options);
  29. };
  30. PhysicsEngine.prototype._registerMeshesAsCompound = function (parts, options) {
  31. return this._currentPlugin.registerMeshesAsCompound(parts, options);
  32. };
  33. PhysicsEngine.prototype._unregisterMesh = function (mesh) {
  34. this._currentPlugin.unregisterMesh(mesh);
  35. };
  36. PhysicsEngine.prototype._applyImpulse = function (mesh, force, contactPoint) {
  37. this._currentPlugin.applyImpulse(mesh, force, contactPoint);
  38. };
  39. PhysicsEngine.prototype._createLink = function (mesh1, mesh2, pivot1, pivot2, options) {
  40. return this._currentPlugin.createLink(mesh1, mesh2, pivot1, pivot2, options);
  41. };
  42. PhysicsEngine.prototype._updateBodyPosition = function (mesh) {
  43. this._currentPlugin.updateBodyPosition(mesh);
  44. };
  45. PhysicsEngine.prototype.dispose = function () {
  46. this._currentPlugin.dispose();
  47. };
  48. PhysicsEngine.prototype.isSupported = function () {
  49. return this._currentPlugin.isSupported();
  50. };
  51. PhysicsEngine.prototype.getPhysicsBodyOfMesh = function (mesh) {
  52. return this._currentPlugin.getPhysicsBodyOfMesh(mesh);
  53. };
  54. PhysicsEngine.prototype.getPhysicsPluginName = function () {
  55. return this._currentPlugin.name;
  56. };
  57. // Statics
  58. PhysicsEngine.NoImpostor = 0;
  59. PhysicsEngine.SphereImpostor = 1;
  60. PhysicsEngine.BoxImpostor = 2;
  61. PhysicsEngine.PlaneImpostor = 3;
  62. PhysicsEngine.MeshImpostor = 4;
  63. PhysicsEngine.CapsuleImpostor = 5;
  64. PhysicsEngine.ConeImpostor = 6;
  65. PhysicsEngine.CylinderImpostor = 7;
  66. PhysicsEngine.ConvexHullImpostor = 8;
  67. PhysicsEngine.HeightmapImpostor = 9;
  68. PhysicsEngine.Epsilon = 0.001;
  69. return PhysicsEngine;
  70. })();
  71. BABYLON.PhysicsEngine = PhysicsEngine;
  72. })(BABYLON || (BABYLON = {}));