class MAGES::MeshDeformations::SpatialHashGrid

Overview

A spatial hash grid for fast neighbor search. More…

class SpatialHashGrid
{
public:
    // structs

    struct CalculateStartIndicesJob;
    struct CollectContactPairsJob;
    struct CreateUnorderedSpatialLookupJob;
    struct SortJob;

    // fields

    NativeArray SpatialLookUpItemIndices = new();
    NativeArray SpatialLookUpCellKeys = new();
    NativeArray StartIndices = new();
    UnsafeAtomicCounter32 QueryResultsCount;
    NativeArray QueryResults = new();

    // properties

    float CellSize;

    // methods

    SpatialHashGrid(float cellSize, int itemCount);
    void SetItemsCount(int itemCount);

    JobHandle RecalculateGrid(
        NativeArray particlePositions,
        JobHandle dependsOn = default
    );

    JobHandle CollectContactPairs(
        in float particleRadius,
        ref NativeArray particlesPredictedPosition,
        ref NativeArray particlesPhase,
        ref NativeArray<ContactPair> contactPairs,
        ref NativeReference contactPairsCount,
        JobHandle dependsOn = default
    );

    void Query(in float3 position, in float maxDistance);
};

Detailed Documentation

A spatial hash grid for fast neighbor search.

Fields

NativeArray SpatialLookUpItemIndices = new()

The lookup indices array.

NativeArray SpatialLookUpCellKeys = new()

The cell keys.

NativeArray StartIndices = new()

The index at which each cell starts.

UnsafeAtomicCounter32 QueryResultsCount

The query results counter.

NativeArray QueryResults = new()

The query results.

Properties

float CellSize

Gets or sets the cell size.

Methods

SpatialHashGrid(float cellSize, int itemCount)

Initializes a new instance of the SpatialHashGrid class.

Parameters:

cellSize

the cell size.

itemCount

The items count.

void SetItemsCount(int itemCount)

Sets the items count.

Parameters:

itemCount

The new number of items.

JobHandle RecalculateGrid(
    NativeArray particlePositions,
    JobHandle dependsOn = default
)

Recalculates the grid.

Parameters:

particlePositions

The particle positions.

dependsOn

A dependency job.

Returns:

The job handle.

JobHandle CollectContactPairs(
    in float particleRadius,
    ref NativeArray particlesPredictedPosition,
    ref NativeArray particlesPhase,
    ref NativeArray<ContactPair> contactPairs,
    ref NativeReference contactPairsCount,
    JobHandle dependsOn = default
)

Collects the contact pairs.

Parameters:

particleRadius

The radius of the particles.

particlesPredictedPosition

The particles predicted positions.

contactPairs

The contact pairs generated.

contactPairsCount

The number of contact pairs generated.

dependsOn

A job dependency.

Returns:

The job handle.

void Query(in float3 position, in float maxDistance)

Queries the grid.

Parameters:

position

The position.

maxDistance

The distance from the position.