main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { RawCCDSolver } from "../raw";
/**
* The CCD solver responsible for resolving Continuous Collision Detection.
*
* To avoid leaking WASM resources, this MUST be freed manually with `ccdSolver.free()`
* once you are done using it.
*/
export declare class CCDSolver {
raw: RawCCDSolver;
/**
* Release the WASM memory occupied by this narrow-phase.
*/
free(): void;
constructor(raw?: RawCCDSolver);
}

View File

@@ -0,0 +1,13 @@
/**
* A rule applied to combine coefficients.
*
* Use this when configuring the `ColliderDesc` to specify
* how friction and restitution coefficient should be combined
* in a contact.
*/
export declare enum CoefficientCombineRule {
Average = 0,
Min = 1,
Multiply = 2,
Max = 3
}

View File

@@ -0,0 +1,259 @@
import { Rotation, Vector } from "../math";
import { RawGenericJoint, RawImpulseJointSet, RawJointAxis } from "../raw";
import { RigidBody } from "./rigid_body";
import { RigidBodySet } from "./rigid_body_set";
/**
* The integer identifier of a collider added to a `ColliderSet`.
*/
export declare type ImpulseJointHandle = number;
/**
* An enum grouping all possible types of joints:
*
* - `Revolute`: A revolute joint that removes all degrees of freedom between the affected
* bodies except for the rotation along one axis.
* - `Fixed`: A fixed joint that removes all relative degrees of freedom between the affected bodies.
* - `Prismatic`: A prismatic joint that removes all degrees of freedom between the affected
* bodies except for the translation along one axis.
* - `Spherical`: (3D only) A spherical joint that removes all relative linear degrees of freedom between the affected bodies.
* - `Generic`: (3D only) A joint with customizable degrees of freedom, allowing any of the 6 axes to be locked.
*/
export declare enum JointType {
Revolute = 0,
Fixed = 1,
Prismatic = 2,
Rope = 3,
Spring = 4,
Spherical = 5,
Generic = 6
}
export declare enum MotorModel {
AccelerationBased = 0,
ForceBased = 1
}
/**
* An enum representing the possible joint axes of a generic joint.
* They can be ORed together, like:
* JointAxesMask.X || JointAxesMask.Y
* to get a joint that is only free in the X and Y translational (positional) axes.
*
* Possible free axes are:
*
* - `X`: X translation axis
* - `Y`: Y translation axis
* - `Z`: Z translation axis
* - `AngX`: X angular rotation axis
* - `AngY`: Y angular rotations axis
* - `AngZ`: Z angular rotation axis
*/
export declare enum JointAxesMask {
X = 1,
Y = 2,
Z = 4,
AngX = 8,
AngY = 16,
AngZ = 32
}
export declare class ImpulseJoint {
protected rawSet: RawImpulseJointSet;
protected bodySet: RigidBodySet;
handle: ImpulseJointHandle;
constructor(rawSet: RawImpulseJointSet, bodySet: RigidBodySet, handle: ImpulseJointHandle);
static newTyped(rawSet: RawImpulseJointSet, bodySet: RigidBodySet, handle: ImpulseJointHandle): ImpulseJoint;
/** @internal */
finalizeDeserialization(bodySet: RigidBodySet): void;
/**
* Checks if this joint is still valid (i.e. that it has
* not been deleted from the joint set yet).
*/
isValid(): boolean;
/**
* The first rigid-body this joint it attached to.
*/
body1(): RigidBody;
/**
* The second rigid-body this joint is attached to.
*/
body2(): RigidBody;
/**
* The type of this joint given as a string.
*/
type(): JointType;
/**
* The rotation quaternion that aligns this joint's first local axis to the `x` axis.
*/
frameX1(): Rotation;
/**
* The rotation matrix that aligns this joint's second local axis to the `x` axis.
*/
frameX2(): Rotation;
/**
* The position of the first anchor of this joint.
*
* The first anchor gives the position of the application point on the
* local frame of the first rigid-body it is attached to.
*/
anchor1(): Vector;
/**
* The position of the second anchor of this joint.
*
* The second anchor gives the position of the application point on the
* local frame of the second rigid-body it is attached to.
*/
anchor2(): Vector;
/**
* Sets the position of the first anchor of this joint.
*
* The first anchor gives the position of the application point on the
* local frame of the first rigid-body it is attached to.
*/
setAnchor1(newPos: Vector): void;
/**
* Sets the position of the second anchor of this joint.
*
* The second anchor gives the position of the application point on the
* local frame of the second rigid-body it is attached to.
*/
setAnchor2(newPos: Vector): void;
/**
* Controls whether contacts are computed between colliders attached
* to the rigid-bodies linked by this joint.
*/
setContactsEnabled(enabled: boolean): void;
/**
* Indicates if contacts are enabled between colliders attached
* to the rigid-bodies linked by this joint.
*/
contactsEnabled(): boolean;
}
export declare class UnitImpulseJoint extends ImpulseJoint {
/**
* The axis left free by this joint.
*/
protected rawAxis?(): RawJointAxis;
/**
* Are the limits enabled for this joint?
*/
limitsEnabled(): boolean;
/**
* The min limit of this joint.
*/
limitsMin(): number;
/**
* The max limit of this joint.
*/
limitsMax(): number;
/**
* Sets the limits of this joint.
*
* @param min - The minimum bound of this joints free coordinate.
* @param max - The maximum bound of this joints free coordinate.
*/
setLimits(min: number, max: number): void;
configureMotorModel(model: MotorModel): void;
configureMotorVelocity(targetVel: number, factor: number): void;
configureMotorPosition(targetPos: number, stiffness: number, damping: number): void;
configureMotor(targetPos: number, targetVel: number, stiffness: number, damping: number): void;
}
export declare class FixedImpulseJoint extends ImpulseJoint {
}
export declare class RopeImpulseJoint extends ImpulseJoint {
}
export declare class SpringImpulseJoint extends ImpulseJoint {
}
export declare class PrismaticImpulseJoint extends UnitImpulseJoint {
rawAxis(): RawJointAxis;
}
export declare class RevoluteImpulseJoint extends UnitImpulseJoint {
rawAxis(): RawJointAxis;
}
export declare class GenericImpulseJoint extends ImpulseJoint {
}
export declare class SphericalImpulseJoint extends ImpulseJoint {
}
export declare class JointData {
anchor1: Vector;
anchor2: Vector;
axis: Vector;
frame1: Rotation;
frame2: Rotation;
jointType: JointType;
limitsEnabled: boolean;
limits: Array<number>;
axesMask: JointAxesMask;
stiffness: number;
damping: number;
length: number;
private constructor();
/**
* Creates a new joint descriptor that builds a Fixed joint.
*
* A fixed joint removes all the degrees of freedom between the affected bodies, ensuring their
* anchor and local frames coincide in world-space.
*
* @param anchor1 - Point where the joint is attached on the first rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param frame1 - The reference orientation of the joint wrt. the first rigid-body.
* @param anchor2 - Point where the joint is attached on the second rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param frame2 - The reference orientation of the joint wrt. the second rigid-body.
*/
static fixed(anchor1: Vector, frame1: Rotation, anchor2: Vector, frame2: Rotation): JointData;
static spring(rest_length: number, stiffness: number, damping: number, anchor1: Vector, anchor2: Vector): JointData;
static rope(length: number, anchor1: Vector, anchor2: Vector): JointData;
/**
* Create a new joint descriptor that builds generic joints.
*
* A generic joint allows customizing its degrees of freedom
* by supplying a mask of the joint axes that should remain locked.
*
* @param anchor1 - Point where the joint is attached on the first rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param anchor2 - Point where the joint is attached on the second rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param axis - The X axis of the joint, expressed in the local-space of the rigid-bodies it is attached to.
* @param axesMask - Mask representing the locked axes of the joint. You can use logical OR to select these from
* the JointAxesMask enum. For example, passing (JointAxesMask.AngX || JointAxesMask.AngY) will
* create a joint locked in the X and Y rotational axes.
*/
static generic(anchor1: Vector, anchor2: Vector, axis: Vector, axesMask: JointAxesMask): JointData;
/**
* Create a new joint descriptor that builds spherical joints.
*
* A spherical joint allows three relative rotational degrees of freedom
* by preventing any relative translation between the anchors of the
* two attached rigid-bodies.
*
* @param anchor1 - Point where the joint is attached on the first rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param anchor2 - Point where the joint is attached on the second rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
*/
static spherical(anchor1: Vector, anchor2: Vector): JointData;
/**
* Creates a new joint descriptor that builds a Prismatic joint.
*
* A prismatic joint removes all the degrees of freedom between the
* affected bodies, except for the translation along one axis.
*
* @param anchor1 - Point where the joint is attached on the first rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param anchor2 - Point where the joint is attached on the second rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param axis - Axis of the joint, expressed in the local-space of the rigid-bodies it is attached to.
*/
static prismatic(anchor1: Vector, anchor2: Vector, axis: Vector): JointData;
/**
* Create a new joint descriptor that builds Revolute joints.
*
* A revolute joint removes all degrees of freedom between the affected
* bodies except for the rotation along one axis.
*
* @param anchor1 - Point where the joint is attached on the first rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param anchor2 - Point where the joint is attached on the second rigid-body affected by this joint. Expressed in the
* local-space of the rigid-body.
* @param axis - Axis of the joint, expressed in the local-space of the rigid-bodies it is attached to.
*/
static revolute(anchor1: Vector, anchor2: Vector, axis: Vector): JointData;
intoRaw(): RawGenericJoint;
}

View File

@@ -0,0 +1,79 @@
import { RawImpulseJointSet } from "../raw";
import { RigidBodySet } from "./rigid_body_set";
import { ImpulseJoint, ImpulseJointHandle, JointData } from "./impulse_joint";
import { RigidBodyHandle } from "./rigid_body";
/**
* A set of joints.
*
* To avoid leaking WASM resources, this MUST be freed manually with `jointSet.free()`
* once you are done using it (and all the joints it created).
*/
export declare class ImpulseJointSet {
raw: RawImpulseJointSet;
private map;
/**
* Release the WASM memory occupied by this joint set.
*/
free(): void;
constructor(raw?: RawImpulseJointSet);
/** @internal */
finalizeDeserialization(bodies: RigidBodySet): void;
/**
* Creates a new joint and return its integer handle.
*
* @param bodies - The set of rigid-bodies containing the bodies the joint is attached to.
* @param desc - The joint's parameters.
* @param parent1 - The handle of the first rigid-body this joint is attached to.
* @param parent2 - The handle of the second rigid-body this joint is attached to.
* @param wakeUp - Should the attached rigid-bodies be awakened?
*/
createJoint(bodies: RigidBodySet, desc: JointData, parent1: RigidBodyHandle, parent2: RigidBodyHandle, wakeUp: boolean): ImpulseJoint;
/**
* Remove a joint from this set.
*
* @param handle - The integer handle of the joint.
* @param wakeUp - If `true`, the rigid-bodies attached by the removed joint will be woken-up automatically.
*/
remove(handle: ImpulseJointHandle, wakeUp: boolean): void;
/**
* Calls the given closure with the integer handle of each impulse joint attached to this rigid-body.
*
* @param f - The closure called with the integer handle of each impulse joint attached to the rigid-body.
*/
forEachJointHandleAttachedToRigidBody(handle: RigidBodyHandle, f: (handle: ImpulseJointHandle) => void): void;
/**
* Internal function, do not call directly.
* @param handle
*/
unmap(handle: ImpulseJointHandle): void;
/**
* The number of joints on this set.
*/
len(): number;
/**
* Does this set contain a joint with the given handle?
*
* @param handle - The joint handle to check.
*/
contains(handle: ImpulseJointHandle): boolean;
/**
* Gets the joint with the given handle.
*
* Returns `null` if no joint with the specified handle exists.
*
* @param handle - The integer handle of the joint to retrieve.
*/
get(handle: ImpulseJointHandle): ImpulseJoint | null;
/**
* Applies the given closure to each joint contained by this set.
*
* @param f - The closure to apply.
*/
forEach(f: (joint: ImpulseJoint) => void): void;
/**
* Gets all joints in the list.
*
* @returns joint list.
*/
getAll(): ImpulseJoint[];
}

View File

@@ -0,0 +1,10 @@
export * from "./rigid_body";
export * from "./rigid_body_set";
export * from "./integration_parameters";
export * from "./impulse_joint";
export * from "./impulse_joint_set";
export * from "./multibody_joint";
export * from "./multibody_joint_set";
export * from "./coefficient_combine_rule";
export * from "./ccd_solver";
export * from "./island_manager";

View File

@@ -0,0 +1,66 @@
import { RawIntegrationParameters } from "../raw";
export declare class IntegrationParameters {
raw: RawIntegrationParameters;
constructor(raw?: RawIntegrationParameters);
/**
* Free the WASM memory used by these integration parameters.
*/
free(): void;
/**
* The timestep length (default: `1.0 / 60.0`)
*/
get dt(): number;
/**
* The Error Reduction Parameter in `[0, 1]` is the proportion of
* the positional error to be corrected at each time step (default: `0.2`).
*/
get erp(): number;
/**
* Amount of penetration the engine wont attempt to correct (default: `0.001m`).
*/
get allowedLinearError(): number;
/**
* The maximal distance separating two objects that will generate predictive contacts (default: `0.002`).
*/
get predictionDistance(): number;
/**
* The number of solver iterations run by the constraints solver for calculating forces (default: `4`).
*/
get numSolverIterations(): number;
/**
* Number of addition friction resolution iteration run during the last solver sub-step (default: `4`).
*/
get numAdditionalFrictionIterations(): number;
/**
* Number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`).
*/
get numInternalPgsIterations(): number;
/**
* Minimum number of dynamic bodies in each active island (default: `128`).
*/
get minIslandSize(): number;
/**
* Maximum number of substeps performed by the solver (default: `1`).
*/
get maxCcdSubsteps(): number;
set dt(value: number);
set erp(value: number);
set allowedLinearError(value: number);
set predictionDistance(value: number);
/**
* Sets the number of solver iterations run by the constraints solver for calculating forces (default: `4`).
*/
set numSolverIterations(value: number);
/**
* Sets the number of addition friction resolution iteration run during the last solver sub-step (default: `4`).
*/
set numAdditionalFrictionIterations(value: number);
/**
* Sets the number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`).
*/
set numInternalPgsIterations(value: number);
set minIslandSize(value: number);
set maxCcdSubsteps(value: number);
switchToStandardPgsSolver(): void;
switchToSmallStepsPgsSolver(): void;
}

View File

@@ -0,0 +1,24 @@
import { RawIslandManager } from "../raw";
import { RigidBodyHandle } from "./rigid_body";
/**
* The CCD solver responsible for resolving Continuous Collision Detection.
*
* To avoid leaking WASM resources, this MUST be freed manually with `ccdSolver.free()`
* once you are done using it.
*/
export declare class IslandManager {
raw: RawIslandManager;
/**
* Release the WASM memory occupied by this narrow-phase.
*/
free(): void;
constructor(raw?: RawIslandManager);
/**
* Applies the given closure to the handle of each active rigid-bodies contained by this set.
*
* A rigid-body is active if it is not sleeping, i.e., if it moved recently.
*
* @param f - The closure to apply.
*/
forEachActiveRigidBodyHandle(f: (handle: RigidBodyHandle) => void): void;
}

View File

@@ -0,0 +1,42 @@
import { RawJointAxis, RawMultibodyJointSet } from "../raw";
/**
* The integer identifier of a collider added to a `ColliderSet`.
*/
export declare type MultibodyJointHandle = number;
export declare class MultibodyJoint {
protected rawSet: RawMultibodyJointSet;
handle: MultibodyJointHandle;
constructor(rawSet: RawMultibodyJointSet, handle: MultibodyJointHandle);
static newTyped(rawSet: RawMultibodyJointSet, handle: MultibodyJointHandle): MultibodyJoint;
/**
* Checks if this joint is still valid (i.e. that it has
* not been deleted from the joint set yet).
*/
isValid(): boolean;
/**
* Controls whether contacts are computed between colliders attached
* to the rigid-bodies linked by this joint.
*/
setContactsEnabled(enabled: boolean): void;
/**
* Indicates if contacts are enabled between colliders attached
* to the rigid-bodies linked by this joint.
*/
contactsEnabled(): boolean;
}
export declare class UnitMultibodyJoint extends MultibodyJoint {
/**
* The axis left free by this joint.
*/
protected rawAxis?(): RawJointAxis;
}
export declare class FixedMultibodyJoint extends MultibodyJoint {
}
export declare class PrismaticMultibodyJoint extends UnitMultibodyJoint {
rawAxis(): RawJointAxis;
}
export declare class RevoluteMultibodyJoint extends UnitMultibodyJoint {
rawAxis(): RawJointAxis;
}
export declare class SphericalMultibodyJoint extends MultibodyJoint {
}

View File

@@ -0,0 +1,76 @@
import { RawMultibodyJointSet } from "../raw";
import { MultibodyJoint, MultibodyJointHandle } from "./multibody_joint";
import { JointData } from "./impulse_joint";
import { RigidBodyHandle } from "./rigid_body";
/**
* A set of joints.
*
* To avoid leaking WASM resources, this MUST be freed manually with `jointSet.free()`
* once you are done using it (and all the joints it created).
*/
export declare class MultibodyJointSet {
raw: RawMultibodyJointSet;
private map;
/**
* Release the WASM memory occupied by this joint set.
*/
free(): void;
constructor(raw?: RawMultibodyJointSet);
/**
* Creates a new joint and return its integer handle.
*
* @param desc - The joint's parameters.
* @param parent1 - The handle of the first rigid-body this joint is attached to.
* @param parent2 - The handle of the second rigid-body this joint is attached to.
* @param wakeUp - Should the attached rigid-bodies be awakened?
*/
createJoint(desc: JointData, parent1: RigidBodyHandle, parent2: RigidBodyHandle, wakeUp: boolean): MultibodyJoint;
/**
* Remove a joint from this set.
*
* @param handle - The integer handle of the joint.
* @param wake_up - If `true`, the rigid-bodies attached by the removed joint will be woken-up automatically.
*/
remove(handle: MultibodyJointHandle, wake_up: boolean): void;
/**
* Internal function, do not call directly.
* @param handle
*/
unmap(handle: MultibodyJointHandle): void;
/**
* The number of joints on this set.
*/
len(): number;
/**
* Does this set contain a joint with the given handle?
*
* @param handle - The joint handle to check.
*/
contains(handle: MultibodyJointHandle): boolean;
/**
* Gets the joint with the given handle.
*
* Returns `null` if no joint with the specified handle exists.
*
* @param handle - The integer handle of the joint to retrieve.
*/
get(handle: MultibodyJointHandle): MultibodyJoint | null;
/**
* Applies the given closure to each joint contained by this set.
*
* @param f - The closure to apply.
*/
forEach(f: (joint: MultibodyJoint) => void): void;
/**
* Calls the given closure with the integer handle of each multibody joint attached to this rigid-body.
*
* @param f - The closure called with the integer handle of each multibody joint attached to the rigid-body.
*/
forEachJointHandleAttachedToRigidBody(handle: RigidBodyHandle, f: (handle: MultibodyJointHandle) => void): void;
/**
* Gets all joints in the list.
*
* @returns joint list.
*/
getAll(): MultibodyJoint[];
}

View File

@@ -0,0 +1,710 @@
import { RawRigidBodySet } from "../raw";
import { Rotation, Vector } from "../math";
import { SdpMatrix3 } from "../math";
import { Collider, ColliderSet } from "../geometry";
/**
* The integer identifier of a collider added to a `ColliderSet`.
*/
export declare type RigidBodyHandle = number;
/**
* The simulation status of a rigid-body.
*/
export declare enum RigidBodyType {
/**
* A `RigidBodyType::Dynamic` body can be affected by all external forces.
*/
Dynamic = 0,
/**
* A `RigidBodyType::Fixed` body cannot be affected by external forces.
*/
Fixed = 1,
/**
* A `RigidBodyType::KinematicPositionBased` body cannot be affected by any external forces but can be controlled
* by the user at the position level while keeping realistic one-way interaction with dynamic bodies.
*
* One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
* cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
* modified by the user and is independent from any contact or joint it is involved in.
*/
KinematicPositionBased = 2,
/**
* A `RigidBodyType::KinematicVelocityBased` body cannot be affected by any external forces but can be controlled
* by the user at the velocity level while keeping realistic one-way interaction with dynamic bodies.
*
* One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
* cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
* modified by the user and is independent from any contact or joint it is involved in.
*/
KinematicVelocityBased = 3
}
/**
* A rigid-body.
*/
export declare class RigidBody {
private rawSet;
private colliderSet;
readonly handle: RigidBodyHandle;
/**
* An arbitrary user-defined object associated with this rigid-body.
*/
userData?: unknown;
constructor(rawSet: RawRigidBodySet, colliderSet: ColliderSet, handle: RigidBodyHandle);
/** @internal */
finalizeDeserialization(colliderSet: ColliderSet): void;
/**
* Checks if this rigid-body is still valid (i.e. that it has
* not been deleted from the rigid-body set yet.
*/
isValid(): boolean;
/**
* Locks or unlocks the ability of this rigid-body to translate.
*
* @param locked - If `true`, this rigid-body will no longer translate due to forces and impulses.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
*/
lockTranslations(locked: boolean, wakeUp: boolean): void;
/**
* Locks or unlocks the ability of this rigid-body to rotate.
*
* @param locked - If `true`, this rigid-body will no longer rotate due to torques and impulses.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
*/
lockRotations(locked: boolean, wakeUp: boolean): void;
/**
* Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
*
* @param enableX - If `false`, this rigid-body will no longer translate due to torques and impulses, along the X coordinate axis.
* @param enableY - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Y coordinate axis.
* @param enableZ - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Z coordinate axis.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
*/
setEnabledTranslations(enableX: boolean, enableY: boolean, enableZ: boolean, wakeUp: boolean): void;
/**
* Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
*
* @param enableX - If `false`, this rigid-body will no longer translate due to torques and impulses, along the X coordinate axis.
* @param enableY - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Y coordinate axis.
* @param enableZ - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Z coordinate axis.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
* @deprecated use `this.setEnabledTranslations` with the same arguments instead.
*/
restrictTranslations(enableX: boolean, enableY: boolean, enableZ: boolean, wakeUp: boolean): void;
/**
* Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
*
* @param enableX - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the X coordinate axis.
* @param enableY - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Y coordinate axis.
* @param enableZ - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Z coordinate axis.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
*/
setEnabledRotations(enableX: boolean, enableY: boolean, enableZ: boolean, wakeUp: boolean): void;
/**
* Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
*
* @param enableX - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the X coordinate axis.
* @param enableY - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Y coordinate axis.
* @param enableZ - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Z coordinate axis.
* @param wakeUp - If `true`, this rigid-body will be automatically awaken if it is currently asleep.
* @deprecated use `this.setEnabledRotations` with the same arguments instead.
*/
restrictRotations(enableX: boolean, enableY: boolean, enableZ: boolean, wakeUp: boolean): void;
/**
* The dominance group, in [-127, +127] this rigid-body is part of.
*/
dominanceGroup(): number;
/**
* Sets the dominance group of this rigid-body.
*
* @param group - The dominance group of this rigid-body. Must be a signed integer in the range [-127, +127].
*/
setDominanceGroup(group: number): void;
/**
* The number of additional solver iterations that will be run for this
* rigid-body and everything that interacts with it directly or indirectly
* through contacts or joints.
*/
additionalSolverIterations(): number;
/**
* Sets the number of additional solver iterations that will be run for this
* rigid-body and everything that interacts with it directly or indirectly
* through contacts or joints.
*
* Compared to increasing the global `World.numSolverIteration`, setting this
* value lets you increase accuracy on only a subset of the scene, resulting in reduced
* performance loss.
*
* @param iters - The new number of additional solver iterations (default: 0).
*/
setAdditionalSolverIterations(iters: number): void;
/**
* Enable or disable CCD (Continuous Collision Detection) for this rigid-body.
*
* @param enabled - If `true`, CCD will be enabled for this rigid-body.
*/
enableCcd(enabled: boolean): void;
/**
* The world-space translation of this rigid-body.
*/
translation(): Vector;
/**
* The world-space orientation of this rigid-body.
*/
rotation(): Rotation;
/**
* The world-space next translation of this rigid-body.
*
* If this rigid-body is kinematic this value is set by the `setNextKinematicTranslation`
* method and is used for estimating the kinematic body velocity at the next timestep.
* For non-kinematic bodies, this value is currently unspecified.
*/
nextTranslation(): Vector;
/**
* The world-space next orientation of this rigid-body.
*
* If this rigid-body is kinematic this value is set by the `setNextKinematicRotation`
* method and is used for estimating the kinematic body velocity at the next timestep.
* For non-kinematic bodies, this value is currently unspecified.
*/
nextRotation(): Rotation;
/**
* Sets the translation of this rigid-body.
*
* @param tra - The world-space position of the rigid-body.
* @param wakeUp - Forces the rigid-body to wake-up so it is properly affected by forces if it
* wasn't moving before modifying its position.
*/
setTranslation(tra: Vector, wakeUp: boolean): void;
/**
* Sets the linear velocity of this rigid-body.
*
* @param vel - The linear velocity to set.
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
*/
setLinvel(vel: Vector, wakeUp: boolean): void;
/**
* The scale factor applied to the gravity affecting
* this rigid-body.
*/
gravityScale(): number;
/**
* Sets the scale factor applied to the gravity affecting
* this rigid-body.
*
* @param factor - The scale factor to set. A value of 0.0 means
* that this rigid-body will on longer be affected by gravity.
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
*/
setGravityScale(factor: number, wakeUp: boolean): void;
/**
* Sets the rotation quaternion of this rigid-body.
*
* This does nothing if a zero quaternion is provided.
*
* @param rotation - The rotation to set.
* @param wakeUp - Forces the rigid-body to wake-up so it is properly affected by forces if it
* wasn't moving before modifying its position.
*/
setRotation(rot: Rotation, wakeUp: boolean): void;
/**
* Sets the angular velocity fo this rigid-body.
*
* @param vel - The angular velocity to set.
* @param wakeUp - Forces the rigid-body to wake-up if it was asleep.
*/
setAngvel(vel: Vector, wakeUp: boolean): void;
/**
* If this rigid body is kinematic, sets its future translation after the next timestep integration.
*
* This should be used instead of `rigidBody.setTranslation` to make the dynamic object
* interacting with this kinematic body behave as expected. Internally, Rapier will compute
* an artificial velocity for this rigid-body from its current position and its next kinematic
* position. This velocity will be used to compute forces on dynamic bodies interacting with
* this body.
*
* @param t - The kinematic translation to set.
*/
setNextKinematicTranslation(t: Vector): void;
/**
* If this rigid body is kinematic, sets its future rotation after the next timestep integration.
*
* This should be used instead of `rigidBody.setRotation` to make the dynamic object
* interacting with this kinematic body behave as expected. Internally, Rapier will compute
* an artificial velocity for this rigid-body from its current position and its next kinematic
* position. This velocity will be used to compute forces on dynamic bodies interacting with
* this body.
*
* @param rot - The kinematic rotation to set.
*/
setNextKinematicRotation(rot: Rotation): void;
/**
* The linear velocity of this rigid-body.
*/
linvel(): Vector;
/**
* The angular velocity of this rigid-body.
*/
angvel(): Vector;
/**
* The mass of this rigid-body.
*/
mass(): number;
/**
* The inverse mass taking into account translation locking.
*/
effectiveInvMass(): Vector;
/**
* The inverse of the mass of a rigid-body.
*
* If this is zero, the rigid-body is assumed to have infinite mass.
*/
invMass(): number;
/**
* The center of mass of a rigid-body expressed in its local-space.
*/
localCom(): Vector;
/**
* The world-space center of mass of the rigid-body.
*/
worldCom(): Vector;
/**
* The inverse of the principal angular inertia of the rigid-body.
*
* Components set to zero are assumed to be infinite along the corresponding principal axis.
*/
invPrincipalInertiaSqrt(): Vector;
/**
* The angular inertia along the principal inertia axes of the rigid-body.
*/
principalInertia(): Vector;
/**
* The principal vectors of the local angular inertia tensor of the rigid-body.
*/
principalInertiaLocalFrame(): Rotation;
/**
* The square-root of the world-space inverse angular inertia tensor of the rigid-body,
* taking into account rotation locking.
*/
effectiveWorldInvInertiaSqrt(): SdpMatrix3;
/**
* The effective world-space angular inertia (that takes the potential rotation locking into account) of
* this rigid-body.
*/
effectiveAngularInertia(): SdpMatrix3;
/**
* Put this rigid body to sleep.
*
* A sleeping body no longer moves and is no longer simulated by the physics engine unless
* it is waken up. It can be woken manually with `this.wakeUp()` or automatically due to
* external forces like contacts.
*/
sleep(): void;
/**
* Wakes this rigid-body up.
*
* A dynamic rigid-body that does not move during several consecutive frames will
* be put to sleep by the physics engine, i.e., it will stop being simulated in order
* to avoid useless computations.
* This methods forces a sleeping rigid-body to wake-up. This is useful, e.g., before modifying
* the position of a dynamic body so that it is properly simulated afterwards.
*/
wakeUp(): void;
/**
* Is CCD enabled for this rigid-body?
*/
isCcdEnabled(): boolean;
/**
* The number of colliders attached to this rigid-body.
*/
numColliders(): number;
/**
* Retrieves the `i-th` collider attached to this rigid-body.
*
* @param i - The index of the collider to retrieve. Must be a number in `[0, this.numColliders()[`.
* This index is **not** the same as the unique identifier of the collider.
*/
collider(i: number): Collider;
/**
* Sets whether this rigid-body is enabled or not.
*
* @param enabled - Set to `false` to disable this rigid-body and all its attached colliders.
*/
setEnabled(enabled: boolean): void;
/**
* Is this rigid-body enabled?
*/
isEnabled(): boolean;
/**
* The status of this rigid-body: static, dynamic, or kinematic.
*/
bodyType(): RigidBodyType;
/**
* Set a new status for this rigid-body: static, dynamic, or kinematic.
*/
setBodyType(type: RigidBodyType, wakeUp: boolean): void;
/**
* Is this rigid-body sleeping?
*/
isSleeping(): boolean;
/**
* Is the velocity of this rigid-body not zero?
*/
isMoving(): boolean;
/**
* Is this rigid-body static?
*/
isFixed(): boolean;
/**
* Is this rigid-body kinematic?
*/
isKinematic(): boolean;
/**
* Is this rigid-body dynamic?
*/
isDynamic(): boolean;
/**
* The linear damping coefficient of this rigid-body.
*/
linearDamping(): number;
/**
* The angular damping coefficient of this rigid-body.
*/
angularDamping(): number;
/**
* Sets the linear damping factor applied to this rigid-body.
*
* @param factor - The damping factor to set.
*/
setLinearDamping(factor: number): void;
/**
* Recompute the mass-properties of this rigid-bodies based on its currently attached colliders.
*/
recomputeMassPropertiesFromColliders(): void;
/**
* Sets the rigid-body's additional mass.
*
* The total angular inertia of the rigid-body will be scaled automatically based on this additional mass. If this
* scaling effect isnt desired, use Self::additional_mass_properties instead of this method.
*
* This is only the "additional" mass because the total mass of the rigid-body is equal to the sum of this
* additional mass and the mass computed from the colliders (with non-zero densities) attached to this rigid-body.
*
* That total mass (which includes the attached colliders contributions) will be updated at the name physics step,
* or can be updated manually with `this.recomputeMassPropertiesFromColliders`.
*
* This will override any previous additional mass-properties set by `this.setAdditionalMass`,
* `this.setAdditionalMassProperties`, `RigidBodyDesc::setAdditionalMass`, or
* `RigidBodyDesc.setAdditionalMassfProperties` for this rigid-body.
*
* @param mass - The additional mass to set.
* @param wakeUp - If `true` then the rigid-body will be woken up if it was put to sleep because it did not move for a while.
*/
setAdditionalMass(mass: number, wakeUp: boolean): void;
/**
* Sets the rigid-body's additional mass-properties.
*
* This is only the "additional" mass-properties because the total mass-properties of the rigid-body is equal to the
* sum of this additional mass-properties and the mass computed from the colliders (with non-zero densities) attached
* to this rigid-body.
*
* That total mass-properties (which include the attached colliders contributions) will be updated at the name
* physics step, or can be updated manually with `this.recomputeMassPropertiesFromColliders`.
*
* This will override any previous mass-properties set by `this.setAdditionalMass`,
* `this.setAdditionalMassProperties`, `RigidBodyDesc.setAdditionalMass`, or `RigidBodyDesc.setAdditionalMassProperties`
* for this rigid-body.
*
* If `wake_up` is true then the rigid-body will be woken up if it was put to sleep because it did not move for a while.
*/
setAdditionalMassProperties(mass: number, centerOfMass: Vector, principalAngularInertia: Vector, angularInertiaLocalFrame: Rotation, wakeUp: boolean): void;
/**
* Sets the linear damping factor applied to this rigid-body.
*
* @param factor - The damping factor to set.
*/
setAngularDamping(factor: number): void;
/**
* Resets to zero the user forces (but not torques) applied to this rigid-body.
*
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
resetForces(wakeUp: boolean): void;
/**
* Resets to zero the user torques applied to this rigid-body.
*
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
resetTorques(wakeUp: boolean): void;
/**
* Adds a force at the center-of-mass of this rigid-body.
*
* @param force - the world-space force to add to the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
addForce(force: Vector, wakeUp: boolean): void;
/**
* Applies an impulse at the center-of-mass of this rigid-body.
*
* @param impulse - the world-space impulse to apply on the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
applyImpulse(impulse: Vector, wakeUp: boolean): void;
/**
* Adds a torque at the center-of-mass of this rigid-body.
*
* @param torque - the world-space torque to add to the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
addTorque(torque: Vector, wakeUp: boolean): void;
/**
* Applies an impulsive torque at the center-of-mass of this rigid-body.
*
* @param torqueImpulse - the world-space torque impulse to apply on the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
applyTorqueImpulse(torqueImpulse: Vector, wakeUp: boolean): void;
/**
* Adds a force at the given world-space point of this rigid-body.
*
* @param force - the world-space force to add to the rigid-body.
* @param point - the world-space point where the impulse is to be applied on the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
addForceAtPoint(force: Vector, point: Vector, wakeUp: boolean): void;
/**
* Applies an impulse at the given world-space point of this rigid-body.
*
* @param impulse - the world-space impulse to apply on the rigid-body.
* @param point - the world-space point where the impulse is to be applied on the rigid-body.
* @param wakeUp - should the rigid-body be automatically woken-up?
*/
applyImpulseAtPoint(impulse: Vector, point: Vector, wakeUp: boolean): void;
}
export declare class RigidBodyDesc {
enabled: boolean;
translation: Vector;
rotation: Rotation;
gravityScale: number;
mass: number;
massOnly: boolean;
centerOfMass: Vector;
translationsEnabledX: boolean;
translationsEnabledY: boolean;
linvel: Vector;
angvel: Vector;
principalAngularInertia: Vector;
angularInertiaLocalFrame: Rotation;
translationsEnabledZ: boolean;
rotationsEnabledX: boolean;
rotationsEnabledY: boolean;
rotationsEnabledZ: boolean;
linearDamping: number;
angularDamping: number;
status: RigidBodyType;
canSleep: boolean;
sleeping: boolean;
ccdEnabled: boolean;
dominanceGroup: number;
additionalSolverIterations: number;
userData?: unknown;
constructor(status: RigidBodyType);
/**
* A rigid-body descriptor used to build a dynamic rigid-body.
*/
static dynamic(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a position-based kinematic rigid-body.
*/
static kinematicPositionBased(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a velocity-based kinematic rigid-body.
*/
static kinematicVelocityBased(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a fixed rigid-body.
*/
static fixed(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a dynamic rigid-body.
*
* @deprecated The method has been renamed to `.dynamic()`.
*/
static newDynamic(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a position-based kinematic rigid-body.
*
* @deprecated The method has been renamed to `.kinematicPositionBased()`.
*/
static newKinematicPositionBased(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a velocity-based kinematic rigid-body.
*
* @deprecated The method has been renamed to `.kinematicVelocityBased()`.
*/
static newKinematicVelocityBased(): RigidBodyDesc;
/**
* A rigid-body descriptor used to build a fixed rigid-body.
*
* @deprecated The method has been renamed to `.fixed()`.
*/
static newStatic(): RigidBodyDesc;
setDominanceGroup(group: number): RigidBodyDesc;
/**
* Sets the number of additional solver iterations that will be run for this
* rigid-body and everything that interacts with it directly or indirectly
* through contacts or joints.
*
* Compared to increasing the global `World.numSolverIteration`, setting this
* value lets you increase accuracy on only a subset of the scene, resulting in reduced
* performance loss.
*
* @param iters - The new number of additional solver iterations (default: 0).
*/
setAdditionalSolverIterations(iters: number): RigidBodyDesc;
/**
* Sets whether the created rigid-body will be enabled or disabled.
* @param enabled If set to `false` the rigid-body will be disabled at creation.
*/
setEnabled(enabled: boolean): RigidBodyDesc;
/**
* Sets the initial translation of the rigid-body to create.
*
* @param tra - The translation to set.
*/
setTranslation(x: number, y: number, z: number): RigidBodyDesc;
/**
* Sets the initial rotation of the rigid-body to create.
*
* @param rot - The rotation to set.
*/
setRotation(rot: Rotation): RigidBodyDesc;
/**
* Sets the scale factor applied to the gravity affecting
* the rigid-body being built.
*
* @param scale - The scale factor. Set this to `0.0` if the rigid-body
* needs to ignore gravity.
*/
setGravityScale(scale: number): RigidBodyDesc;
/**
* Sets the initial mass of the rigid-body being built, before adding colliders' contributions.
*
* @param mass The initial mass of the rigid-body to create.
*/
setAdditionalMass(mass: number): RigidBodyDesc;
/**
* Sets the initial linear velocity of the rigid-body to create.
*
* @param x - The linear velocity to set along the `x` axis.
* @param y - The linear velocity to set along the `y` axis.
* @param z - The linear velocity to set along the `z` axis.
*/
setLinvel(x: number, y: number, z: number): RigidBodyDesc;
/**
* Sets the initial angular velocity of the rigid-body to create.
*
* @param vel - The angular velocity to set.
*/
setAngvel(vel: Vector): RigidBodyDesc;
/**
* Sets the mass properties of the rigid-body being built.
*
* Note that the final mass properties of the rigid-bodies depends
* on the initial mass-properties of the rigid-body (set by this method)
* to which is added the contributions of all the colliders with non-zero density
* attached to this rigid-body.
*
* Therefore, if you want your provided mass properties to be the final
* mass properties of your rigid-body, don't attach colliders to it, or
* only attach colliders with densities equal to zero.
*
* @param mass The initial mass of the rigid-body to create.
* @param centerOfMass The initial center-of-mass of the rigid-body to create.
* @param principalAngularInertia The initial principal angular inertia of the rigid-body to create.
* These are the eigenvalues of the angular inertia matrix.
* @param angularInertiaLocalFrame The initial local angular inertia frame of the rigid-body to create.
* These are the eigenvectors of the angular inertia matrix.
*/
setAdditionalMassProperties(mass: number, centerOfMass: Vector, principalAngularInertia: Vector, angularInertiaLocalFrame: Rotation): RigidBodyDesc;
/**
* Allow translation of this rigid-body only along specific axes.
* @param translationsEnabledX - Are translations along the X axis enabled?
* @param translationsEnabledY - Are translations along the y axis enabled?
* @param translationsEnabledZ - Are translations along the Z axis enabled?
*/
enabledTranslations(translationsEnabledX: boolean, translationsEnabledY: boolean, translationsEnabledZ: boolean): RigidBodyDesc;
/**
* Allow translation of this rigid-body only along specific axes.
* @param translationsEnabledX - Are translations along the X axis enabled?
* @param translationsEnabledY - Are translations along the y axis enabled?
* @param translationsEnabledZ - Are translations along the Z axis enabled?
* @deprecated use `this.enabledTranslations` with the same arguments instead.
*/
restrictTranslations(translationsEnabledX: boolean, translationsEnabledY: boolean, translationsEnabledZ: boolean): RigidBodyDesc;
/**
* Locks all translations that would have resulted from forces on
* the created rigid-body.
*/
lockTranslations(): RigidBodyDesc;
/**
* Allow rotation of this rigid-body only along specific axes.
* @param rotationsEnabledX - Are rotations along the X axis enabled?
* @param rotationsEnabledY - Are rotations along the y axis enabled?
* @param rotationsEnabledZ - Are rotations along the Z axis enabled?
*/
enabledRotations(rotationsEnabledX: boolean, rotationsEnabledY: boolean, rotationsEnabledZ: boolean): RigidBodyDesc;
/**
* Allow rotation of this rigid-body only along specific axes.
* @param rotationsEnabledX - Are rotations along the X axis enabled?
* @param rotationsEnabledY - Are rotations along the y axis enabled?
* @param rotationsEnabledZ - Are rotations along the Z axis enabled?
* @deprecated use `this.enabledRotations` with the same arguments instead.
*/
restrictRotations(rotationsEnabledX: boolean, rotationsEnabledY: boolean, rotationsEnabledZ: boolean): RigidBodyDesc;
/**
* Locks all rotations that would have resulted from forces on
* the created rigid-body.
*/
lockRotations(): RigidBodyDesc;
/**
* Sets the linear damping of the rigid-body to create.
*
* This will progressively slowdown the translational movement of the rigid-body.
*
* @param damping - The angular damping coefficient. Should be >= 0. The higher this
* value is, the stronger the translational slowdown will be.
*/
setLinearDamping(damping: number): RigidBodyDesc;
/**
* Sets the angular damping of the rigid-body to create.
*
* This will progressively slowdown the rotational movement of the rigid-body.
*
* @param damping - The angular damping coefficient. Should be >= 0. The higher this
* value is, the stronger the rotational slowdown will be.
*/
setAngularDamping(damping: number): RigidBodyDesc;
/**
* Sets whether or not the rigid-body to create can sleep.
*
* @param can - true if the rigid-body can sleep, false if it can't.
*/
setCanSleep(can: boolean): RigidBodyDesc;
/**
* Sets whether or not the rigid-body is to be created asleep.
*
* @param can - true if the rigid-body should be in sleep, default false.
*/
setSleeping(sleeping: boolean): RigidBodyDesc;
/**
* Sets whether Continuous Collision Detection (CCD) is enabled for this rigid-body.
*
* @param enabled - true if the rigid-body has CCD enabled.
*/
setCcdEnabled(enabled: boolean): RigidBodyDesc;
/**
* Sets the user-defined object of this rigid-body.
*
* @param userData - The user-defined object to set.
*/
setUserData(data?: unknown): RigidBodyDesc;
}

View File

@@ -0,0 +1,78 @@
import { RawRigidBodySet } from "../raw";
import { RigidBody, RigidBodyDesc, RigidBodyHandle } from "./rigid_body";
import { ColliderSet } from "../geometry";
import { ImpulseJointSet } from "./impulse_joint_set";
import { MultibodyJointSet } from "./multibody_joint_set";
import { IslandManager } from "./island_manager";
/**
* A set of rigid bodies that can be handled by a physics pipeline.
*
* To avoid leaking WASM resources, this MUST be freed manually with `rigidBodySet.free()`
* once you are done using it (and all the rigid-bodies it created).
*/
export declare class RigidBodySet {
raw: RawRigidBodySet;
private map;
/**
* Release the WASM memory occupied by this rigid-body set.
*/
free(): void;
constructor(raw?: RawRigidBodySet);
/**
* Internal method, do not call this explicitly.
*/
finalizeDeserialization(colliderSet: ColliderSet): void;
/**
* Creates a new rigid-body and return its integer handle.
*
* @param desc - The description of the rigid-body to create.
*/
createRigidBody(colliderSet: ColliderSet, desc: RigidBodyDesc): RigidBody;
/**
* Removes a rigid-body from this set.
*
* This will also remove all the colliders and joints attached to the rigid-body.
*
* @param handle - The integer handle of the rigid-body to remove.
* @param colliders - The set of colliders that may contain colliders attached to the removed rigid-body.
* @param impulseJoints - The set of impulse joints that may contain joints attached to the removed rigid-body.
* @param multibodyJoints - The set of multibody joints that may contain joints attached to the removed rigid-body.
*/
remove(handle: RigidBodyHandle, islands: IslandManager, colliders: ColliderSet, impulseJoints: ImpulseJointSet, multibodyJoints: MultibodyJointSet): void;
/**
* The number of rigid-bodies on this set.
*/
len(): number;
/**
* Does this set contain a rigid-body with the given handle?
*
* @param handle - The rigid-body handle to check.
*/
contains(handle: RigidBodyHandle): boolean;
/**
* Gets the rigid-body with the given handle.
*
* @param handle - The handle of the rigid-body to retrieve.
*/
get(handle: RigidBodyHandle): RigidBody | null;
/**
* Applies the given closure to each rigid-body contained by this set.
*
* @param f - The closure to apply.
*/
forEach(f: (body: RigidBody) => void): void;
/**
* Applies the given closure to each active rigid-bodies contained by this set.
*
* A rigid-body is active if it is not sleeping, i.e., if it moved recently.
*
* @param f - The closure to apply.
*/
forEachActiveRigidBody(islands: IslandManager, f: (body: RigidBody) => void): void;
/**
* Gets all rigid-bodies in the list.
*
* @returns rigid-bodies list.
*/
getAll(): RigidBody[];
}