import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { Observable } from "@babylonjs/core/Misc/observable"; import { Scene } from "@babylonjs/core/scene"; import type { DeepImmutable } from "@babylonjs/core/types"; import { WasmSpinlock } from "../../../Misc/wasmSpinlock"; import type { IBulletWasmInstance } from "../bulletWasmInstance"; import type { Constraint } from "../constraint"; import type { RigidBody } from "../rigidBody"; import type { RigidBodyBundle } from "../rigidBodyBundle"; import type { IPhysicsRuntime } from "./IPhysicsRuntime"; import type { IRigidBodyBundleImpl } from "./IRigidBodyBundleImpl"; import type { IRigidBodyImpl } from "./IRigidBodyImpl"; import { PhysicsRuntimeEvaluationType } from "./physicsRuntimeEvaluationType"; /** * PhysicsRuntime handles the physics simulation and provides an interface for managing rigid bodies and constraints * * It is responsible for evaluating the physics world and synchronizing the state of rigid bodies */ export declare class PhysicsRuntime implements IPhysicsRuntime { /** * Observable that is triggered when the physics world is synchronized * in this observable callback scope, ensure that the physics world is not being evaluated */ readonly onSyncObservable: Observable; /** * Observable that is triggered on each physics tick * in this observable callback scope, physics may be evaluating on the worker thread when evaluation type is Buffered */ readonly onTickObservable: Observable; /** * @internal */ readonly wasmInstance: IBulletWasmInstance; /** * Spinlock for the physics runtime to synchronize access to the physics world state * @internal */ readonly lock: WasmSpinlock; private readonly _inner; private readonly _physicsWorld; private _scene; private _afterAnimationsBinded; private _evaluationType; private _usingWasmBackBuffer; /** * Whether to use delta time for world step (default: true) * * If true, the delta time will be calculated based on the scene's delta time * If false, the `MultiPhysicsRuntime.timeStep` property will be used as the fixed time step */ useDeltaForWorldStep: boolean; /** * The time step for the physics simulation (default: 1/60) * * This property is only used when `useDeltaForWorldStep` is false */ timeStep: number; /** * The maximum number of substeps for the physics simulation (default: 10) * * This value is used to control the maximum number of substeps taken in a single frame */ maxSubSteps: number; /** * The fixed time step for the physics simulation (default: 1/60) */ fixedTimeStep: number; private readonly _rigidBodyList; private readonly _rigidBodyBundleList; /** * Creates a new physics runtime * @param wasmInstance The Bullet WASM instance */ constructor(wasmInstance: IBulletWasmInstance); /** * Disposes the physics runtime and releases any associated resources */ dispose(): void; /** @internal */ get ptr(): number; private _nullCheck; /** @internal */ createRigidBodyImpl(): IRigidBodyImpl; /** @internal */ createRigidBodyBundleImpl(bundle: RigidBodyBundle): IRigidBodyBundleImpl; /** * Registers the physics runtime with the given scene * * This method binds the `afterAnimations` method to the scene's `onAfterAnimationsObservable` event * * You can manually call `afterAnimations` if you want to control the timing of the physics simulation * @param scene The scene to register with */ register(scene: Scene): void; /** * Unregisters the physics runtime from the scene */ unregister(): void; /** * Steps the physics simulation and synchronizes the state of rigid bodies * * In most cases, you do not need to call this method manually, * Instead, you can use the `register` method to bind it to the scene's `onAfterAnimationsObservable` event * @param deltaTime The time delta in milliseconds */ afterAnimations(deltaTime: number): void; /** * Animation evaluation type */ get evaluationType(): PhysicsRuntimeEvaluationType; set evaluationType(value: PhysicsRuntimeEvaluationType); private readonly _gravity; /** * Gets the gravity vector of the physics worlds (default: (0, -10, 0)) * @returns The gravity vector */ getGravityToRef(result: Vector3): Vector3; /** * Sets the gravity vector of the physics world * @param gravity The new gravity vector */ setGravity(gravity: DeepImmutable): void; /** * Adds a rigid body to the physics world * * If the world evaluation type is Buffered, the rigid body will be added after waiting for the lock * @param rigidBody The rigid body to add * @returns True if the rigid body was added successfully, false otherwise */ addRigidBody(rigidBody: RigidBody): boolean; /** * Removes a rigid body from the physics world * * If the runtime evaluation type is Buffered, the rigid body will be removed after waiting for the lock * @param rigidBody The rigid body to remove * @returns True if the rigid body was removed successfully, false otherwise */ removeRigidBody(rigidBody: RigidBody): boolean; /** * Adds a rigid body bundle to the physics world * * If the runtime evaluation type is Buffered, the rigid body bundle will be added after waiting for the lock * @param rigidBodyBundle The rigid body bundle to add * @returns True if the rigid body bundle was added successfully, false otherwise */ addRigidBodyBundle(rigidBodyBundle: RigidBodyBundle): boolean; /** * Removes a rigid body bundle from the physics world * * If the runtime evaluation type is Buffered, the rigid body bundle will be removed after waiting for the lock * @param rigidBodyBundle The rigid body bundle to remove * @returns True if the rigid body bundle was removed successfully, false otherwise */ removeRigidBodyBundle(rigidBodyBundle: RigidBodyBundle): boolean; /** * Gets the list of rigid bodies in the physics world */ get rigidBodyList(): readonly RigidBody[]; /** * Gets the list of rigid body bundles in the physics world */ get rigidBodyBundleList(): readonly RigidBodyBundle[]; /** * Adds a constraint to the physics world * * If the runtime evaluation type is Buffered, the constraint will be added after waiting for the lock * @param constraint The constraint to add * @param disableCollisionsBetweenLinkedBodies Whether to disable collisions between the linked bodies * @returns True if the constraint was added successfully, false otherwise */ addConstraint(constraint: Constraint, disableCollisionsBetweenLinkedBodies: boolean): boolean; /** * Removes a constraint from the physics world * * If the runtime evaluation type is Buffered, the constraint will be removed after waiting for the lock * @param constraint The constraint to remove * @returns True if the constraint was removed successfully, false otherwise */ removeConstraint(constraint: Constraint): boolean; }