import type { BoundingBox } from "@babylonjs/core/Culling/boundingBox"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; import { Quaternion } from "@babylonjs/core/Maths/math.vector"; import type { Mesh } from "@babylonjs/core/Meshes/mesh"; import type { TransformNode } from "@babylonjs/core/Meshes/transformNode"; import { Observable } from "@babylonjs/core/Misc/observable"; import type { IRaycastQuery, PhysicsRaycastResult } from "@babylonjs/core/Physics/physicsRaycastResult"; import type { PhysicsConstraintAxisLimitMode, PhysicsConstraintMotorType, PhysicsShapeParameters } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; import { type ConstrainedBodyPair, type IBasePhysicsCollisionEvent, type IPhysicsCollisionEvent, type IPhysicsEnginePluginV2, type PhysicsConstraintAxis, type PhysicsMassProperties, PhysicsMotionType, PhysicsShapeType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin"; import type { PhysicsBody } from "@babylonjs/core/Physics/v2/physicsBody"; import type { PhysicsConstraint } from "@babylonjs/core/Physics/v2/physicsConstraint"; import { type PhysicsMaterial } from "@babylonjs/core/Physics/v2/physicsMaterial"; import type { PhysicsShape } from "@babylonjs/core/Physics/v2/physicsShape"; import type { Nullable } from "@babylonjs/core/types"; import type { IBulletWasmInstance } from "../bulletWasmInstance"; import { MultiPhysicsRuntime } from "../Impl/multiPhysicsRuntime"; export declare class BulletPluginCommandContext { worldId: number; constructor(); } /** * The Bullet Physics plugin */ export declare class BulletPlugin implements IPhysicsEnginePluginV2 { /** * Created bullet physics runtime which physics bodies are added to */ world: MultiPhysicsRuntime; /** * Name of the plugin */ name: string; /** * Observable for collision started and collision continued events */ onCollisionObservable: Observable; /** * Observable for collision ended events */ onCollisionEndedObservable: Observable; /** * Observable for trigger entered and trigger exited events */ onTriggerCollisionObservable: Observable; private readonly _initializedBodies; private readonly _unInitializedBodies; private readonly _shapeMap; readonly commandContext: BulletPluginCommandContext; private static readonly _TempMatrix; private static readonly _TempMatrix2; private static readonly _TempMatrix3; private static readonly _TempVector; private static readonly _TempVector2; private static readonly _TempQuaternion; constructor(wasmInstance: IBulletWasmInstance); /** * Sets the gravity of the physics world. * * @param gravity - The gravity vector to set. * */ setGravity(gravity: Vector3): void; /** * Sets the fixed time step for the physics engine. * * @param timeStep - The fixed time step to use for the physics engine. * */ setTimeStep(timeStep: number): void; /** * Gets the fixed time step used by the physics engine. * * @returns The fixed time step used by the physics engine. * */ getTimeStep(): number; /** * Executes a single step of the physics engine. * * @param delta The time delta in seconds since the last step. * @param physicsBodies An array of physics bodies to be simulated. * * This method is useful for simulating the physics engine. It sets the physics body transformation, * steps the world, syncs the physics body, and notifies collisions. This allows for the physics engine * to accurately simulate the physics bodies in the world. */ executeStep(delta: number, bodies: PhysicsBody[]): void; /** * Sets the transformation of the given physics body to the given transform node. * @param body The physics body to set the transformation for. * @param node The transform node to set the transformation from. * Sets the transformation of the given physics body to the given transform node. * * This function is useful for setting the transformation of a physics body to a * transform node, which is necessary for the physics engine to accurately simulate * the motion of the body. It also takes into account instances of the transform * node, which is necessary for accurate simulation of multiple bodies with the * same transformation. */ setPhysicsBodyTransformation(body: PhysicsBody, node: TransformNode): void; /** * Returns the version of the physics engine plugin. * * @returns The version of the physics engine plugin. * * This method is useful for determining the version of the physics engine plugin that is currently running. */ getPluginVersion(): number; /** * 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; private static _MotionTypeToBulletMotionType; private static _BulletMotionTypeToMotionType; /** * Initializes a physics body with the given position and orientation. * * @param body - The physics body to initialize. * @param motionType - The motion type of the body. * @param position - The position of the body. * @param orientation - The orientation of the body. * This code is useful for initializing a physics body with the given position and orientation. * It creates a plugin data for the body and adds it to the world. It then converts the position * and orientation to a transform and sets the body's transform to the given values. */ initBody(body: PhysicsBody, motionType: PhysicsMotionType, position: Vector3, orientation: Quaternion): void; /** * Initializes the body instances for a given physics body and mesh. * * @param body - The physics body to initialize. * @param motionType - How the body will be handled by the engine * @param mesh - The mesh to initialize. * * This code is useful for creating a physics body from a mesh. It creates a * body instance for each instance of the mesh and adds it to the world. It also * sets the position of the body instance to the position of the mesh instance. * This allows for the physics engine to accurately simulate the mesh in the * world. */ initBodyInstances(body: PhysicsBody, motionType: PhysicsMotionType, mesh: Mesh): void; /** * Update the internal body instances for a given physics body to match the instances in a mesh. * @param body the body that will be updated * @param mesh the mesh with reference instances */ updateBodyInstances(body: PhysicsBody, mesh: Mesh): void; /** * Removes a body from the world. To dispose of a body, it is necessary to remove it from the world first. * * @param body - The body to remove. */ removeBody(body: PhysicsBody): void; /** * Synchronizes the transform of a physics body with its transform node. * @param body - The physics body to synchronize. * * This function is useful for keeping the physics body's transform in sync with its transform node. * This is important for ensuring that the physics body is accurately represented in the physics engine. */ sync(body: PhysicsBody): void; /** * Synchronizes the transform of a physics body with the transform of its * corresponding transform node. * * @param body - The physics body to synchronize. * @param transformNode - The destination Transform Node. * * This code is useful for synchronizing the position and orientation of a * physics body with the position and orientation of its corresponding * transform node. This is important for ensuring that the physics body and * the transform node are in the same position and orientation in the scene. * This is necessary for the physics engine to accurately simulate the * physical behavior of the body. */ syncTransform(body: PhysicsBody, transformNode: TransformNode): void; /** * Sets the shape of a physics body. * @param body - The physics body to set the shape for. * @param shape - The physics shape to set. * * This function is used to set the shape of a physics body. It is useful for * creating a physics body with a specific shape, such as a box or a sphere, * which can then be used to simulate physical interactions in a physics engine. * This function is especially useful for meshes with multiple instances, as it * will set the shape for each instance of the mesh. */ setShape(body: PhysicsBody, shape: Nullable): void; /** * Gets the shape of a physics body. This will create a new shape object * * @param body - The physics body. * @returns The shape of the physics body. * */ getShape(body: PhysicsBody): Nullable; /** * Gets the type of a physics shape. * @param shape - The physics shape to get the type for. * @returns The type of the physics shape. * */ getShapeType(shape: PhysicsShape): PhysicsShapeType; /** * Sets the event mask of a physics body. * @param body - The physics body to set the event mask for. * @param eventMask - The event mask to set. * @param instanceIndex - The index of the instance to set the event mask for * * This function is useful for setting the event mask of a physics body, which is used to determine which events the body will respond to. This is important for ensuring that the physics engine is able to accurately simulate the behavior of the body in the game world. */ setEventMask(body: PhysicsBody, eventMask: number, instanceIndex?: number): void; /** * Retrieves the event mask of a physics body. * * @param body - The physics body to retrieve the event mask from. * @param instanceIndex - The index of the instance to retrieve the event mask from. * @returns The event mask of the physics body. * */ getEventMask(body: PhysicsBody, instanceIndex?: number): number; /** * sets the motion type of a physics body. * @param body - The physics body to set the motion type for. * @param motionType - The motion type to set. * @param instanceIndex - The index of the instance to set the motion type for. If undefined, the motion type of all the bodies will be set. */ setMotionType(body: PhysicsBody, motionType: PhysicsMotionType, instanceIndex?: number): void; /** * Gets the motion type of a physics body. * @param body - The physics body to get the motion type from. * @param instanceIndex - The index of the instance to get the motion type from. If not specified, the motion type of the first instance will be returned. * @returns The motion type of the physics body. */ getMotionType(body: PhysicsBody, instanceIndex?: number): PhysicsMotionType; /** * Computes the mass properties of a physics body, from it's shape * * @param body - The physics body to copmute the mass properties of * @param instanceIndex - The index of the instance to compute the mass properties of. * @returns The mass properties of the physics body. */ computeMassProperties(body: PhysicsBody, instanceIndex?: number): PhysicsMassProperties; /** * Sets the mass properties of a physics body. * * @param body - The physics body to set the mass properties of. * @param massProps - The mass properties to set. * @param instanceIndex - The index of the instance to set the mass properties of. If undefined, the mass properties of all the bodies will be set. * This function is useful for setting the mass properties of a physics body, * such as its mass, inertia, and center of mass. This is important for * accurately simulating the physics of the body in the physics engine. * */ setMassProperties(body: PhysicsBody, massProps: PhysicsMassProperties, instanceIndex?: number): void; /** * Gets the mass properties of a physics body. * @param body - The physics body to get the mass properties from. * @param instanceIndex - The index of the instance to get the mass properties from. If not specified, the mass properties of the first instance will be returned. * @returns The mass properties of the physics body. */ getMassProperties(body: PhysicsBody, instanceIndex?: number): PhysicsMassProperties; /** * Sets the linear damping of the given body. * @param body - The body to set the linear damping for. * @param damping - The linear damping to set. * @param instanceIndex - The index of the instance to set the linear damping for. If not specified, the linear damping of the first instance will be set. * * This method is useful for controlling the linear damping of a body in a physics engine. * Linear damping is a force that opposes the motion of the body, and is proportional to the velocity of the body. * This method allows the user to set the linear damping of a body, which can be used to control the motion of the body. */ setLinearDamping(body: PhysicsBody, damping: number, instanceIndex?: number): void; /** * Gets the linear damping of the given body. * @param body - The body to get the linear damping from. * @param instanceIndex - The index of the instance to get the linear damping from. If not specified, the linear damping of the first instance will be returned. * @returns The linear damping of the given body. * * This method is useful for getting the linear damping of a body in a physics engine. * Linear damping is a force that opposes the motion of the body and is proportional to the velocity of the body. * It is used to simulate the effects of air resistance and other forms of friction. */ getLinearDamping(body: PhysicsBody, instanceIndex?: number): number; /** * Gets the angular damping of a physics body. * @param body - The physics body to get the angular damping from. * @param instanceIndex - The index of the instance to get the angular damping from. If not specified, the angular damping of the first instance will be returned. * @returns The angular damping of the body. * * This function is useful for retrieving the angular damping of a physics body, * which is used to control the rotational motion of the body. The angular damping is a value between 0 and 1, where 0 is no damping and 1 is full damping. */ setAngularDamping(body: PhysicsBody, damping: number, instanceIndex?: number): void; /** * Gets the angular damping of a physics body. * @param body - The physics body to get the angular damping from. * @param instanceIndex - The index of the instance to get the angular damping from. If not specified, the angular damping of the first instance will be returned. * @returns The angular damping of the body. * * This function is useful for retrieving the angular damping of a physics body, * which is used to control the rotational motion of the body. The angular damping is a value between 0 and 1, where 0 is no damping and 1 is full damping. */ getAngularDamping(body: PhysicsBody, instanceIndex?: number): number; /** * Sets the linear velocity of a physics body. * @param body - The physics body to set the linear velocity of. * @param linVel - The linear velocity to set. * @param instanceIndex - The index of the instance to set the linear velocity of. If not specified, the linear velocity of the first instance will be set. * * This function is useful for setting the linear velocity of a physics body, which is necessary for simulating * motion in a physics engine. The linear velocity is the speed and direction of the body's movement. */ setLinearVelocity(body: PhysicsBody, linVel: Vector3, instanceIndex?: number): void; /** * Gets the linear velocity of a physics body and stores it in a given vector. * @param body - The physics body to get the linear velocity from. * @param linVel - The vector to store the linear velocity in. * @param instanceIndex - The index of the instance to get the linear velocity from. If not specified, the linear velocity of the first instance will be returned. * * This function is useful for retrieving the linear velocity of a physics body, * which can be used to determine the speed and direction of the body. This * information can be used to simulate realistic physics behavior in a game. */ getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3, instanceIndex?: number): void; /** * Applies an impulse to a physics body at a given location. * @param body - The physics body to apply the impulse to. * @param impulse - The impulse vector to apply. * @param location - The location in world space to apply the impulse. * @param instanceIndex - The index of the instance to apply the impulse to. If not specified, the impulse will be applied to all instances. * * This method is useful for applying an impulse to a physics body at a given location. * This can be used to simulate physical forces such as explosions, collisions, and gravity. */ applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3, instanceIndex?: number): void; /** * Applies an angular impulse(torque) to a physics body * @param body - The physics body to apply the impulse to. * @param angularImpulse - The torque value * @param instanceIndex - The index of the instance to apply the impulse to. If not specified, the impulse will be applied to all instances. */ applyAngularImpulse(body: PhysicsBody, angularImpulse: Vector3, instanceIndex?: number): void; /** * Applies a force to a physics body at a given location. * @param body - The physics body to apply the impulse to. * @param force - The force vector to apply. * @param location - The location in world space to apply the impulse. * @param instanceIndex - The index of the instance to apply the force to. If not specified, the force will be applied to all instances. * * This method is useful for applying a force to a physics body at a given location. * This can be used to simulate physical forces such as explosions, collisions, and gravity. */ applyForce(body: PhysicsBody, force: Vector3, location: Vector3, instanceIndex?: number): void; /** * Applies a torque to a physics body. * @param body - The physics body to apply the torque to. * @param torque - The torque vector. * @param instanceIndex - The index of the instance to apply the torque to. If not specified, the torque will be applied to all instances. * * This method is useful for applying a torque to a physics body. * This can be used to simulate rotational forces such as motors, angular momentum, and rotational dynamics. */ applyTorque(body: PhysicsBody, torque: Vector3, instanceIndex?: number): void; /** * Sets the angular velocity of a physics body. * * @param body - The physics body to set the angular velocity of. * @param angVel - The angular velocity to set. * @param instanceIndex - The index of the instance to set the angular velocity of. If not specified, the angular velocity of the first instance will be set. * * This function is useful for setting the angular velocity of a physics body in a physics engine. * This allows for more realistic simulations of physical objects, as they can be given a rotational velocity. */ setAngularVelocity(body: PhysicsBody, angVel: Vector3, instanceIndex?: number): void; /** * Gets the angular velocity of a body. * @param body - The body to get the angular velocity from. * @param angVel - The vector3 to store the angular velocity. * @param instanceIndex - The index of the instance to get the angular velocity from. If not specified, the angular velocity of the first instance will be returned. * * This method is useful for getting the angular velocity of a body in a physics engine. It * takes the body and a vector3 as parameters and stores the angular velocity of the body * in the vector3. This is useful for getting the angular velocity of a body in order to * calculate the motion of the body in the physics engine. */ getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3, instanceIndex?: number): void; getBodyGeometry(body: PhysicsBody): {}; /** * Disposes a physics body. * * @param body - The physics body to dispose. * * This method is useful for releasing the resources associated with a physics body when it is no longer needed. * This is important for avoiding memory leaks in the physics engine. */ disposeBody(body: PhysicsBody): void; setCollisionCallbackEnabled(body: PhysicsBody, enabled: boolean, instanceIndex?: number): void; setCollisionEndedCallbackEnabled(body: PhysicsBody, enabled: boolean, instanceIndex?: number): void; addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void; getCollisionObservable(body: PhysicsBody, instanceIndex?: number): Observable; getCollisionEndedObservable(body: PhysicsBody, instanceIndex?: number): Observable; /** * Sets the gravity factor of a body * @param body the physics body to set the gravity factor for * @param factor the gravity factor * @param instanceIndex the index of the instance in an instanced body */ setGravityFactor(body: PhysicsBody, factor: number, instanceIndex?: number): void; /** * Get the gravity factor of a body * @param body the physics body to get the gravity factor from * @param instanceIndex the index of the instance in an instanced body. If not specified, the gravity factor of the first instance will be returned. * @returns the gravity factor */ getGravityFactor(body: PhysicsBody, instanceIndex?: number): number; /** * Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target * @param body The physics body to set the target transformation for. * @param position The target position * @param rotation The target rotation * @param instanceIndex The index of the instance in an instanced body */ setTargetTransform(body: PhysicsBody, position: Vector3, rotation: Quaternion, instanceIndex?: number): void; /** * Initializes a physics shape with the given type and parameters. * @param shape - The physics shape to initialize. * @param type - The type of shape to initialize. * @param options - The parameters for the shape. * * This code is useful for initializing a physics shape with the given type and parameters. * It allows for the creation of a sphere, box, capsule, container, cylinder, mesh, and heightfield. * Depending on the type of shape, different parameters are required. * For example, a sphere requires a radius, while a box requires extents and a rotation. */ initShape(shape: PhysicsShape, type: PhysicsShapeType, options: PhysicsShapeParameters): void; /** * Sets the shape filter membership mask of a body * @param shape - The physics body to set the shape filter membership mask for. * @param membershipMask - The shape filter membership mask to set. */ setShapeFilterMembershipMask(shape: PhysicsShape, membershipMask: number): void; /** * Gets the shape filter membership mask of a body * @param shape - The physics body to get the shape filter membership mask from. * @returns The shape filter membership mask of the given body. */ getShapeFilterMembershipMask(shape: PhysicsShape): number; /** * Sets the shape filter collide mask of a body * @param shape - The physics body to set the shape filter collide mask for. * @param collideMask - The shape filter collide mask to set. */ setShapeFilterCollideMask(shape: PhysicsShape, collideMask: number): void; /** * Gets the shape filter collide mask of a body * @param shape - The physics body to get the shape filter collide mask from. * @returns The shape filter collide mask of the given body. */ getShapeFilterCollideMask(shape: PhysicsShape): number; /** * Sets the material of a physics shape. * @param shape - The physics shape to set the material of. * @param material - The material to set. * */ setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void; /** * Gets the material associated with a physics shape. * @param shape - The shape to get the material from. * @returns The material associated with the shape. */ getMaterial(shape: PhysicsShape): PhysicsMaterial; /** * Sets the density of a physics shape. * @param shape - The physics shape to set the density of. * @param density - The density to set. * */ setDensity(shape: PhysicsShape, density: number): void; /** * Calculates the density of a given physics shape. * * @param shape - The physics shape to calculate the density of. * @returns The density of the given physics shape. * */ getDensity(shape: PhysicsShape): number; /** * Gets the transform infos of a given transform node. * This code is useful for getting the position and orientation of a given transform node. * It first checks if the node has a rotation quaternion, and if not, it creates one from the node's rotation. * It then creates an array containing the position and orientation of the node and returns it. * @param node - The transform node. * @returns An array containing the position and orientation of the node. */ private _getTransformInfos; addChild(shape: PhysicsShape, newChild: PhysicsShape, translation?: Vector3, rotation?: Quaternion, scale?: Vector3): void; removeChild(shape: PhysicsShape, childIndex: number): void; getNumChildren(shape: PhysicsShape): number; getBoundingBox(shape: PhysicsShape): BoundingBox; getBodyBoundingBox(body: PhysicsBody): BoundingBox; /** * Releases a physics shape from the physics engine. * * @param shape - The physics shape to be released. * * This method is useful for releasing a physics shape from the physics engine, freeing up resources and preventing memory leaks. */ disposeShape(shape: PhysicsShape): void; setTrigger(shape: PhysicsShape, isTrigger: boolean): void; initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void; setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void; getEnabled(constraint: PhysicsConstraint): boolean; setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void; getCollisionsEnabled(constraint: PhysicsConstraint): boolean; setAxisFriction(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, friction: number): void; getAxisFriction(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMode(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, limitMode: PhysicsConstraintAxisLimitMode): void; getAxisMode(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMinLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, minLimit: number): void; getAxisMinLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMaxLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, limit: number): void; getAxisMaxLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMotorType(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, motorType: PhysicsConstraintMotorType): void; getAxisMotorType(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMotorTarget(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, target: number): void; getAxisMotorTarget(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, maxForce: number): void; getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable; disposeConstraint(constraint: PhysicsConstraint): void; getBodiesUsingConstraint(constraint: PhysicsConstraint): ConstrainedBodyPair[]; raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult, query?: IRaycastQuery): void; /** * Dispose the world and free resources */ dispose(): void; }