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
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
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
Properties
ActiveRefinementSchedule
Gets or sets the refinement schedule to use for the active tree.
public BroadPhase.RefinementScheduler ActiveRefinementSchedule { get; set; }
Property Value
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
Methods
AddActive(CollidableReference, ref BoundingBox)
public int AddActive(CollidableReference collidable, ref BoundingBox bounds)
Parameters
collidable
CollidableReferencebounds
BoundingBox
Returns
AddStatic(CollidableReference, ref BoundingBox)
public int AddStatic(CollidableReference collidable, ref BoundingBox bounds)
Parameters
collidable
CollidableReferencebounds
BoundingBox
Returns
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
intIndex of the frame as tracked by the broad phase.
tree
TreeTree being considered for refinement.
rootRefinementSize
intSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCount
intNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSize
intTarget size of the subtree refinements.
usePriorityQueue
boolTrue 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
floatTarget fraction of the tree to be optimized.
rootRefinementPeriod
intPeriod, in timesteps, of refinements applied to the root.
rootRefinementSizeScale
floatMultiplier to apply to the square root of the leaf count to get the target root refinement size.
subtreeRefinementSizeScale
floatMultiplier to apply to the square root of the leaf count to get the target subtree refinement size.
nonpriorityPeriod
intThe period between non-priority queue based root refinements, measured in units of root refinements.
frameIndex
intIndex of the frame as tracked by the broad phase.
tree
TreeTree being considered for refinement.
rootRefinementSize
intSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCount
intNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSize
intTarget size of the subtree refinements.
usePriorityQueue
boolTrue 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
intIndex of the frame as tracked by the broad phase.
tree
TreeTree being considered for refinement.
rootRefinementSize
intSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCount
intNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSize
intTarget size of the subtree refinements.
usePriorityQueue
boolTrue 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
intNumber of leaves to allocate space for in the active tree.
staticCapacity
intNumber 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
intIndex 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
BoundingBoxQuery box bounds.
overlapEnumerator
TOverlapEnumeratorEnumerator 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
Vector3Minimum bounds of the query box.
max
Vector3Maximum bounds of the query box.
overlapEnumerator
TOverlapEnumeratorEnumerator 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
intIndex 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
Vector3Origin of the ray to cast.
direction
Vector3Direction of the ray to cast.
maximumT
floatMaximum length of the ray traversal in units of the direction's length.
rayTester
TRayTesterCallback to execute on ray-leaf bounding box intersections.
id
intUser 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
intmovedLeaf
CollidableReference
Returns
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
inttree
Treeleaves
Buffer<CollidableReference>movedLeaf
CollidableReference
Returns
RemoveStaticAt(int, out CollidableReference)
public bool RemoveStaticAt(int index, out CollidableReference movedLeaf)
Parameters
index
intmovedLeaf
CollidableReference
Returns
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
intNumber of leaves to allocate space for in the active tree.
staticCapacity
intNumber 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
BoundingBoxBounding box to sweep.
direction
Vector3Direction along which to sweep the bounding box.
maximumT
floatMaximum length of the sweep in units of the direction's length.
sweepTester
TSweepTesterCallback 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
Vector3Minimum bounds of the box to sweep.
max
Vector3Maximum bounds of the box to sweep.
direction
Vector3Direction along which to sweep the bounding box.
maximumT
floatMaximum length of the sweep in units of the direction's length.
sweepTester
TSweepTesterCallback 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
IThreadDispatcherdeterministic
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
intIndex of the leaf to update.
min
Vector3New minimum bounds for the leaf.
max
Vector3New 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)