Table of Contents

Struct CompoundBuilder

Namespace
BepuPhysics.Collidables
Assembly
BepuPhysics.dll

Reusable convenience type for incrementally building compound shapes.

public struct CompoundBuilder : IDisposable
Implements
Inherited Members

Constructors

CompoundBuilder(BufferPool, Shapes, int)

Creates a compound builder.

public CompoundBuilder(BufferPool pool, Shapes shapes, int initialBuilderCapacity)

Parameters

pool BufferPool

Buffer pool to allocate memory from when necessary.

shapes Shapes

Shapes collection to access when constructing the compound children.

initialBuilderCapacity int

Number of children the compound builder can hold without resizing.

Fields

Children

public QuickList<CompoundBuilder.Child> Children

Field Value

QuickList<CompoundBuilder.Child>

Pool

public BufferPool Pool

Field Value

BufferPool

Shapes

public Shapes Shapes

Field Value

Shapes

Methods

Add(TypedIndex, in RigidPose, in BodyInertia)

Adds a new shape to the accumulator.

public void Add(TypedIndex shape, in RigidPose localPose, in BodyInertia childInertia)

Parameters

shape TypedIndex

Index of the shape to add.

localPose RigidPose

Pose of the shape in the compound's local space.

childInertia BodyInertia

Inverse inertia tensor and inverse mass of the shape being added in the child's local space. The inverse mass is used as the inverse weight for building the compound.

Add(TypedIndex, in RigidPose, in Symmetric3x3, float)

Adds a new shape to the accumulator.

public void Add(TypedIndex shape, in RigidPose localPose, in Symmetric3x3 localInverseInertia, float weight)

Parameters

shape TypedIndex

Index of the shape to add.

localPose RigidPose

Pose of the shape in the compound's local space.

localInverseInertia Symmetric3x3

Inverse inertia tensor of the shape being added in its local space. This is assumed to already be scaled as desired by the weight.

weight float

Weight of the shape. If the compound is interpreted as a dynamic, this will be used as the mass. Otherwise, it is used for recentering.

AddForKinematic(TypedIndex, in RigidPose, float)

Adds a new shape to the accumulator, assuming it has infinite inertia.

public void AddForKinematic(TypedIndex shape, in RigidPose localPose, float weight)

Parameters

shape TypedIndex

Index of the shape to add.

localPose RigidPose

Pose of the shape in the compound's local space.

weight float

Weight of the shape used for computing the center of rotation.

AddForKinematic<TShape>(in TShape, in RigidPose, float)

Adds a new shape to the accumulator, creating a new shape in the shapes set. Inertia is assumed to be infinite.

public void AddForKinematic<TShape>(in TShape shape, in RigidPose localPose, float weight) where TShape : unmanaged, IConvexShape

Parameters

shape TShape

Shape to add.

localPose RigidPose

Pose of the shape in the compound's local space.

weight float

Weight of the shape. If the compound is interpreted as a dynamic, this will be used as the mass. Otherwise, it is used for recentering.

Type Parameters

TShape

Type of the shape to add to the accumulator and the shapes set.

Add<TShape>(in TShape, in RigidPose, float)

Adds a new shape to the accumulator, creating a new shape in the shapes set. The mass used to compute the inertia tensor will be based on the given weight.

public void Add<TShape>(in TShape shape, in RigidPose localPose, float weight) where TShape : unmanaged, IConvexShape

Parameters

shape TShape

Shape to add.

localPose RigidPose

Pose of the shape in the compound's local space.

weight float

Weight of the shape. If the compound is interpreted as a dynamic, this will be used as the mass and scales the inertia tensor. Otherwise, it is used for recentering.

Type Parameters

TShape

Type of the shape to add to the accumulator and the shapes set.

BuildDynamicCompound(out Buffer<CompoundChild>, out BodyInertia)

Builds a buffer of compound children from the accumulated set for a dynamic compound. Does not recenter the children. Does not reset the accumulator.

public void BuildDynamicCompound(out Buffer<CompoundChild> children, out BodyInertia inertia)

Parameters

children Buffer<CompoundChild>

List of children created from the accumulated set.

inertia BodyInertia

Combined inertia of the compound.

BuildDynamicCompound(out Buffer<CompoundChild>, out BodyInertia, out Vector3)

Builds a buffer of compound children from the accumulated set for a dynamic compound. Computes a center of mass and recenters child shapes relative to it. Does not reset the accumulator.

public void BuildDynamicCompound(out Buffer<CompoundChild> children, out BodyInertia inertia, out Vector3 center)

Parameters

children Buffer<CompoundChild>

List of children created from the accumulated set.

inertia BodyInertia

Combined inertia of the compound.

center Vector3

Computed center of rotation based on the poses and weights of accumulated children.

BuildKinematicCompound(out Buffer<CompoundChild>)

Builds a buffer of compound children from the accumulated set for a kinematic compound. Does not recenter children. Does not reset the accumulator.

public void BuildKinematicCompound(out Buffer<CompoundChild> children)

Parameters

children Buffer<CompoundChild>

List of children created from the accumulated set.

BuildKinematicCompound(out Buffer<CompoundChild>, out Vector3)

Builds a buffer of compound children from the accumulated set for a kinematic compound. Computes a center of mass and recenters child shapes relative to it. Does not reset the accumulator.

public void BuildKinematicCompound(out Buffer<CompoundChild> children, out Vector3 center)

Parameters

children Buffer<CompoundChild>

List of children created from the accumulated set.

center Vector3

Computed center of rotation based on the poses and weights of accumulated children.

ComputeCenterOfMass(Span<CompoundChild>, Span<float>)

Computes the center of mass of a compound.

public static Vector3 ComputeCenterOfMass(Span<CompoundChild> children, Span<float> childMasses)

Parameters

children Span<CompoundChild>

Children of the compound.

childMasses Span<float>

Masses of the children in the compound.

Returns

Vector3

The compound's center of mass.

ComputeCenterOfMass(Span<CompoundChild>, Span<float>, out float)

Computes the center of mass of a compound.

public static Vector3 ComputeCenterOfMass(Span<CompoundChild> children, Span<float> childMasses, out float inverseMass)

Parameters

children Span<CompoundChild>

Children of the compound.

childMasses Span<float>

Masses of the children in the compound.

inverseMass float

Inverse of the sum of all child masses.

Returns

Vector3

The compound's center of mass.

ComputeCenterOfMass(Span<RigidPose>, Span<float>)

Computes the center of mass of a compound.

public static Vector3 ComputeCenterOfMass(Span<RigidPose> childPoses, Span<float> childMasses)

Parameters

childPoses Span<RigidPose>

Poses of the children in the compound.

childMasses Span<float>

Masses of the children in the compound.

Returns

Vector3

The compound's center of mass.

ComputeCenterOfMass(Span<RigidPose>, Span<float>, out float)

Computes the center of mass of a compound.

public static Vector3 ComputeCenterOfMass(Span<RigidPose> childPoses, Span<float> childMasses, out float inverseMass)

Parameters

childPoses Span<RigidPose>

Poses of the children in the compound.

childMasses Span<float>

Masses of the children in the compound.

inverseMass float

Inverse of the sum of all child masses.

Returns

Vector3

The compound's center of mass.

ComputeInertia(Span<CompoundChild>, Span<float>, Shapes)

Computes the inertia of a compound. Does not recenter the child poses.

public static BodyInertia ComputeInertia(Span<CompoundChild> children, Span<float> childMasses, Shapes shapes)

Parameters

children Span<CompoundChild>

Children of the compound.

childMasses Span<float>

Masses of the children.

shapes Shapes

Shapes collection containing the data for the compound child shapes.

Returns

BodyInertia

Inertia of the compound.

ComputeInertia(Span<CompoundChild>, Span<float>, Shapes, out Vector3)

Computes the inertia of a compound. Recenters the child poses around the calculated center of mass.

public static BodyInertia ComputeInertia(Span<CompoundChild> children, Span<float> childMasses, Shapes shapes, out Vector3 centerOfMass)

Parameters

children Span<CompoundChild>

Children of the compound. Child local positions will have the calculated center of mass subtracted from them.

childMasses Span<float>

Masses of the children.

shapes Shapes

Shapes collection containing the data for the compound child shapes.

centerOfMass Vector3

Calculated center of mass of the compound. Subtracted from all the compound child poses.

Returns

BodyInertia

Inertia of the compound.

ComputeInertiaForChild(in RigidPose, Symmetric3x3, float)

Computes the uninverted inertia contribution of a child.

public static Symmetric3x3 ComputeInertiaForChild(in RigidPose pose, Symmetric3x3 inverseLocalInertia, float mass)

Parameters

pose RigidPose

Pose of the child.

inverseLocalInertia Symmetric3x3

Inverse inertia tensor of the child in its local space.

mass float

Mass of the child.

Returns

Symmetric3x3

Inertia contribution of the child to a compound given its relative pose.

ComputeInertiaForChild(Vector3, Quaternion, Symmetric3x3, float)

Computes the uninverted inertia contribution of a child.

public static Symmetric3x3 ComputeInertiaForChild(Vector3 position, Quaternion orientation, Symmetric3x3 inverseLocalInertia, float mass)

Parameters

position Vector3

Position of the child.

orientation Quaternion

Orientation of the child.

inverseLocalInertia Symmetric3x3

Inverse inertia tensor of the child in its local space.

mass float

Mass of the child.

Returns

Symmetric3x3

Inertia contribution of the child to a compound given its relative pose.

ComputeInverseInertia(Span<CompoundChild>, Span<Symmetric3x3>, Span<float>)

Computes the inertia for a set of compound children based on their poses and the provided inverse inertias. Does not recenter the children.

public static BodyInertia ComputeInverseInertia(Span<CompoundChild> children, Span<Symmetric3x3> inverseLocalInertias, Span<float> childMasses)

Parameters

children Span<CompoundChild>

Children and their associated poses.

inverseLocalInertias Span<Symmetric3x3>

Inverse inertias of the children, each in the child's local space. Assumed to have already been premultiplied by the mass of the child.

childMasses Span<float>

Masses of each child in the compound.

Returns

BodyInertia

BodyInertia of the compound.

ComputeInverseInertia(Span<CompoundChild>, Span<Symmetric3x3>, Span<float>, out Vector3)

Computes the inertia for a set of compound children based on their poses and the provided inverse inertias. Recenters the children onto the computed center of mass.

public static BodyInertia ComputeInverseInertia(Span<CompoundChild> children, Span<Symmetric3x3> inverseLocalInertias, Span<float> childMasses, out Vector3 centerOfMass)

Parameters

children Span<CompoundChild>

Children and their associated poses. Center of mass will be subtracted from the child position.

inverseLocalInertias Span<Symmetric3x3>

Inverse inertias of the children, each in the child's local space. Assumed to have already been premultiplied by the mass of the child.

childMasses Span<float>

Masses of each child in the compound.

centerOfMass Vector3

Computed center of mass that was subtracted from the child positions.

Returns

BodyInertia

BodyInertia of the compound.

ComputeInverseInertia(Span<RigidPose>, Span<Symmetric3x3>, Span<float>)

Computes the inverse inertia for a set of compound children based on their poses and the provided inverse inertias. Does not recenter the children.

public static BodyInertia ComputeInverseInertia(Span<RigidPose> childPoses, Span<Symmetric3x3> inverseLocalInertias, Span<float> childMasses)

Parameters

childPoses Span<RigidPose>

Poses of the compound's children.

inverseLocalInertias Span<Symmetric3x3>

Inverse inertias of the children, each in the child's local space. Assumed to have already been premultiplied by the mass of the child.

childMasses Span<float>

Masses of each child in the compound.

Returns

BodyInertia

BodyInertia of the compound.

ComputeInverseInertia(Span<RigidPose>, Span<Symmetric3x3>, Span<float>, out Vector3)

Computes the inertia for a set of compound children based on their poses and the provided inverse inertias. Recenters the children onto the computed center of mass.

public static BodyInertia ComputeInverseInertia(Span<RigidPose> childPoses, Span<Symmetric3x3> inverseLocalInertias, Span<float> childMasses, out Vector3 centerOfMass)

Parameters

childPoses Span<RigidPose>

Poses of the compound's children. Center of mass will be subtracted from the child position.

inverseLocalInertias Span<Symmetric3x3>

Inverse inertias of the children, each in the child's local space. Assumed to have already been premultiplied by the mass of the child.

childMasses Span<float>

Masses of each child in the compound.

centerOfMass Vector3

Computed center of mass that was subtracted from the child positions.

Returns

BodyInertia

BodyInertia of the compound.

Dispose()

Returns internal resources to the pool, rendering the builder unusable.

public void Dispose()

GetOffsetInertiaContribution(Vector3, float, out Symmetric3x3)

Gets the contribution to an inertia tensor of a point mass at the given offset from the center of mass.

public static void GetOffsetInertiaContribution(Vector3 offset, float mass, out Symmetric3x3 contribution)

Parameters

offset Vector3

Offset from the center of mass.

mass float

Mass of the point.

contribution Symmetric3x3

Contribution to the inertia tensor.

Reset()

Empties out the accumulated children.

public void Reset()