Table of Contents

Class BroadPhase

Namespace
BepuPhysics.CollisionDetection
Assembly
BepuPhysics.dll

Manages scene acceleration structures for collision detection and queries.

public class BroadPhase : IDisposable
Inheritance
BroadPhase
Implements
Inherited Members

Constructors

BroadPhase(BufferPool, int, int)

public BroadPhase(BufferPool pool, int initialActiveLeafCapacity = 4096, int initialStaticLeafCapacity = 8192)

Parameters

pool BufferPool
initialActiveLeafCapacity int
initialStaticLeafCapacity int

Fields

ActiveLeaves

Collidable references contained within the ActiveTree. Note that values at or beyond the ActiveTree.LeafCount are not defined.

public Buffer<CollidableReference> ActiveLeaves

Field Value

Buffer<CollidableReference>

ActiveTree

Tree containing wakeful bodies.

public Tree ActiveTree

Field Value

Tree

StaticLeaves

Collidable references contained within the StaticTree. Note that values at or beyond StaticTree.LeafCount are not defined.

public Buffer<CollidableReference> StaticLeaves

Field Value

Buffer<CollidableReference>

StaticTree

Tree containing sleeping bodies and statics.

public Tree StaticTree

Field Value

Tree

Properties

ActiveRefinementSchedule

Gets or sets the refinement schedule to use for the active tree.

public BroadPhase.RefinementScheduler ActiveRefinementSchedule { get; set; }

Property Value

BroadPhase.RefinementScheduler

Pool

Pool used by the broad phase.

public BufferPool Pool { get; }

Property Value

BufferPool

StaticRefinementSchedule

Gets or sets the refinement schedule to use for the static tree.

public BroadPhase.RefinementScheduler StaticRefinementSchedule { get; set; }

Property Value

BroadPhase.RefinementScheduler

Methods

AddActive(CollidableReference, ref BoundingBox)

public int AddActive(CollidableReference collidable, ref BoundingBox bounds)

Parameters

collidable CollidableReference
bounds BoundingBox

Returns

int

AddStatic(CollidableReference, ref BoundingBox)

public int AddStatic(CollidableReference collidable, ref BoundingBox bounds)

Parameters

collidable CollidableReference
bounds BoundingBox

Returns

int

Clear()

Clears out the broad phase's structures without releasing any resources.

public void Clear()

DefaultActiveRefinementScheduler(int, in Tree, out int, out int, out int, out bool)

Returns the size and number of refinements to execute for the active tree. Used by default.

public static void DefaultActiveRefinementScheduler(int frameIndex, in Tree tree, out int rootRefinementSize, out int subtreeRefinementCount, out int subtreeRefinementSize, out bool usePriorityQueue)

Parameters

frameIndex int

Index of the frame as tracked by the broad phase.

tree Tree

Tree being considered for refinement.

rootRefinementSize int

Size of the root refinement. If zero or negative, no root refinement will be performed.

subtreeRefinementCount int

Number of subtree refinements to perform. Can be zero.

subtreeRefinementSize int

Target size of the subtree refinements.

usePriorityQueue bool

True if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.

DefaultRefinementScheduler(float, int, float, float, int, int, in Tree, out int, out int, out int, out bool)

Returns the size and number of refinements to execute for the active tree. Used by default.

public static void DefaultRefinementScheduler(float optimizationFraction, int rootRefinementPeriod, float rootRefinementSizeScale, float subtreeRefinementSizeScale, int nonpriorityPeriod, int frameIndex, in Tree tree, out int rootRefinementSize, out int subtreeRefinementCount, out int subtreeRefinementSize, out bool usePriorityQueue)

Parameters

optimizationFraction float

Target fraction of the tree to be optimized.

rootRefinementPeriod int

Period, in timesteps, of refinements applied to the root.

rootRefinementSizeScale float

Multiplier to apply to the square root of the leaf count to get the target root refinement size.

subtreeRefinementSizeScale float

Multiplier to apply to the square root of the leaf count to get the target subtree refinement size.

nonpriorityPeriod int

The period between non-priority queue based root refinements, measured in units of root refinements.

frameIndex int

Index of the frame as tracked by the broad phase.

tree Tree

Tree being considered for refinement.

rootRefinementSize int

Size of the root refinement. If zero or negative, no root refinement will be performed.

subtreeRefinementCount int

Number of subtree refinements to perform. Can be zero.

subtreeRefinementSize int

Target size of the subtree refinements.

usePriorityQueue bool

True if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.

DefaultStaticRefinementScheduler(int, in Tree, out int, out int, out int, out bool)

Returns the size and number of refinements to execute for the active tree. Used by default.

public static void DefaultStaticRefinementScheduler(int frameIndex, in Tree tree, out int rootRefinementSize, out int subtreeRefinementCount, out int subtreeRefinementSize, out bool usePriorityQueue)

Parameters

frameIndex int

Index of the frame as tracked by the broad phase.

tree Tree

Tree being considered for refinement.

rootRefinementSize int

Size of the root refinement. If zero or negative, no root refinement will be performed.

subtreeRefinementCount int

Number of subtree refinements to perform. Can be zero.

subtreeRefinementSize int

Target size of the subtree refinements.

usePriorityQueue bool

True if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.

Dispose()

Releases memory used by the broad phase. Leaves the broad phase unusable.

public void Dispose()

EnsureCapacity(int, int)

Ensures that the broad phase structures can hold at least the given number of leaves.

public void EnsureCapacity(int activeCapacity, int staticCapacity)

Parameters

activeCapacity int

Number of leaves to allocate space for in the active tree.

staticCapacity int

Number of leaves to allocate space for in the static tree.

GetActiveBoundsPointers(int, out Vector3*, out Vector3*)

Gets pointers to the leaf's bounds stored in the broad phase's active tree.

public void GetActiveBoundsPointers(int index, out Vector3* minPointer, out Vector3* maxPointer)

Parameters

index int

Index of the active collidable to examine.

minPointer Vector3*

Pointer to the minimum bounds in the tree.

maxPointer Vector3*

Pointer to the maximum bounds in the tree.

GetOverlaps<TOverlapEnumerator>(in BoundingBox, ref TOverlapEnumerator)

Finds any overlaps between a bounding box and leaf bounding boxes.

public void GetOverlaps<TOverlapEnumerator>(in BoundingBox boundingBox, ref TOverlapEnumerator overlapEnumerator) where TOverlapEnumerator : IBreakableForEach<CollidableReference>

Parameters

boundingBox BoundingBox

Query box bounds.

overlapEnumerator TOverlapEnumerator

Enumerator to call for overlaps.

Type Parameters

TOverlapEnumerator

Type of the enumerator to call for overlaps.

GetOverlaps<TOverlapEnumerator>(Vector3, Vector3, ref TOverlapEnumerator)

Finds any overlaps between a bounding box and leaf bounding boxes.

public void GetOverlaps<TOverlapEnumerator>(Vector3 min, Vector3 max, ref TOverlapEnumerator overlapEnumerator) where TOverlapEnumerator : IBreakableForEach<CollidableReference>

Parameters

min Vector3

Minimum bounds of the query box.

max Vector3

Maximum bounds of the query box.

overlapEnumerator TOverlapEnumerator

Enumerator to call for overlaps.

Type Parameters

TOverlapEnumerator

Type of the enumerator to call for overlaps.

GetStaticBoundsPointers(int, out Vector3*, out Vector3*)

Gets pointers to the leaf's bounds stored in the broad phase's static tree.

public void GetStaticBoundsPointers(int index, out Vector3* minPointer, out Vector3* maxPointer)

Parameters

index int

Index of the static to examine.

minPointer Vector3*

Pointer to the minimum bounds in the tree.

maxPointer Vector3*

Pointer to the maximum bounds in the tree.

RayCast<TRayTester>(Vector3, Vector3, float, ref TRayTester, int)

Finds any intersections between a ray and leaf bounding boxes.

public void RayCast<TRayTester>(Vector3 origin, Vector3 direction, float maximumT, ref TRayTester rayTester, int id = 0) where TRayTester : IBroadPhaseRayTester

Parameters

origin Vector3

Origin of the ray to cast.

direction Vector3

Direction of the ray to cast.

maximumT float

Maximum length of the ray traversal in units of the direction's length.

rayTester TRayTester

Callback to execute on ray-leaf bounding box intersections.

id int

User specified id of the ray.

Type Parameters

TRayTester

Type of the callback to execute on ray-leaf bounding box intersections.

RemoveActiveAt(int, out CollidableReference)

public bool RemoveActiveAt(int index, out CollidableReference movedLeaf)

Parameters

index int
movedLeaf CollidableReference

Returns

bool

RemoveAt(int, ref Tree, ref Buffer<CollidableReference>, out CollidableReference)

public static bool RemoveAt(int index, ref Tree tree, ref Buffer<CollidableReference> leaves, out CollidableReference movedLeaf)

Parameters

index int
tree Tree
leaves Buffer<CollidableReference>
movedLeaf CollidableReference

Returns

bool

RemoveStaticAt(int, out CollidableReference)

public bool RemoveStaticAt(int index, out CollidableReference movedLeaf)

Parameters

index int
movedLeaf CollidableReference

Returns

bool

Resize(int, int)

Resizes the broad phase structures to hold the given number of leaves. Note that this is conservative; it will never orphan any existing leaves.

public void Resize(int activeCapacity, int staticCapacity)

Parameters

activeCapacity int

Number of leaves to allocate space for in the active tree.

staticCapacity int

Number of leaves to allocate space for in the static tree.

Sweep<TSweepTester>(in BoundingBox, Vector3, float, ref TSweepTester)

Finds any intersections between a swept bounding box and leaf bounding boxes.

public void Sweep<TSweepTester>(in BoundingBox boundingBox, Vector3 direction, float maximumT, ref TSweepTester sweepTester) where TSweepTester : IBroadPhaseSweepTester

Parameters

boundingBox BoundingBox

Bounding box to sweep.

direction Vector3

Direction along which to sweep the bounding box.

maximumT float

Maximum length of the sweep in units of the direction's length.

sweepTester TSweepTester

Callback to execute on sweep-leaf bounding box intersections.

Type Parameters

TSweepTester

Type of the callback to execute on sweep-leaf bounding box intersections.

Sweep<TSweepTester>(Vector3, Vector3, Vector3, float, ref TSweepTester)

Finds any intersections between a swept bounding box and leaf bounding boxes.

public void Sweep<TSweepTester>(Vector3 min, Vector3 max, Vector3 direction, float maximumT, ref TSweepTester sweepTester) where TSweepTester : IBroadPhaseSweepTester

Parameters

min Vector3

Minimum bounds of the box to sweep.

max Vector3

Maximum bounds of the box to sweep.

direction Vector3

Direction along which to sweep the bounding box.

maximumT float

Maximum length of the sweep in units of the direction's length.

sweepTester TSweepTester

Callback to execute on sweep-leaf bounding box intersections.

Type Parameters

TSweepTester

Type of the callback to execute on sweep-leaf bounding box intersections.

Update(IThreadDispatcher)

public void Update(IThreadDispatcher threadDispatcher = null)

Parameters

threadDispatcher IThreadDispatcher

Update2(IThreadDispatcher, bool)

public void Update2(IThreadDispatcher threadDispatcher = null, bool deterministic = false)

Parameters

threadDispatcher IThreadDispatcher
deterministic bool

UpdateActiveBounds(int, Vector3, Vector3)

Applies updated bounds to the given active leaf index, refitting the tree to match.

public void UpdateActiveBounds(int broadPhaseIndex, Vector3 min, Vector3 max)

Parameters

broadPhaseIndex int

Index of the leaf to update.

min Vector3

New minimum bounds for the leaf.

max Vector3

New maximum bounds for the leaf.

UpdateStaticBounds(int, Vector3, Vector3)

Applies updated bounds to the given active leaf index, refitting the tree to match.

public void UpdateStaticBounds(int broadPhaseIndex, Vector3 min, Vector3 max)

Parameters

broadPhaseIndex int

Index of the leaf to update.

min Vector3

New minimum bounds for the leaf.

max Vector3

New maximum bounds for the leaf.