@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
150 lines (149 loc) • 5.62 kB
TypeScript
import type { Nullable } from "../../types.js";
import { Vector3 } from "../../Maths/math.vector.js";
import type { IPhysicsEnginePlugin } from "./IPhysicsEnginePlugin.js";
import type { IPhysicsEngine } from "../IPhysicsEngine.js";
import type { PhysicsImpostor, IPhysicsEnabledObject } from "./physicsImpostor.js";
import type { PhysicsJoint } from "./physicsJoint.js";
import type { PhysicsRaycastResult } from "../physicsRaycastResult.js";
/**
* 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;
}