123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import type { Nullable } from "../../types";
- import { Vector3 } from "../../Maths/math.vector";
- import type { IPhysicsEnginePlugin } from "./IPhysicsEnginePlugin";
- import type { IPhysicsEngine } from "../IPhysicsEngine";
- import type { PhysicsImpostor, IPhysicsEnabledObject } from "./physicsImpostor";
- import type { PhysicsJoint } from "./physicsJoint";
- import type { PhysicsRaycastResult } from "../physicsRaycastResult";
- /**
- * Class used to control physics engine
- * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
- */
- export declare class PhysicsEngine implements IPhysicsEngine {
- private _physicsPlugin;
- /**
- * Global value used to control the smallest number supported by the simulation
- */
- private _impostors;
- private _joints;
- private _subTimeStep;
- private _uniqueIdCounter;
- /**
- * Gets the gravity vector used by the simulation
- */
- gravity: Vector3;
- /**
- *
- * @returns version
- */
- getPluginVersion(): number;
- /**
- * @virtual
- * Factory used to create the default physics plugin.
- * @returns The default physics plugin
- */
- static DefaultPluginFactory(): IPhysicsEnginePlugin;
- /**
- * Creates a new Physics Engine
- * @param gravity defines the gravity vector used by the simulation
- * @param _physicsPlugin defines the plugin to use (CannonJS by default)
- */
- constructor(gravity: Nullable<Vector3>, _physicsPlugin?: IPhysicsEnginePlugin);
- /**
- * Sets the gravity vector used by the simulation
- * @param gravity defines the gravity vector to use
- */
- setGravity(gravity: Vector3): void;
- /**
- * Set the time step of the physics engine.
- * Default is 1/60.
- * To slow it down, enter 1/600 for example.
- * To speed it up, 1/30
- * @param newTimeStep defines the new timestep to apply to this world.
- */
- setTimeStep(newTimeStep?: number): void;
- /**
- * Get the time step of the physics engine.
- * @returns the current time step
- */
- getTimeStep(): number;
- /**
- * Set the sub time step of the physics engine.
- * Default is 0 meaning there is no sub steps
- * To increase physics resolution precision, set a small value (like 1 ms)
- * @param subTimeStep defines the new sub timestep used for physics resolution.
- */
- setSubTimeStep(subTimeStep?: number): void;
- /**
- * Get the sub time step of the physics engine.
- * @returns the current sub time step
- */
- getSubTimeStep(): number;
- /**
- * Release all resources
- */
- dispose(): void;
- /**
- * Gets the name of the current physics plugin
- * @returns the name of the plugin
- */
- getPhysicsPluginName(): string;
- /**
- * Adding a new impostor for the impostor tracking.
- * This will be done by the impostor itself.
- * @param impostor the impostor to add
- */
- addImpostor(impostor: PhysicsImpostor): void;
- /**
- * Remove an impostor from the engine.
- * This impostor and its mesh will not longer be updated by the physics engine.
- * @param impostor the impostor to remove
- */
- removeImpostor(impostor: PhysicsImpostor): void;
- /**
- * Add a joint to the physics engine
- * @param mainImpostor defines the main impostor to which the joint is added.
- * @param connectedImpostor defines the impostor that is connected to the main impostor using this joint
- * @param joint defines the joint that will connect both impostors.
- */
- addJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
- /**
- * Removes a joint from the simulation
- * @param mainImpostor defines the impostor used with the joint
- * @param connectedImpostor defines the other impostor connected to the main one by the joint
- * @param joint defines the joint to remove
- */
- removeJoint(mainImpostor: PhysicsImpostor, connectedImpostor: PhysicsImpostor, joint: PhysicsJoint): void;
- /**
- * Called by the scene. No need to call it.
- * @param delta defines the timespan between frames
- */
- _step(delta: number): void;
- /**
- * Gets the current plugin used to run the simulation
- * @returns current plugin
- */
- getPhysicsPlugin(): IPhysicsEnginePlugin;
- /**
- * Gets the list of physic impostors
- * @returns an array of PhysicsImpostor
- */
- getImpostors(): Array<PhysicsImpostor>;
- /**
- * Gets the impostor for a physics enabled object
- * @param object defines the object impersonated by the impostor
- * @returns the PhysicsImpostor or null if not found
- */
- getImpostorForPhysicsObject(object: IPhysicsEnabledObject): Nullable<PhysicsImpostor>;
- /**
- * Gets the impostor for a physics body object
- * @param body defines physics body used by the impostor
- * @returns the PhysicsImpostor or null if not found
- */
- getImpostorWithPhysicsBody(body: any): Nullable<PhysicsImpostor>;
- /**
- * Does a raycast in the physics world
- * @param from when should the ray start?
- * @param to when should the ray end?
- * @returns PhysicsRaycastResult
- */
- raycast(from: Vector3, to: Vector3): PhysicsRaycastResult;
- /**
- * Does a raycast in the physics world
- * @param from when should the ray start?
- * @param to when should the ray end?
- * @param result resulting PhysicsRaycastResult
- * @returns true if the ray hits an impostor, else false
- */
- raycastToRef(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;
- }
|