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 { IRigidBodyImpl } from "./Impl/IRigidBodyImpl"; import type { PhysicsShape } from "./physicsShape"; import type { RigidBodyConstructionInfo } from "./rigidBodyConstructionInfo"; import type { RigidBodyConstructionInfoList } from "./rigidBodyConstructionInfoList"; /** * bullet physics rigid body */ export declare class RigidBody { /** * @internal */ readonly runtime: IPhysicsRuntime; private readonly _motionStatePtr; private _bufferedMotionStatePtr; private readonly _worldTransformPtr; private readonly _kinematicStatePtr; private readonly _inner; private _worldReference; /** * @internal */ impl: IRigidBodyImpl; /** * Whether this rigid body is dynamic or not(kinematic or static) */ readonly isDynamic: boolean; /** * Create a new rigid body with the given construction info * @param runtime The physics runtime * @param info The construction info for the rigid body */ constructor(runtime: IPhysicsRuntime, info: RigidBodyConstructionInfo); /** * Create a new rigid body with the given construction info list * @param runtime The physics runtime * @param info The construction info list for the rigid body * @param n The index of the construction info in the list */ constructor(runtime: IPhysicsRuntime, info: RigidBodyConstructionInfoList, n: number); /** * Dispose the rigid body * * rigid body must be removed from the world before disposing */ dispose(): void; /** * @internal */ get ptr(): 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 */ updateBufferedMotionState(forceUseFrontBuffer: boolean): void; private _nullCheck; /** * Get the transform matrix of the rigid body * @param result The matrix to store the result * @returns The transform matrix of the rigid body */ getTransformMatrixToRef(result: Matrix): Matrix; /** * Get the transform matrix of the rigid body * @param result The array to store the result * @param offset The offset in the array to store the result */ getTransformMatrixToArray(result: Float32Array, offset?: number): void; /** * Set the transform matrix of the rigid body * * 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 rigid body * @param matrix The transform matrix to set */ setTransformMatrix(matrix: Matrix): void; /** * Set the transform matrix of the rigid body * * 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 rigid body * @param array The array to set the transform matrix from * @param offset The offset in the array to set the transform matrix from */ setTransformMatrixFromArray(array: DeepImmutable>, offset?: number): void; /** * Set the dynamic transform matrix of the rigid body * * 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 rigid body * @param matrix The transform matrix to set * @param fallbackToSetTransformMatrix Whether to fallback to setTransformMatrix if the rigid body is not dynamic */ setDynamicTransformMatrix(matrix: Matrix, fallbackToSetTransformMatrix?: boolean): void; /** * Set the dynamic transform matrix of the rigid body * * 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 rigid body * @param array The array to set the transform matrix from * @param offset The offset in the array to set the transform matrix from * @param fallbackToSetTransformMatrix Whether to fallback to setTransformMatrix if the rigid body is not dynamic */ setDynamicTransformMatrixFromArray(array: DeepImmutable>, offset?: number, fallbackToSetTransformMatrix?: boolean): void; /** * The 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 rigid body */ get effectiveKinematicState(): boolean; set effectiveKinematicState(value: boolean); /** * Set the linear and angular damping of the rigid body * * Application can be deferred to the next frame when world evaluating the rigid body * @param linearDamping * @param angularDamping */ setDamping(linearDamping: number, angularDamping: number): void; /** * Get the linear damping of the rigid body * @returns The linear damping of the rigid body */ getLinearDamping(): number; /** * Get the angular damping of the rigid body * @returns The angular damping of the rigid body */ getAngularDamping(): number; /** * Set the mass and local inertia of the rigid body * * Application can be deferred to the next frame when world evaluating the rigid body * @param mass The mass of the rigid body * @param localInertia The local inertia of the rigid body */ setMassProps(mass: number, localInertia: DeepImmutable): void; /** * Get the mass of the rigid body * @returns The mass of the rigid body */ getMass(): number; /** * Get the local inertia of the rigid body * @returns The local inertia of the rigid body */ getLocalInertia(): Vector3; /** * Translate the rigid body * * Application can be deferred to the next frame when world evaluating the rigid body * @param translation The translation vector */ translate(translation: DeepImmutable): void; /** * @internal */ get needToCommit(): boolean; /** * @internal */ commitToWasm(): void; /** * Get the total force of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The total force of the rigid body */ getTotalForceToRef(result: Vector3): Vector3; /** * Get the total torque of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The total torque of the rigid body */ getTotalTorqueToRef(result: Vector3): Vector3; /** * Apply a central force to the rigid body * * This operation is always synchronized * @param force The force vector to apply */ applyCentralForce(force: DeepImmutable): void; /** * Apply a torque to the rigid body * * This operation is always synchronized * @param torque The torque vector to apply */ applyTorque(torque: DeepImmutable): void; /** * Apply a force to the rigid body * * This operation is always synchronized * @param force The force vector to apply * @param relativePosition The relative position vector to apply the force at */ applyForce(force: DeepImmutable, relativePosition: DeepImmutable): void; /** * Apply a central impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply */ applyCentralImpulse(impulse: DeepImmutable): void; /** * Apply a torque impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply */ applyTorqueImpulse(impulse: DeepImmutable): void; /** * Apply an impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply * @param relativePosition The relative position vector to apply the impulse at */ applyImpulse(impulse: DeepImmutable, relativePosition: DeepImmutable): void; /** * Apply a push impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply * @param relativePosition The relative position vector to apply the impulse at */ applyPushImpulse(impulse: DeepImmutable, relativePosition: DeepImmutable): void; /** * Get the push velocity of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The push velocity of the rigid body */ getPushVelocityToRef(result: Vector3): DeepImmutable; /** * Get the turn velocity of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The turn velocity of the rigid body */ getTurnVelocityToRef(result: Vector3): Vector3; /** * Set the push velocity of the rigid body * * This operation is always synchronized * @param velocity The velocity vector to set */ setPushVelocity(velocity: DeepImmutable): void; /** * Set the turn velocity of the rigid body * * This operation is always synchronized * @param velocity The velocity vector to set */ setTurnVelocity(velocity: DeepImmutable): void; /** * Apply a central push impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply */ applyCentralPushImpulse(impulse: DeepImmutable): void; /** * Apply a torque turn impulse to the rigid body * * This operation is always synchronized * @param impulse The impulse vector to apply */ applyTorqueTurnImpulse(impulse: DeepImmutable): void; /** * Clear the forces of the rigid body * * This operation is always synchronized */ clearForces(): void; /** * Get the linear velocity of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The linear velocity of the rigid body */ getLinearVelocityToRef(result: Vector3): Vector3; /** * Get the angular velocity of the rigid body * * This operation is always synchronized * @param result The vector to store the result * @returns The angular velocity of the rigid body */ getAngularVelocityToRef(result: Vector3): Vector3; /** * Set the linear velocity of the rigid body * * 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 velocity The linear velocity vector * @param shouldSynced Whether to synchronize the operation */ setLinearVelocity(velocity: DeepImmutable, shouldSynced: boolean): void; /** * Set the angular velocity of the rigid body * * 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 velocity The velocity vector to set * @param shouldSynced Whether to synchronize the operation */ setAngularVelocity(velocity: DeepImmutable, shouldSynced: boolean): void; /** * Get the velocity of the rigid body in local point * * This operation is always synchronized * @param relativePosition The relative position vector to get the velocity at * @param result The vector to store the result * @returns The velocity of the rigid body in local point */ getVelocityInLocalPointToRef(relativePosition: DeepImmutable, result: Vector3): Vector3; /** * Get the push velocity of the rigid body in local point * * This operation is always synchronized * @param relativePosition The relative position vector to get the push velocity at * @param result The vector to store the result * @returns The push velocity of the rigid body in local point */ getPushVelocityInLocalPointToRef(relativePosition: DeepImmutable, result: Vector3): Vector3; /** * Get shape of the rigid body * @returns The shape of the rigid body */ getShape(): PhysicsShape; /** * Set shape of the rigid body * * This operation is always synchronized * @param shape The shape to set */ setShape(shape: PhysicsShape): void; }