Table of Contents

Class Bodies

Namespace
BepuPhysics
Assembly
BepuPhysics.dll

Collection of all allocated bodies.

public class Bodies
Inheritance
Bodies
Inherited Members

Constructors

Bodies(BufferPool, Shapes, BroadPhase, int, int, int)

Constructs a new bodies collection. Initialize must be called for the instance to be ready for use.

public Bodies(BufferPool pool, Shapes shapes, BroadPhase broadPhase, int initialBodyCapacity, int initialIslandCapacity, int initialConstraintCapacityPerBody)

Parameters

pool BufferPool

Pool for the collection to pull persistent allocations from.

shapes Shapes

Shapes referenced by the collection's bodies.

broadPhase BroadPhase

Broad phase containing the body collidables.

initialBodyCapacity int

Initial number of bodies to allocate space for in the active set.

initialIslandCapacity int

Initial number of islands to allocate space for in the Sets buffer.

initialConstraintCapacityPerBody int

Expected number of constraint references per body to allocate space for.

Fields

BodyReferenceMask

Mask of bits containing the decoded body reference in a constraint body reference. For active constraints this would be the body index bits, for sleeping constraints this would be the body handle bits.

public const int BodyReferenceMask = 1073741823

Field Value

int

BodyReferenceMetadataMask

public const uint BodyReferenceMetadataMask = 3221225472

Field Value

uint

DoesntExistFlagIndex

public const int DoesntExistFlagIndex = 31

Field Value

int

DynamicLimit

Constraint body references greater than a given unsigned value are either kinematic (bit 30 set) or correspond to an empty lane (bit 31 set).

public const uint DynamicLimit = 1073741824

Field Value

uint

HandlePool

Pool from which handles are pulled for new bodies.

public IdPool HandlePool

Field Value

IdPool

HandleToLocation

Remaps a body handle integer value to the actual array index of the body. The backing array index may change in response to cache optimization.

public Buffer<BodyMemoryLocation> HandleToLocation

Field Value

Buffer<BodyMemoryLocation>

KinematicFlagIndex

public const int KinematicFlagIndex = 30

Field Value

int

KinematicMask

public const int KinematicMask = 1073741824

Field Value

int

Sets

The set of existing bodies. The slot at index 0 contains all active bodies. Later slots, if allocated, contain the bodies associated with inactive islands. Note that this buffer does not necessarily contain contiguous elements. When a set is removed, a gap remains.

public Buffer<BodySet> Sets

Field Value

Buffer<BodySet>

Properties

ActiveSet

Gets a reference to the active set, stored in the index 0 of the Sets buffer.

public ref BodySet ActiveSet { get; }

Property Value

BodySet

Reference to the active body set.

this[BodyHandle]

Gets a reference to a body in the collection.

public BodyReference this[BodyHandle handle] { get; }

Parameters

handle BodyHandle

Handle of the body to pull a reference for.

Property Value

BodyReference

Reference to the requested body.

Remarks

This is an alias for the older GetBodyReference(BodyHandle) and the BodyReference constructor. They are all equivalent.

MinimumConstraintCapacityPerBody

Gets or sets the minimum constraint capacity for each body. Future resizes or allocations will obey this minimum, but changing this does not immediately resize existing lists.

public int MinimumConstraintCapacityPerBody { get; set; }

Property Value

int

Pool

Gets the pool used by the bodies collection to allocate and free memory.

public BufferPool Pool { get; }

Property Value

BufferPool

Methods

Add(in BodyDescription)

Adds a new active body to the simulation.

public BodyHandle Add(in BodyDescription description)

Parameters

description BodyDescription

Description of the body to add.

Returns

BodyHandle

Handle of the created body.

ApplyDescription(BodyHandle, in BodyDescription)

Applies a description to a body. Properly handles any transitions between dynamic and kinematic and between shapeless and shapeful. If the body is becoming kinematic, any constraints which only contain kinematic bodies will be removed. Wakes up the body. Updates the bounds of the body in the broad phase.

public void ApplyDescription(BodyHandle handle, in BodyDescription description)

Parameters

handle BodyHandle

Handle of the body to receive the description.

description BodyDescription

Description to apply to the body.

BodyExists(BodyHandle)

Checks whether a body handle is currently registered with the bodies set.

public bool BodyExists(BodyHandle bodyHandle)

Parameters

bodyHandle BodyHandle

Handle to check for.

Returns

bool

True if the handle exists in the collection, false otherwise.

Clear()

Clears all bodies from all sets without releasing any memory that wouldn't be released by a sequence of regular removals.

public void Clear()

CountBodies()

Computes the number of bodies contained in the simulation.

public int CountBodies()

Returns

int

Number of bodies contained in the simulation.

Remarks

Enumerates all BodySet instances in the Bodies collection, summing the body counts for every allocated instance. For simulations with very large numbers of sleeping body sets, this is not a trivial operation.

Dispose()

Returns all body resources to the pool used to create them.

public void Dispose()

Remarks

The object can be reused if it is reinitialized by using EnsureCapacity or Resize.

EnsureCapacity(int)

Increases the size of active body buffers if needed to hold the target capacity.

public void EnsureCapacity(int capacity)

Parameters

capacity int

Target data capacity.

EnsureConstraintListCapacities()

Ensures all active body constraint lists can hold at least MinimumConstraintCapacityPerBody constraints. Inactive bodies are untouched.

public void EnsureConstraintListCapacities()

EnumerateConnectedBodies<TEnumerator>(BodyHandle, ref TEnumerator)

Enumerates all the bodies connected to a given body. Bodies which are connected by more than one constraint will be reported multiple times.

public void EnumerateConnectedBodies<TEnumerator>(BodyHandle bodyHandle, ref TEnumerator enumerator) where TEnumerator : IForEach<BodyHandle>

Parameters

bodyHandle BodyHandle

Handle of the body to enumerate the connections of. This body will not appear in the set of enumerated bodies, even if it is connected to itself somehow.

enumerator TEnumerator

Enumerator instance to run on each connected body.

Type Parameters

TEnumerator

Type of the enumerator to execute on each connected body.

GatherState<TAccessFilter>(Vector<int>, bool, out Vector3Wide, out QuaternionWide, out BodyVelocityWide, out BodyInertiaWide)

public void GatherState<TAccessFilter>(Vector<int> encodedBodyIndices, bool worldInertia, out Vector3Wide position, out QuaternionWide orientation, out BodyVelocityWide velocity, out BodyInertiaWide inertia) where TAccessFilter : unmanaged, IBodyAccessFilter

Parameters

encodedBodyIndices Vector<int>
worldInertia bool
position Vector3Wide
orientation QuaternionWide
velocity BodyVelocityWide
inertia BodyInertiaWide

Type Parameters

TAccessFilter

GetBodyReference(BodyHandle)

Gets a reference to a body by its handle.

public BodyReference GetBodyReference(BodyHandle handle)

Parameters

handle BodyHandle

Handle of the body to grab a reference of.

Returns

BodyReference

Reference to the desired body.

Remarks

This is an alias for this[BodyHandle] and the BodyReference constructor. They are all equivalent.

GetDescription(BodyHandle)

Gets the description of a body by handle.

public BodyDescription GetDescription(BodyHandle handle)

Parameters

handle BodyHandle

Handle of the body to look up.

Returns

BodyDescription

Description of the body.

GetDescription(BodyHandle, out BodyDescription)

Gets the description of a body by handle.

public void GetDescription(BodyHandle handle, out BodyDescription description)

Parameters

handle BodyHandle

Handle of the body to look up.

description BodyDescription

Description of the body.

HasLockedInertia(Symmetric3x3)

Gets whether the angular inertia matches that of a kinematic body (that is, all inverse inertia tensor components are zero).

public static bool HasLockedInertia(Symmetric3x3 inertia)

Parameters

inertia Symmetric3x3

Body inertia to analyze.

Returns

bool

True if all components of inverse mass and inertia are zero, false otherwise.

HasLockedInertia(Symmetric3x3*)

Gets whether the angular inertia matches that of a kinematic body (that is, all inverse inertia tensor components are zero).

public static bool HasLockedInertia(Symmetric3x3* inertia)

Parameters

inertia Symmetric3x3*

Body inertia to analyze.

Returns

bool

True if all components of inverse mass and inertia are zero, false otherwise.

Initialize(Solver, IslandAwakener, IslandSleeper)

Initializes the bodies set. Used to complete bidirectional dependencies.

public void Initialize(Solver solver, IslandAwakener awakener, IslandSleeper sleeper)

Parameters

solver Solver

Solver responsible for the constraints connected to the collection's bodies.

awakener IslandAwakener

Island awakener to use when bodies undergo transitions requiring that they exist in the active set.

sleeper IslandSleeper

IsEncodedDynamicReference(int)

Checks whether a constraint encoded body reference value refers to a dynamic body.

public static bool IsEncodedDynamicReference(int encodedBodyReferenceValue)

Parameters

encodedBodyReferenceValue int

Raw encoded value taken from a constraint.

Returns

bool

True if the encoded body reference refers to a dynamic body, false otherwise.

IsEncodedKinematicReference(int)

Checks whether a constraint encoded body reference value refers to a kinematic body.

public static bool IsEncodedKinematicReference(int encodedBodyReferenceValue)

Parameters

encodedBodyReferenceValue int

Raw encoded value taken from a constraint.

Returns

bool

True if the encoded body reference refers to a kinematic body, false otherwise.

IsKinematic(BodyInertia)

Gets whether the inertia matches that of a kinematic body (that is, all inverse mass and inertia components are zero).

public static bool IsKinematic(BodyInertia inertia)

Parameters

inertia BodyInertia

Body inertia to analyze.

Returns

bool

True if all components of inverse mass and inertia are zero, false otherwise.

IsKinematic(BodyInertia*)

Gets whether the inertia matches that of a kinematic body (that is, all inverse mass and inertia components are zero).

public static bool IsKinematic(BodyInertia* inertia)

Parameters

inertia BodyInertia*

Body inertia to analyze.

Returns

bool

True if all components of inverse mass and inertia are zero, false otherwise.

IsKinematic(BodyInertiaWide)

Checks inertia lanes for kinematicity (all inverse mass and inertia values are zero).

public static Vector<int> IsKinematic(BodyInertiaWide inertia)

Parameters

inertia BodyInertiaWide

Inertia to examine for kinematicity.

Returns

Vector<int>

Mask of lanes which contain zeroed inverse masses and inertias.

Remove(BodyHandle)

Removes a body from the set by its handle. If the body is inactive, all bodies in its island will be forced active.

public void Remove(BodyHandle handle)

Parameters

handle BodyHandle

Handle of the body to remove.

RemoveAt(int)

Removes an active body by its index. Any constraints connected to this body will be removed. Assumes that the input location is valid.

public void RemoveAt(int activeBodyIndex)

Parameters

activeBodyIndex int

Index of the active body.

Resize(int)

Resizes the allocated spans for active body data. Note that this is conservative; it will never orphan existing objects.

public void Resize(int capacity)

Parameters

capacity int

Target body data capacity.

ResizeConstraintListCapacities()

Resizes all active body constraint lists to meet the MinimumConstraintCapacityPerBody. Inactive bodies are untouched. Resizes are guaranteed to never shrink a list below the current count.

public void ResizeConstraintListCapacities()

ScatterInertia(ref BodyInertiaWide, Vector<int>, Vector<int>)

public void ScatterInertia(ref BodyInertiaWide inertia, Vector<int> encodedBodyIndices, Vector<int> mask)

Parameters

inertia BodyInertiaWide
encodedBodyIndices Vector<int>
mask Vector<int>

ScatterPose(ref Vector3Wide, ref QuaternionWide, Vector<int>, Vector<int>)

public void ScatterPose(ref Vector3Wide position, ref QuaternionWide orientation, Vector<int> encodedBodyIndices, Vector<int> mask)

Parameters

position Vector3Wide
orientation QuaternionWide
encodedBodyIndices Vector<int>
mask Vector<int>

ScatterVelocities<TAccessFilter>(ref BodyVelocityWide, ref Vector<int>)

public void ScatterVelocities<TAccessFilter>(ref BodyVelocityWide sourceVelocities, ref Vector<int> encodedBodyIndices) where TAccessFilter : unmanaged, IBodyAccessFilter

Parameters

sourceVelocities BodyVelocityWide
encodedBodyIndices Vector<int>

Type Parameters

TAccessFilter

SetLocalInertia(BodyHandle, in BodyInertia)

Changes the local mass and inertia tensor associated with a body. Properly handles the transition between kinematic and dynamic. If the body is becoming kinematic, any constraints which only contain kinematic bodies will be removed. Wakes up the body.

public void SetLocalInertia(BodyHandle handle, in BodyInertia localInertia)

Parameters

handle BodyHandle

Handle of the body whose inertia should change.

localInertia BodyInertia

New local inertia for the body.

Remarks

This function is only necessary when the inertia change could potentially result in a transition between dynamic and kinematic states. If it is guaranteed to be dynamic before and after the change, the inertia can be directly modified without issue.

SetShape(BodyHandle, TypedIndex)

Changes the shape of a body. Properly handles the transition between shapeless and shapeful. If the body is inactive, it will be forced awake. Updates the bounds of the body in the broad phase.

public void SetShape(BodyHandle handle, TypedIndex newShape)

Parameters

handle BodyHandle

Handle of the body to change the shape of.

newShape TypedIndex

Index of the new shape to use for the body.

TransposeMotionStates(Buffer<MotionState>, out Vector3Wide, out QuaternionWide, out BodyVelocityWide)

Transposes of bundle of array-of-structures layout motion states into a bundle of array-of-structures-of-arrays layout. Size of buffer must be no larger than the Count.

public static void TransposeMotionStates(Buffer<MotionState> states, out Vector3Wide position, out QuaternionWide orientation, out BodyVelocityWide velocity)

Parameters

states Buffer<MotionState>

Array-of-structures data to transpose.

position Vector3Wide

Array-of-structures-of-arrays positions.

orientation QuaternionWide

Array-of-structures-of-arrays orientations.

velocity BodyVelocityWide

Array-of-structures-of-arrays velocities.

UpdateBounds(BodyHandle)

Updates the bounds held within the broad phase for the body's current state. Does not expand the bounding box by velocity. If there is no shape associated with the body, this does nothing.

public void UpdateBounds(BodyHandle bodyHandle)

Parameters

bodyHandle BodyHandle