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
collidableCollidableReferenceboundsBoundingBox
Returns
AddStatic(CollidableReference, ref BoundingBox)
public int AddStatic(CollidableReference collidable, ref BoundingBox bounds)
Parameters
collidableCollidableReferenceboundsBoundingBox
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
frameIndexintIndex of the frame as tracked by the broad phase.
treeTreeTree being considered for refinement.
rootRefinementSizeintSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCountintNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSizeintTarget size of the subtree refinements.
usePriorityQueueboolTrue 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
optimizationFractionfloatTarget fraction of the tree to be optimized.
rootRefinementPeriodintPeriod, in timesteps, of refinements applied to the root.
rootRefinementSizeScalefloatMultiplier to apply to the square root of the leaf count to get the target root refinement size.
subtreeRefinementSizeScalefloatMultiplier to apply to the square root of the leaf count to get the target subtree refinement size.
nonpriorityPeriodintThe period between non-priority queue based root refinements, measured in units of root refinements.
frameIndexintIndex of the frame as tracked by the broad phase.
treeTreeTree being considered for refinement.
rootRefinementSizeintSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCountintNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSizeintTarget size of the subtree refinements.
usePriorityQueueboolTrue 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
frameIndexintIndex of the frame as tracked by the broad phase.
treeTreeTree being considered for refinement.
rootRefinementSizeintSize of the root refinement. If zero or negative, no root refinement will be performed.
subtreeRefinementCountintNumber of subtree refinements to perform. Can be zero.
subtreeRefinementSizeintTarget size of the subtree refinements.
usePriorityQueueboolTrue 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
activeCapacityintNumber of leaves to allocate space for in the active tree.
staticCapacityintNumber 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
indexintIndex of the active collidable to examine.
minPointerVector3*Pointer to the minimum bounds in the tree.
maxPointerVector3*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
boundingBoxBoundingBoxQuery box bounds.
overlapEnumeratorTOverlapEnumeratorEnumerator to call for overlaps.
Type Parameters
TOverlapEnumeratorType 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
minVector3Minimum bounds of the query box.
maxVector3Maximum bounds of the query box.
overlapEnumeratorTOverlapEnumeratorEnumerator to call for overlaps.
Type Parameters
TOverlapEnumeratorType 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
indexintIndex of the static to examine.
minPointerVector3*Pointer to the minimum bounds in the tree.
maxPointerVector3*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
originVector3Origin of the ray to cast.
directionVector3Direction of the ray to cast.
maximumTfloatMaximum length of the ray traversal in units of the direction's length.
rayTesterTRayTesterCallback to execute on ray-leaf bounding box intersections.
idintUser specified id of the ray.
Type Parameters
TRayTesterType of the callback to execute on ray-leaf bounding box intersections.
RemoveActiveAt(int, out CollidableReference)
public bool RemoveActiveAt(int index, out CollidableReference movedLeaf)
Parameters
indexintmovedLeafCollidableReference
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
indexinttreeTreeleavesBuffer<CollidableReference>movedLeafCollidableReference
Returns
RemoveStaticAt(int, out CollidableReference)
public bool RemoveStaticAt(int index, out CollidableReference movedLeaf)
Parameters
indexintmovedLeafCollidableReference
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
activeCapacityintNumber of leaves to allocate space for in the active tree.
staticCapacityintNumber 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
boundingBoxBoundingBoxBounding box to sweep.
directionVector3Direction along which to sweep the bounding box.
maximumTfloatMaximum length of the sweep in units of the direction's length.
sweepTesterTSweepTesterCallback to execute on sweep-leaf bounding box intersections.
Type Parameters
TSweepTesterType 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
minVector3Minimum bounds of the box to sweep.
maxVector3Maximum bounds of the box to sweep.
directionVector3Direction along which to sweep the bounding box.
maximumTfloatMaximum length of the sweep in units of the direction's length.
sweepTesterTSweepTesterCallback to execute on sweep-leaf bounding box intersections.
Type Parameters
TSweepTesterType of the callback to execute on sweep-leaf bounding box intersections.
Update(IThreadDispatcher)
public void Update(IThreadDispatcher threadDispatcher = null)
Parameters
threadDispatcherIThreadDispatcher
Update2(IThreadDispatcher, bool)
public void Update2(IThreadDispatcher threadDispatcher = null, bool deterministic = false)
Parameters
threadDispatcherIThreadDispatcherdeterministicbool
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
broadPhaseIndexintIndex of the leaf to update.
minVector3New minimum bounds for the leaf.
maxVector3New 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)