@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.
137 lines (136 loc) • 4.72 kB
TypeScript
import type { Nullable } from "../../types.js";
import { Vector3 } from "../../Maths/math.vector.js";
import type { IPhysicsEngine } from "../IPhysicsEngine.js";
import type { IPhysicsEnginePluginV2 } from "./IPhysicsEnginePlugin.js";
import type { IRaycastQuery } from "../physicsRaycastResult.js";
import { PhysicsRaycastResult } from "../physicsRaycastResult.js";
import type { PhysicsBody } from "./physicsBody.js";
/**
* Class used to control physics engine
* @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
*/
export declare class PhysicsEngine implements IPhysicsEngine {
private _physicsPlugin;
/** @internal */
private _physicsBodies;
private _subTimeStep;
/**
* Gets the gravity vector used by the simulation
*/
gravity: Vector3;
/**
*
* @returns physics plugin version
*/
getPluginVersion(): number;
/**
* Factory used to create the default physics plugin.
* @returns The default physics plugin
*/
static DefaultPluginFactory(): IPhysicsEnginePluginV2;
/**
* 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?: IPhysicsEnginePluginV2);
/**
* 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
* Unit is seconds.
* @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;
/**
* Set the maximum allowed linear and angular velocities
* @param maxLinearVelocity maximum allowed linear velocity
* @param maxAngularVelocity maximum allowed angular velocity
*/
setVelocityLimits(maxLinearVelocity: number, maxAngularVelocity: number): void;
/**
* @returns maximum allowed linear velocity
*/
getMaxLinearVelocity(): number;
/**
* @returns maximum allowed angular velocity
*/
getMaxAngularVelocity(): number;
/**
* Adding a new impostor for the impostor tracking.
* This will be done by the impostor itself.
* @param impostor the impostor to add
*/
/**
* Called by the scene. No need to call it.
* @param delta defines the timespan between frames
*/
_step(delta: number): void;
/**
* Add a body as an active component of this engine
* @param physicsBody The body to add
*/
addBody(physicsBody: PhysicsBody): void;
/**
* Removes a particular body from this engine
* @param physicsBody The body to remove from the simulation
*/
removeBody(physicsBody: PhysicsBody): void;
/**
* @returns an array of bodies added to this engine
*/
getBodies(): Array<PhysicsBody>;
/**
* Gets the current plugin used to run the simulation
* @returns current plugin
*/
getPhysicsPlugin(): IPhysicsEnginePluginV2;
/**
* 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
* @param query raycast query object
*/
raycastToRef(from: Vector3, to: Vector3, result: PhysicsRaycastResult, query?: IRaycastQuery): void;
/**
* Does a raycast in the physics world
* @param from when should the ray start?
* @param to when should the ray end?
* @param query raycast query object
* @returns PhysicsRaycastResult
*/
raycast(from: Vector3, to: Vector3, query?: IRaycastQuery): PhysicsRaycastResult;
}