import type { Matrix, Vector3 } from "@babylonjs/core/Maths/math.vector"; import type { DeepImmutable, Nullable, Tuple } from "@babylonjs/core/types"; import type { IPhysicsRuntime } from "./Impl/IPhysicsRuntime"; import type { IRigidBodyBundleImpl } from "./Impl/IRigidBodyBundleImpl"; import type { PhysicsShape } from "./physicsShape"; import type { RigidBodyConstructionInfoList } from "./rigidBodyConstructionInfoList"; /** * bundle of bullet physics rigid bodies * * rigid body bundle is a collection of rigid bodies * that allocates all of its motion state data * in the one big linearly contiguous memory * * Bundle is useful for following cases: * - when you have a lot of rigid bodies * - when you want manage several rigid bodies as a group */ export declare class RigidBodyBundle { /** * @internal */ readonly runtime: IPhysicsRuntime; private readonly _motionStatesPtr; private _bufferedMotionStatesPtr; private readonly _worldTransformPtrArray; private readonly _kinematicStatesPtr; private readonly _inner; private readonly _count; private _worldReference; /** * @internal */ impl: IRigidBodyBundleImpl; /** * Whether this bundle contains dynamic rigid bodies */ readonly isContainsDynamic: boolean; /** * Create a new rigid body bundle * @param runtime The physics runtime * @param info The rigid body construction info list * @param countOverride The number of rigid bodies in the bundle */ constructor(runtime: IPhysicsRuntime, info: RigidBodyConstructionInfoList, countOverride?: number); /** * Dispose the rigid body bundle * * rigid body bundle must be removed from the world before disposing */ dispose(): void; /** * @internal */ get ptr(): number; /** * The number of rigid bodies in the bundle */ get count(): number; /** * @internal */ addReference(): void; /** * @internal */ removeReference(): void; /** * @internal */ addShadowReference(): void; /** * @internal */ removeShadowReference(): void; /** * @internal */ get hasShadows(): boolean; /** * @internal */ setWorldReference(worldReference: Nullable): void; /** * @internal */ getWorldReference(): Nullable; /** * @internal */ updateBufferedMotionStates(forceUseFrontBuffer: boolean): void; private _nullCheck; /** * Get the transform matrix of the rigid body at the given index * @param index Index of the rigid body * @param result The matrix to store the result * @returns The transform matrix of the rigid body */ getTransformMatrixToRef(index: number, result: Matrix): Matrix; /** * Get the transform matrix of the rigid body at the given index * @param index Index of the rigid body * @param result The matrix to store the result * @param offset The offset in the result matrix */ getTransformMatrixToArray(index: number, result: Float32Array, offset?: number): void; /** * Get the transform matrices of the rigid bodies in the bundle * @param result The array to store the result * @param offset The offset in the result array */ getTransformMatricesToArray(result: Float32Array, offset?: number): void; /** * Set the transform matrix of the rigid body at the given index * * This method will work only if the rigid body motion type is kinematic * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param matrix The transform matrix to set */ setTransformMatrix(index: number, matrix: Matrix): void; /** * Set the transform matrix of the rigid body at the given index * * This method will work only if the rigid body motion type is kinematic * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param array The array to set * @param offset The offset in the array */ setTransformMatrixFromArray(index: number, array: DeepImmutable>, offset?: number): void; /** * Set the transform matrices of the rigid bodies in the bundle * * This method will work only if the rigid body motion type is kinematic * * Application can be deferred to the next frame when world evaluating the bundle * @param array The array to set * @param offset The offset in the array */ setTransformMatricesFromArray(array: DeepImmutable>, offset?: number): void; /** * Set the dynamic transform matrix of the rigid body at the given index * * This method will work only if the rigid body motion type is dynamic * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param matrix The transform matrix to set * @param fallbackToSetTransformMatrix Whether to fallback to setTransformMatrix if the rigid body is not dynamic */ setDynamicTransformMatrix(index: number, matrix: Matrix, fallbackToSetTransformMatrix?: boolean): void; /** * Set the dynamic transform matrix of the rigid body at the given index * * This method will work only if the rigid body motion type is dynamic * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param array The array to set * @param offset The offset in the array * @param fallbackToSetTransformMatrix Whether to fallback to setTransformMatrix if the rigid body is not dynamic */ setDynamicTransformMatrixFromArray(index: number, array: DeepImmutable>, offset?: number, fallbackToSetTransformMatrix?: boolean): void; /** * Get effective kinematic state of the rigid body * * Even rigid body motion type is dynamic, * You can set effective kinematic state to true to make it kinematic * * @param index Index of the rigid body */ getEffectiveKinematicState(index: number): boolean; /** * Set effective kinematic state of the rigid body * * Even rigid body motion type is dynamic, * You can set effective kinematic state to true to make it kinematic * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param value The effective kinematic state to set */ setEffectiveKinematicState(index: number, value: boolean): void; /** * Set the linear and angular damping of the rigid body at the given index * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param linearDamping Linear damping * @param angularDamping Angular damping */ setDamping(index: number, linearDamping: number, angularDamping: number): void; /** * Get the linear damping of the rigid body at the given index * @param index Index of the rigid body * @return The linear damping of the rigid body */ getLinearDamping(index: number): number; /** * Get the angular damping of the rigid body at the given index * @param index Index of the rigid body * @return The angular damping of the rigid body */ getAngularDamping(index: number): number; /** * Set the mass and local inertia of the rigid body at the given index * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param mass Mass * @param localInertia Local inertia */ setMassProps(index: number, mass: number, localInertia: DeepImmutable): void; /** * Get the mass of the rigid body at the given index * @param index Index of the rigid body * @return The mass of the rigid body */ getMass(index: number): number; /** * Get the local inertia of the rigid body at the given index * @param index Index of the rigid body * @return The local inertia of the rigid body */ getLocalInertia(index: number): Vector3; /** * Translate the rigid body at the given index * * Application can be deferred to the next frame when world evaluating the bundle * @param index Index of the rigid body * @param translation The translation vector */ translate(index: number, translation: DeepImmutable): void; /** * @internal */ get needToCommit(): boolean; /** * @internal */ commitToWasm(): void; /** * Get the total force of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The total force of the rigid body */ getTotalForceToRef(index: number, result: Vector3): Vector3; /** * Get the total torque of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The total torque of the rigid body */ getTotalTorqueToRef(index: number, result: Vector3): Vector3; /** * Apply a central force to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param force The force vector */ applyCentralForce(index: number, force: DeepImmutable): void; /** * Apply a torque to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param torque The torque vector */ applyTorque(index: number, torque: DeepImmutable): void; /** * Apply a force to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param force The force vector * @param relativePosition The relative position vector */ applyForce(index: number, force: DeepImmutable, relativePosition: DeepImmutable): void; /** * Apply a push force to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector */ applyCentralImpulse(index: number, impulse: DeepImmutable): void; /** * Apply a torque impulse to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector */ applyTorqueImpulse(index: number, impulse: DeepImmutable): void; /** * Apply an impulse to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector * @param relativePosition The relative position vector */ applyImpulse(index: number, impulse: DeepImmutable, relativePosition: DeepImmutable): void; /** * Apply a push impulse to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector * @param relativePosition The relative position vector */ applyPushImpulse(index: number, impulse: DeepImmutable, relativePosition: DeepImmutable): void; /** * Get the push velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The push velocity of the rigid body */ getPushVelocityToRef(index: number, result: Vector3): DeepImmutable; /** * Get the turn velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The turn velocity of the rigid body */ getTurnVelocityToRef(index: number, result: Vector3): Vector3; /** * Set the push velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param velocity The push velocity vector */ setPushVelocity(index: number, velocity: DeepImmutable): void; /** * Set the turn velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param velocity The turn velocity vector */ setTurnVelocity(index: number, velocity: DeepImmutable): void; /** * Apply a central push impulse to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector */ applyCentralPushImpulse(index: number, impulse: DeepImmutable): void; /** * Apply a torque turn impulse to the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param impulse The impulse vector */ applyTorqueTurnImpulse(index: number, impulse: DeepImmutable): void; /** * Clear the forces of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body */ clearForces(index: number): void; /** * Get the linear velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The linear velocity of the rigid body */ getLinearVelocityToRef(index: number, result: Vector3): Vector3; /** * Get the angular velocity of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param result The vector to store the result * @returns The angular velocity of the rigid body */ getAngularVelocityToRef(index: number, result: Vector3): Vector3; /** * Set the linear velocity of the rigid body at the given index * * This operation is synchronized when `synced` is true. * * If `synced` is false, the operation will not wait for the lock and * will not be applied until the next frame when the world is evaluated. * @param index Index of the rigid body * @param velocity The linear velocity vector * @param shouldSynced Whether to synchronize the operation */ setLinearVelocity(index: number, velocity: DeepImmutable, shouldSynced: boolean): void; /** * Set the angular velocity of the rigid body at the given index * * This operation is synchronized when `synced` is true. * * If `synced` isd false, the operation will not wait for the lock and * will not be applied until the next frame when the world is evaluate. * @param index Index of the rigid body * @param velocity The angular velocity vector * @param shouldSynced Whether to synchronize the operation */ setAngularVelocity(index: number, velocity: DeepImmutable, shouldSynced: boolean): void; /** * Get the velocity of the rigid body at the given index in the local point * * This operation is always synchronized * @param index Index of the rigid body * @param relativePosition The relative position vector * @param result The vector to store the result * @returns The velocity of the rigid body at the given index in the local point */ getVelocityInLocalPointToRef(index: number, relativePosition: DeepImmutable, result: Vector3): Vector3; /** * Get the push velocity of the rigid body at the given index in the local point * * This operation is always synchronized * @param index Index of the rigid body * @param relativePosition The relative position vector * @param result The vector to store the result * @returns The push velocity of the rigid body at the given index in the local point */ getPushVelocityInLocalPointToRef(index: number, relativePosition: DeepImmutable, result: Vector3): Vector3; /** * Get the shape of the rigid body at the given index * @param index Index of the rigid body * @returns The shape of the rigid body */ getShape(index: number): PhysicsShape; /** * Set the shape of the rigid body at the given index * * This operation is always synchronized * @param index Index of the rigid body * @param shape The shape to set */ setShape(index: number, shape: PhysicsShape): void; }