physicsEngineComponent.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { TransformNode } from "../../Meshes/transformNode.js";
  2. import "../joinedPhysicsEngineComponent.js";
  3. Object.defineProperty(TransformNode.prototype, "physicsBody", {
  4. get: function () {
  5. return this._physicsBody;
  6. },
  7. set: function (value) {
  8. if (this._physicsBody === value) {
  9. return;
  10. }
  11. if (this._disposePhysicsObserver) {
  12. this.onDisposeObservable.remove(this._disposePhysicsObserver);
  13. }
  14. this._physicsBody = value;
  15. if (value) {
  16. this._disposePhysicsObserver = this.onDisposeObservable.add(() => {
  17. // Physics
  18. if (this.physicsBody) {
  19. this.physicsBody.dispose( /*!doNotRecurse*/);
  20. this.physicsBody = null;
  21. }
  22. });
  23. }
  24. },
  25. enumerable: true,
  26. configurable: true,
  27. });
  28. /**
  29. * Gets the current physics body
  30. * @returns a physics body or null
  31. */
  32. TransformNode.prototype.getPhysicsBody = function () {
  33. return this.physicsBody;
  34. };
  35. /**
  36. * Apply a physic impulse to the mesh
  37. * @param force defines the force to apply
  38. * @param contactPoint defines where to apply the force
  39. * @returns the current mesh
  40. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  41. */
  42. TransformNode.prototype.applyImpulse = function (force, contactPoint) {
  43. if (!this.physicsBody) {
  44. throw new Error("No Physics Body for TransformNode");
  45. }
  46. this.physicsBody.applyImpulse(force, contactPoint);
  47. return this;
  48. };
  49. /**
  50. * Apply a physic angular impulse to the mesh
  51. * @param angularImpulse defines the torque to apply
  52. * @returns the current mesh
  53. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  54. */
  55. TransformNode.prototype.applyAngularImpulse = function (angularImpulse) {
  56. if (!this.physicsBody) {
  57. throw new Error("No Physics Body for TransformNode");
  58. }
  59. this.physicsBody.applyAngularImpulse(angularImpulse);
  60. return this;
  61. };
  62. //# sourceMappingURL=physicsEngineComponent.js.map