IPhysicsEngine.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { Vector3 } from "../Maths/math.vector";
  2. import type { PhysicsRaycastResult, IRaycastQuery } from "./physicsRaycastResult";
  3. import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "./v1/IPhysicsEnginePlugin";
  4. import type { IPhysicsEnginePluginV2 } from "./v2/IPhysicsEnginePlugin";
  5. /**
  6. * Interface used to define a physics engine
  7. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  8. */
  9. export interface IPhysicsEngine {
  10. /**
  11. * Gets the gravity vector used by the simulation
  12. */
  13. gravity: Vector3;
  14. /**
  15. *
  16. */
  17. getPluginVersion(): number;
  18. /**
  19. * Sets the gravity vector used by the simulation
  20. * @param gravity defines the gravity vector to use
  21. */
  22. setGravity(gravity: Vector3): void;
  23. /**
  24. * Set the time step of the physics engine.
  25. * Default is 1/60.
  26. * To slow it down, enter 1/600 for example.
  27. * To speed it up, 1/30
  28. * @param newTimeStep the new timestep to apply to this world.
  29. */
  30. setTimeStep(newTimeStep: number): void;
  31. /**
  32. * Get the time step of the physics engine.
  33. * @returns the current time step
  34. */
  35. getTimeStep(): number;
  36. /**
  37. * Set the sub time step of the physics engine.
  38. * Default is 0 meaning there is no sub steps
  39. * To increase physics resolution precision, set a small value (like 1 ms)
  40. * @param subTimeStep defines the new sub timestep used for physics resolution.
  41. */
  42. setSubTimeStep(subTimeStep: number): void;
  43. /**
  44. * Get the sub time step of the physics engine.
  45. * @returns the current sub time step
  46. */
  47. getSubTimeStep(): number;
  48. /**
  49. * Release all resources
  50. */
  51. dispose(): void;
  52. /**
  53. * Gets the name of the current physics plugin
  54. * @returns the name of the plugin
  55. */
  56. getPhysicsPluginName(): string;
  57. /**
  58. * Gets the current plugin used to run the simulation
  59. * @returns current plugin
  60. */
  61. getPhysicsPlugin(): IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2 | null;
  62. /**
  63. * Does a raycast in the physics world
  64. * @param from when should the ray start?
  65. * @param to when should the ray end?
  66. * @returns PhysicsRaycastResult
  67. */
  68. raycast(from: Vector3, to: Vector3, query?: IRaycastQuery): PhysicsRaycastResult;
  69. /**
  70. * Called by the scene. No need to call it.
  71. * @param delta defines the timespan between frames
  72. */
  73. _step(delta: number): void;
  74. }