physicsEngine.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import type { Nullable } from "../../types";
  2. import { Vector3 } from "../../Maths/math.vector";
  3. import type { IPhysicsEngine } from "../IPhysicsEngine";
  4. import type { IPhysicsEnginePluginV2 } from "./IPhysicsEnginePlugin";
  5. import type { IRaycastQuery } from "../physicsRaycastResult";
  6. import { PhysicsRaycastResult } from "../physicsRaycastResult";
  7. import type { PhysicsBody } from "./physicsBody";
  8. /**
  9. * Class used to control physics engine
  10. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  11. */
  12. export declare class PhysicsEngine implements IPhysicsEngine {
  13. private _physicsPlugin;
  14. /** @internal */
  15. private _physicsBodies;
  16. private _subTimeStep;
  17. /**
  18. * Gets the gravity vector used by the simulation
  19. */
  20. gravity: Vector3;
  21. /**
  22. *
  23. * @returns physics plugin version
  24. */
  25. getPluginVersion(): number;
  26. /**
  27. * Factory used to create the default physics plugin.
  28. * @returns The default physics plugin
  29. */
  30. static DefaultPluginFactory(): IPhysicsEnginePluginV2;
  31. /**
  32. * Creates a new Physics Engine
  33. * @param gravity defines the gravity vector used by the simulation
  34. * @param _physicsPlugin defines the plugin to use (CannonJS by default)
  35. */
  36. constructor(gravity: Nullable<Vector3>, _physicsPlugin?: IPhysicsEnginePluginV2);
  37. /**
  38. * Sets the gravity vector used by the simulation
  39. * @param gravity defines the gravity vector to use
  40. */
  41. setGravity(gravity: Vector3): void;
  42. /**
  43. * Set the time step of the physics engine.
  44. * Default is 1/60.
  45. * To slow it down, enter 1/600 for example.
  46. * To speed it up, 1/30
  47. * Unit is seconds.
  48. * @param newTimeStep defines the new timestep to apply to this world.
  49. */
  50. setTimeStep(newTimeStep?: number): void;
  51. /**
  52. * Get the time step of the physics engine.
  53. * @returns the current time step
  54. */
  55. getTimeStep(): number;
  56. /**
  57. * Set the sub time step of the physics engine.
  58. * Default is 0 meaning there is no sub steps
  59. * To increase physics resolution precision, set a small value (like 1 ms)
  60. * @param subTimeStep defines the new sub timestep used for physics resolution.
  61. */
  62. setSubTimeStep(subTimeStep?: number): void;
  63. /**
  64. * Get the sub time step of the physics engine.
  65. * @returns the current sub time step
  66. */
  67. getSubTimeStep(): number;
  68. /**
  69. * Release all resources
  70. */
  71. dispose(): void;
  72. /**
  73. * Gets the name of the current physics plugin
  74. * @returns the name of the plugin
  75. */
  76. getPhysicsPluginName(): string;
  77. /**
  78. * Adding a new impostor for the impostor tracking.
  79. * This will be done by the impostor itself.
  80. * @param impostor the impostor to add
  81. */
  82. /**
  83. * Called by the scene. No need to call it.
  84. * @param delta defines the timespan between frames
  85. */
  86. _step(delta: number): void;
  87. /**
  88. * Add a body as an active component of this engine
  89. * @param physicsBody The body to add
  90. */
  91. addBody(physicsBody: PhysicsBody): void;
  92. /**
  93. * Removes a particular body from this engine
  94. * @param physicsBody The body to remove from the simulation
  95. */
  96. removeBody(physicsBody: PhysicsBody): void;
  97. /**
  98. * @returns an array of bodies added to this engine
  99. */
  100. getBodies(): Array<PhysicsBody>;
  101. /**
  102. * Gets the current plugin used to run the simulation
  103. * @returns current plugin
  104. */
  105. getPhysicsPlugin(): IPhysicsEnginePluginV2;
  106. /**
  107. * Does a raycast in the physics world
  108. * @param from when should the ray start?
  109. * @param to when should the ray end?
  110. * @param result resulting PhysicsRaycastResult
  111. * @param query raycast query object
  112. */
  113. raycastToRef(from: Vector3, to: Vector3, result: PhysicsRaycastResult, query?: IRaycastQuery): void;
  114. /**
  115. * Does a raycast in the physics world
  116. * @param from when should the ray start?
  117. * @param to when should the ray end?
  118. * @param query raycast query object
  119. * @returns PhysicsRaycastResult
  120. */
  121. raycast(from: Vector3, to: Vector3, query?: IRaycastQuery): PhysicsRaycastResult;
  122. }