Table of Contents

Struct RayBatcher

Namespace
BepuPhysics.Trees
Assembly
BepuPhysics.dll

Reusable structure for testing large numbers of rays against trees.

public struct RayBatcher : IDisposable
Implements
Inherited Members

Constructors

RayBatcher(BufferPool, int, int)

Constructs a ray batcher and initializes its backing resources.

public RayBatcher(BufferPool pool, int rayCapacity = 2048, int treeDepthForPreallocation = 24)

Parameters

pool BufferPool

Pool to pull resources from.

rayCapacity int

Maximum number of rays to execute in each traversal. This should typically be chosen as the highest value which avoids spilling data out of L2 cache.

treeDepthForPreallocation int

Tree depth to preallocate ray stack space for. If a traversal finds nodes deeper than this, a dynamic resize will be triggered.

Properties

RayCapacity

public readonly int RayCapacity { get; }

Property Value

int

RayCount

public readonly int RayCount { get; }

Property Value

int

Methods

Add(ref Vector3, ref Vector3, float, int)

Adds a ray to the batcher. Returns true if the batcher has reached maximum ray capacity and needs to be reset in order to continue adding rays.

public bool Add(ref Vector3 origin, ref Vector3 direction, float maximumT, int id = 0)

Parameters

origin Vector3

Origin of the ray to test against the tree.

direction Vector3

Direction of the ray to test against the tree.

maximumT float

Maximum distance that the ray will travel in units of the ray's length.

id int

Identifier value for the ray. Leaf tests will have access to the id.

Returns

bool

True if the batcher is full and requires a call to ResetRays before adding any more rays, false otherwise.

Dispose()

Disposes all the resources backing the ray batcher.

public void Dispose()

ResetRays()

Resets the accumulated ray count to zero.

public void ResetRays()

TestRays<TLeafTester>(ref Tree, ref TLeafTester)

Tests any batched rays against the given tree.

public void TestRays<TLeafTester>(ref Tree tree, ref TLeafTester leafTester) where TLeafTester : IBatchedRayLeafTester

Parameters

tree Tree

Tree to test the accumulated rays against.

leafTester TLeafTester

Type Parameters

TLeafTester