Table of Contents

Class Voxel

Namespace
GridForge.Grids
Assembly
GridForge.dll

Represents a voxel within a 3D grid, handling spatial positioning, obstacles, occupants, and neighbor relationships.

public class Voxel : IEquatable<Voxel>
Inheritance
Voxel
Implements
Inherited Members

Constructors

Voxel()

public Voxel()

Properties

CachedGridVersion

The current version of the grid at the time this voxel was created.

public uint CachedGridVersion { get; }

Property Value

uint

GridIndex

The world-local index of the grid this voxel belongs to.

public ushort GridIndex { get; }

Property Value

ushort

HasVacancy

Checks if this voxel has open slots for new occupants.

public bool HasVacancy { get; }

Property Value

bool

Index

The local coordinates of this voxel within its grid.

public VoxelIndex Index { get; }

Property Value

VoxelIndex

IsAllocated

Indicates whether this voxel is allocated within a grid.

public bool IsAllocated { get; }

Property Value

bool

IsBlockable

Determines if this voxel can accept additional obstacles.

public bool IsBlockable { get; }

Property Value

bool

IsBlocked

Determines whether this voxel is blocked due to obstacles.

public bool IsBlocked { get; }

Property Value

bool

IsBoundaryVoxel

Determines if this voxel is a boundary voxel.

public bool IsBoundaryVoxel { get; }

Property Value

bool

IsOccupied

Determines whether this voxel is occupied by entities.

public bool IsOccupied { get; }

Property Value

bool

IsPartioned

Indicates whether this voxel has any active partitions.

public bool IsPartioned { get; }

Property Value

bool

ObstacleCount

The current number of obstacles on this voxel.

public byte ObstacleCount { get; }

Property Value

byte

ObstacleTracker

Stores the process-unique identity of each obstacle registration added to this voxel.

public SwiftHashSet<ObstacleToken>? ObstacleTracker { get; }

Property Value

SwiftHashSet<ObstacleToken>

OccupantCount

The current number of occupants on this voxel.

public byte OccupantCount { get; }

Property Value

byte

ScanCellKey

The grid-local key of the scan cell that this voxel belongs to.

public int ScanCellKey { get; }

Property Value

int

WorldIndex

The world-scoped runtime identity of this voxel within the grid system.

public WorldVoxelIndex WorldIndex { get; set; }

Property Value

WorldVoxelIndex

WorldPosition

The world-space position of this voxel.

public Vector3d WorldPosition { get; }

Property Value

Vector3d

Methods

Equals(Voxel?)

public bool Equals(Voxel? other)

Parameters

other Voxel

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

GetHexNeighborsInto(VoxelGrid, SwiftList<(HexDirection Direction, Voxel Voxel)>)

Clears and fills caller-owned storage with hex-prism neighbors in deterministic direction order.

public void GetHexNeighborsInto(VoxelGrid ownerGrid, SwiftList<(HexDirection Direction, Voxel Voxel)> results)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

results SwiftList<(HexDirection Direction, Voxel Voxel)>

Caller-owned storage cleared and filled with direction-labeled neighbors.

GetNeighborsInto(VoxelGrid, SwiftList<Voxel>, VoxelNeighborScope, Fixed64?)

Clears and fills caller-owned storage with neighboring voxels whose world-space voxel footprints touch this voxel's footprint.

public void GetNeighborsInto(VoxelGrid ownerGrid, SwiftList<Voxel> results, VoxelNeighborScope scope = VoxelNeighborScope.All, Fixed64? tolerance = null)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

results SwiftList<Voxel>

Caller-owned storage cleared and filled with contact neighbors.

scope VoxelNeighborScope

The grid groups included by the contact query.

tolerance Fixed64?

Optional fixed-point tolerance applied to footprint contact checks.

GetPartitionOrDefault<T>()

Retrieves a partition from the voxel by type and returns null if it doesn't exist.

public T? GetPartitionOrDefault<T>() where T : class, IVoxelPartition

Returns

T

Type Parameters

T

GetRectangularNeighborsInto(VoxelGrid, SwiftList<(RectangularDirection Direction, Voxel Voxel)>)

Clears and fills caller-owned storage with rectangular-prism neighbors in deterministic direction order.

public void GetRectangularNeighborsInto(VoxelGrid ownerGrid, SwiftList<(RectangularDirection Direction, Voxel Voxel)> results)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

results SwiftList<(RectangularDirection Direction, Voxel Voxel)>

Caller-owned storage cleared and filled with direction-labeled neighbors.

HasNeighbor(VoxelGrid, VoxelNeighborScope, Fixed64?)

Determines whether this voxel has at least one footprint-contact neighbor in the requested scope.

public bool HasNeighbor(VoxelGrid ownerGrid, VoxelNeighborScope scope = VoxelNeighborScope.All, Fixed64? tolerance = null)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

scope VoxelNeighborScope

The grid groups included by the contact query.

tolerance Fixed64?

Optional fixed-point tolerance applied to footprint contact checks.

Returns

bool

True when at least one contact exists; otherwise false.

HasPartition<T>()

Checks whether or not this voxel contains a specific partition.

public bool HasPartition<T>() where T : IVoxelPartition

Returns

bool

Type Parameters

T

ToString()

public override string ToString()

Returns

string

TryAddPartition(IVoxelPartition)

Adds a partition to this voxel, allowing specialized behaviors.

public bool TryAddPartition(IVoxelPartition partition)

Parameters

partition IVoxelPartition

Returns

bool

TryGetNeighbor(VoxelGrid, HexDirection, out Voxel?)

Retrieves the hex-prism neighbor voxel in the supplied topology-local direction.

public bool TryGetNeighbor(VoxelGrid ownerGrid, HexDirection direction, out Voxel? neighbor)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

direction HexDirection

The hex-prism direction to resolve.

neighbor Voxel

The resolved same-topology neighbor when found.

Returns

bool

True when a same-topology neighbor exists in the supplied direction; otherwise false.

TryGetNeighbor(VoxelGrid, RectangularDirection, out Voxel?)

Retrieves the rectangular-prism neighbor voxel in the supplied topology-local direction.

public bool TryGetNeighbor(VoxelGrid ownerGrid, RectangularDirection direction, out Voxel? neighbor)

Parameters

ownerGrid VoxelGrid

The active grid that owns this voxel.

direction RectangularDirection

The rectangular-prism direction to resolve.

neighbor Voxel

The resolved same-topology neighbor when found.

Returns

bool

True when a same-topology neighbor exists in the supplied direction; otherwise false.

TryGetPartition<T>(out T?)

Retrieves a partition from the voxel by type.

public bool TryGetPartition<T>(out T? partition) where T : IVoxelPartition

Parameters

partition T

Returns

bool

Type Parameters

T

TryRemovePartition<T>()

Removes a partition from this voxel.

public bool TryRemovePartition<T>() where T : IVoxelPartition

Returns

bool

Type Parameters

T

Events

OnObstacleAdded

public event Action<ObstacleEventInfo> OnObstacleAdded

Event Type

Action<ObstacleEventInfo>

OnObstacleRemoved

public event Action<ObstacleEventInfo> OnObstacleRemoved

Event Type

Action<ObstacleEventInfo>

OnObstaclesCleared

public event Action<ObstacleClearEventInfo> OnObstaclesCleared

Event Type

Action<ObstacleClearEventInfo>

OnOccupantAdded

public event Action<OccupantEventInfo> OnOccupantAdded

Event Type

Action<OccupantEventInfo>

OnOccupantRemoved

public event Action<OccupantEventInfo> OnOccupantRemoved

Event Type

Action<OccupantEventInfo>