Table of Contents

Struct BigCompound

Namespace
BepuPhysics.Collidables
Assembly
BepuPhysics.dll

Compound shape containing a bunch of shapes accessible through a tree acceleration structure. Useful for compounds with lots of children.

public struct BigCompound : ICompoundShape, IDisposableShape, IShape, IBoundsQueryableCompound
Implements
Inherited Members

Constructors

BigCompound(Buffer<CompoundChild>, Shapes, BufferPool, IThreadDispatcher)

Creates a compound shape with an acceleration structure.

public BigCompound(Buffer<CompoundChild> children, Shapes shapes, BufferPool pool, IThreadDispatcher dispatcher = null)

Parameters

children Buffer<CompoundChild>

Set of children in the compound.

shapes Shapes

Shapes set in which child shapes are allocated.

pool BufferPool

Pool to use to allocate acceleration structures.

dispatcher IThreadDispatcher

Thread dispatcher to use to multithread the acceleration structure build, if any.

Fields

Children

Buffer of children within this compound.

public Buffer<CompoundChild> Children

Field Value

Buffer<CompoundChild>

Id

Type id of compound shapes.

public const int Id = 7

Field Value

int

Tree

Acceleration structure for the compound children.

public Tree Tree

Field Value

Tree

Properties

ChildCount

Gets the number of children in the compound shape.

public int ChildCount { get; }

Property Value

int

TypeId

Unique type id for this shape type.

public static int TypeId { get; }

Property Value

int

Methods

Add(CompoundChild, BufferPool, Shapes)

Adds a child to the compound.

public void Add(CompoundChild child, BufferPool pool, Shapes shapes)

Parameters

child CompoundChild

Child to add to the compound.

pool BufferPool

Pool to use to resize the compound's children buffer if necessary.

shapes Shapes

Shapes collection containing the compound's children.

Remarks

This function keeps the Tree in a valid state, but significant changes over time may degrade the tree's quality and result in reduced collision/query performance. If this happens, consider calling RefitAndRefine(BufferPool, int, float) with a refinementIndex that changes with each call (to prioritize different parts of the tree). Incrementing a counter with each call would work fine. The ideal frequency of refinement depends on the kind of modifications being made, but it's likely to be rare.

AddChildBoundsToBatcher(ref BoundingBoxBatcher, in RigidPose, in BodyVelocity, int)

Submits child shapes to a bounding box batcher for vectorized bounds calculation.

public void AddChildBoundsToBatcher(ref BoundingBoxBatcher batcher, in RigidPose pose, in BodyVelocity velocity, int bodyIndex)

Parameters

batcher BoundingBoxBatcher

Batcher to accumulate children in.

pose RigidPose

Pose of the compound.

velocity BodyVelocity

Velocity of the compound used to expand child bounds.

bodyIndex int

Index of the body in the active body set; used to accumulate child bounds results.

Remarks

This is used internally for bounding box calculation, but it is unlikely to be useful externally.

ComputeBounds(Quaternion, Shapes, out Vector3, out Vector3)

Computes the bounding box of a compound shape.

public void ComputeBounds(Quaternion orientation, Shapes shapeBatches, out Vector3 min, out Vector3 max)

Parameters

orientation Quaternion

Orientation of the compound.

shapeBatches Shapes

Shape batches to look up child shape information in.

min Vector3

Minimum of the compound's bounding box.

max Vector3

Maximum of the compound's bounding box.

ComputeInertia(Span<float>, Shapes)

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

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

Parameters

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<float>, Shapes, out Vector3)

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

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

Parameters

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.

CreateShapeBatch(BufferPool, int, Shapes)

Creates a shape batch for this type of shape.

public static ShapeBatch CreateShapeBatch(BufferPool pool, int initialCapacity, Shapes shapes)

Parameters

pool BufferPool

Buffer pool used to create the batch.

initialCapacity int

Initial capacity to allocate within the batch.

shapes Shapes

Returns

ShapeBatch

Shape batch for the shape type.

Remarks

This is typically used internally to initialize new shape collections in response to shapes being added. It is not likely to be useful outside of the engine.

CreateWithSweepBuild(Buffer<CompoundChild>, Shapes, BufferPool)

Creates a compound shape instance and builds an acceleration structure using a sweep builder.

public static BigCompound CreateWithSweepBuild(Buffer<CompoundChild> children, Shapes shapes, BufferPool pool)

Parameters

children Buffer<CompoundChild>

Children to use in the compound.

shapes Shapes

Shapes set in which child shapes are allocated.

pool BufferPool

Pool used to allocate acceleration structures.

Returns

BigCompound

Created compound shape.

Remarks

The sweep builder is significantly slower than the binned builder, but can sometimes create higher quality trees.

Note that the binned builder can be tuned to create higher quality trees. That is usually a better choice than trying to use the sweep builder; this is here primarily for legacy reasons.

CreateWithoutTreeBuild(Buffer<CompoundChild>, BufferPool)

Creates a BigCompound shape instance, but leaves the Tree in an unbuilt state. The Tree must be built before the compound can be used.

public static BigCompound CreateWithoutTreeBuild(Buffer<CompoundChild> children, BufferPool pool)

Parameters

children Buffer<CompoundChild>

Children to use in the compound.

pool BufferPool

Pool used to allocate acceleration structures.

Returns

BigCompound

Created compound shape.

Remarks

In some cases, the default binned build may not be the ideal builder. This function does everything needed to set up a tree without the expense of figuring out the details of the acceleration structure. The user can then run whatever build/refinement process is appropriate.

Dispose(BufferPool)

Returns all resources used by the shape instance to the given pool.

public void Dispose(BufferPool bufferPool)

Parameters

bufferPool BufferPool

FillSubtreesForChildren(Span<CompoundChild>, Shapes, Span<NodeChild>)

Fills a buffer of subtrees according to a buffer of triangles.

public static void FillSubtreesForChildren(Span<CompoundChild> children, Shapes shapes, Span<NodeChild> subtrees)

Parameters

children Span<CompoundChild>

Children to build subtrees from.

shapes Shapes

Shapes set in which child shapes are allocated.

subtrees Span<NodeChild>

Subtrees created for the triangles.

Remarks

The term "subtree" is used because the binned builder does not care whether the input came from leaf nodes or a refinement process's internal nodes.

FindLocalOverlaps<TOverlaps>(Vector3, Vector3, Vector3, float, BufferPool, Shapes, void*)

public void FindLocalOverlaps<TOverlaps>(Vector3 min, Vector3 max, Vector3 sweep, float maximumT, BufferPool pool, Shapes shapes, void* overlaps) where TOverlaps : ICollisionTaskSubpairOverlaps

Parameters

min Vector3
max Vector3
sweep Vector3
maximumT float
pool BufferPool
shapes Shapes
overlaps void*

Type Parameters

TOverlaps

FindLocalOverlaps<TOverlaps, TSubpairOverlaps>(ref Buffer<OverlapQueryForPair>, BufferPool, Shapes, ref TOverlaps)

public void FindLocalOverlaps<TOverlaps, TSubpairOverlaps>(ref Buffer<OverlapQueryForPair> pairs, BufferPool pool, Shapes shapes, ref TOverlaps overlaps) where TOverlaps : struct, ICollisionTaskOverlaps<TSubpairOverlaps> where TSubpairOverlaps : struct, ICollisionTaskSubpairOverlaps

Parameters

pairs Buffer<OverlapQueryForPair>
pool BufferPool
shapes Shapes
overlaps TOverlaps

Type Parameters

TOverlaps
TSubpairOverlaps

GetChild(int)

Gets a child from the compound by index.

public ref CompoundChild GetChild(int compoundChildIndex)

Parameters

compoundChildIndex int

Index of the child to look up.

Returns

CompoundChild

Reference to the requested compound child.

RayTest<TRayHitHandler>(in RigidPose, in RayData, ref float, Shapes, ref TRayHitHandler)

Tests a ray against the shape.

public void RayTest<TRayHitHandler>(in RigidPose pose, in RayData ray, ref float maximumT, Shapes shapes, ref TRayHitHandler hitHandler) where TRayHitHandler : struct, IShapeRayHitHandler

Parameters

pose RigidPose

Pose of the shape during the ray test.

ray RayData

Ray to test against the shape.

maximumT float

Maximum distance along the ray, in units of the ray direction's length, that the ray will test.

shapes Shapes
hitHandler TRayHitHandler

Callbacks called when the ray interacts with a test candidate.

Type Parameters

TRayHitHandler

RayTest<TRayHitHandler>(in RigidPose, ref RaySource, Shapes, ref TRayHitHandler)

Tests multiple rays against the shape.

public void RayTest<TRayHitHandler>(in RigidPose pose, ref RaySource rays, Shapes shapes, ref TRayHitHandler hitHandler) where TRayHitHandler : struct, IShapeRayHitHandler

Parameters

pose RigidPose

Pose of the shape during the ray test.

rays RaySource

Rays to test against the shape.

shapes Shapes
hitHandler TRayHitHandler

Callbacks called when the ray interacts with a test candidate.

Type Parameters

TRayHitHandler

RemoveAt(int, BufferPool)

Removes a child from the compound by index. The last child is pulled to fill the gap left by the removed child.

public void RemoveAt(int childIndex, BufferPool pool)

Parameters

childIndex int

Index of the child to remove from the compound.

pool BufferPool

Pool to use to resize the compound's children buffer if necessary.

Remarks

This function keeps the Tree in a valid state, but significant changes over time may degrade the tree's quality and result in reduced collision/query performance. If this happens, consider calling RefitAndRefine(BufferPool, int, float) with a refinementIndex that changes with each call (to prioritize different parts of the tree). Incrementing a counter with each call would work fine. The ideal frequency of refinement depends on the kind of modifications being made, but it's likely to be rare.