import type { Vector3 } from "@babylonjs/core/Maths/math.vector"; import type { DeepImmutable } from "@babylonjs/core/types"; import type { Constraint } from "./constraint"; import type { IPhysicsRuntime } from "./Impl/IPhysicsRuntime"; import type { RigidBody } from "./rigidBody"; import type { RigidBodyBundle } from "./rigidBodyBundle"; /** * MultiPhysicsWorld handles multiple physics worlds and allows to add rigid bodies and constraints to them * * It supports multi-threading by introducing a rigid body shadow concept * * Rigid body shadow is a copy of the rigid body that can be added to a different world * * Internally, it just creates a new rigid body with Kinematic motion type and synchronizes the position and rotation with the original rigid body */ export declare class MultiPhysicsWorld { private readonly _runtime; private readonly _inner; private readonly _fromPointer; /** * Creates a new MultiPhysicsWorld instance * @param runtime The physics runtime that this world belongs to * @param allowDynamicShadow Whether to allow dynamic shadow */ constructor(runtime: IPhysicsRuntime, allowDynamicShadow: boolean); /** * Creates a MultiPhysicsWorld instance from an existing pointer * @param runtime The physics runtime that this world belongs to * @param ptr The pointer to the existing MultiPhysicsWorld instance * @internal */ constructor(runtime: IPhysicsRuntime, ptr: number); /** * Disposes the physics world */ dispose(): void; /** * @internal */ get ptr(): number; /** * @internal */ addReference(): void; /** * @internal */ removeReference(): void; private _nullCheck; /** * Sets the gravity vector of the physics world * * This operation performs waiting for the lock before executing * @param gravity The gravity vector */ setGravity(gravity: DeepImmutable): void; /** * Steps the physics simulation * @param timeStep The time step to use for the simulation * @param maxSubSteps The maximum number of substeps to use for the simulation * @param fixedTimeStep The fixed time step to use for the simulation */ stepSimulation(timeStep: number, maxSubSteps: number, fixedTimeStep: number): void; /** * Adds a rigid body to the physics world * * If the world is not existing, it will be created * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to add * @param worldId The ID of the world to add the rigid body to * @returns True if the rigid body was added successfully, false otherwise */ addRigidBody(rigidBody: RigidBody, worldId: number): boolean; /** * Removes a rigid body from the physics world * * If there are no more rigid bodies in the world, the world will be destroyed automatically * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to remove * @param worldId The ID of the world to remove the rigid body from * @returns True if the rigid body was removed successfully, false otherwise */ removeRigidBody(rigidBody: RigidBody, worldId: number): boolean; /** * Adds a rigid body bundle to the physics world * * If the world is not existing, it will be created * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to add * @param worldId The ID of the world to add the rigid body bundle to * @returns True if the rigid body bundle was added successfully, false otherwise */ addRigidBodyBundle(rigidBodyBundle: RigidBodyBundle, worldId: number): boolean; /** * Removes a rigid body bundle from the physics world * * If there are no more rigid body bundles in the world, the world will be destroyed automatically * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to remove * @param worldId The ID of the world to remove the rigid body bundle from * @returns True if the rigid body bundle was removed successfully, false otherwise */ removeRigidBodyBundle(rigidBodyBundle: RigidBodyBundle, worldId: number): boolean; /** * Adds a rigid body to all worlds * * rigid body physics mode must be Static or Kinematic * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to add * @returns True if the rigid body was added successfully, false otherwise */ addRigidBodyToGlobal(rigidBody: RigidBody): boolean; /** * Removes a rigid body from all worlds * * This method does not remove the rigid body that is added with `MultiPhysicsWorld.addRigidBody` * * Only the rigid body that is added with `MultiPhysicsWorld.addRigidBodyToGlobal` will be removed * * If there are no more rigid bodies in the world, the world will be destroyed automatically * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to remove * @returns True if the rigid body was removed successfully, false otherwise */ removeRigidBodyFromGlobal(rigidBody: RigidBody): boolean; /** * Adds a rigid body bundle to all worlds * * rigid body bundle physics mode must be Static or Kinematic * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to add * @returns True if the rigid body bundle was added successfully, false otherwise */ addRigidBodyBundleToGlobal(rigidBodyBundle: RigidBodyBundle): boolean; /** * Removes a rigid body bundle from all worlds * * This method does not remove the rigid body bundle that is added with `MultiPhysicsWorld.addRigidBodyBundle` * * Only the rigid body bundle that is added with `MultiPhysicsWorld.addRigidBodyBundleToGlobal` will be removed * * If there are no more rigid body bundles in the world, the world will be destroyed automatically * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to remove * @returns True if the rigid body bundle was removed successfully, false otherwise */ removeRigidBodyBundleFromGlobal(rigidBodyBundle: RigidBodyBundle): boolean; /** * Adds a rigid body shadow to the physics world * * In case of Dynamic physics mode, Rigid body firstly needs to be added to the other world * * The worldId must be not equal to the worldId of the rigid body * * Rigid body shadow allows the rigid body to be added to multiple worlds * * When RigidBody with dynamic physics mode is added to the world as shadow, * the rigid body will be added to the world as kinematic * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to add * @param worldId The ID of the world to add the rigid body as shadow * @returns True if the rigid body shadow was added successfully, false otherwise */ addRigidBodyShadow(rigidBody: RigidBody, worldId: number): boolean; /** * Removes a rigid body shadow from the physics world * * This operation performs waiting for the lock before executing * @param rigidBody The rigid body to remove * @param worldId The ID of the world to remove the rigid body shadow from * @returns True if the rigid body shadow was removed successfully, false otherwise */ removeRigidBodyShadow(rigidBody: RigidBody, worldId: number): boolean; /** * Adds a rigid body bundle shadow to the physics world * * In case of Dynamic physics mode, Rigid body bundle firstly needs to be added to the other world * * The worldId must be not equal to the worldId of the rigid body bundle * * Rigid body bundle shadow allows the rigid body bundle to be added to multiple worlds * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to add * @param worldId The ID of the world to add the rigid body bundle as shadow * @returns True if the rigid body shadow was added successfully, false otherwise */ addRigidBodyBundleShadow(rigidBodyBundle: RigidBodyBundle, worldId: number): boolean; /** * Removes a rigid body bundle shadow from the physics world * * This operation performs waiting for the lock before executing * @param rigidBodyBundle The rigid body bundle to remove * @param worldId The ID of the world to remove the rigid body bundle shadow from * @returns True if the rigid body bundle shadow was removed successfully, false otherwise */ removeRigidBodyBundleShadow(rigidBodyBundle: RigidBodyBundle, worldId: number): boolean; /** * Adds a constraint to the physics world * * Constraint worldId must be equal to the worldId of the connected rigid bodies * * This operation performs waiting for the lock before executing * @param constraint The constraint to add * @param worldId The ID of the world to add the constraint to * @param disableCollisionsBetweenLinkedBodies Whether to disable collisions between the linked bodies * @returns True if the constraint was added successfully, false otherwise */ addConstraint(constraint: Constraint, worldId: number, disableCollisionsBetweenLinkedBodies: boolean): boolean; /** * Removes a constraint from the physics world * * This operation performs waiting for the lock before executing * @param constraint The constraint to remove * @param worldId The ID of the world to remove the constraint from * @returns True if the constraint was removed successfully, false otherwise */ removeConstraint(constraint: Constraint, worldId: number): boolean; }