Table of Contents

Class PointOctree<T>

Namespace
VoxelPlayground.Utility
Assembly
GamePlay.dll
public class PointOctree<T>

Type Parameters

T
Inheritance
object
PointOctree<T>

Constructors

PointOctree(float, Vector3, float)

Constructor for the point octree.

public PointOctree(float initialWorldSize, Vector3 initialWorldPos, float minNodeSize)

Parameters

initialWorldSize float

Size of the sides of the initial node. The octree will never shrink smaller than this.

initialWorldPos Vector3

Position of the centre of the initial node.

minNodeSize float

Nodes will stop splitting if the new nodes would be smaller than this.

Properties

Count

public int Count { get; }

Property Value

int

Methods

Add(T, Vector3)

Add an object.

public void Add(T obj, Vector3 objPos)

Parameters

obj T

Object to add.

objPos Vector3

Position of the object.

DrawAllBounds()

Draws node boundaries visually for debugging. Must be called from OnDrawGizmos externally. See also: DrawAllObjects.

public void DrawAllBounds()

DrawAllObjects()

Draws the bounds of all objects in the tree visually for debugging. Must be called from OnDrawGizmos externally. See also: DrawAllBounds.

public void DrawAllObjects()

GetAll()

Return all objects in the tree. If none, returns an empty array (not null).

public ICollection<T> GetAll()

Returns

ICollection<T>

All objects.

GetNearby(Ray, float)

Returns objects that are within maxDistance of the specified ray. If none, returns an empty array (not null).

public T[] GetNearby(Ray ray, float maxDistance)

Parameters

ray Ray

The ray. Passing as ref to improve performance since it won't have to be copied.

maxDistance float

Maximum distance from the ray to consider.

Returns

T[]

Objects within range.

GetNearby(Vector3, float)

Returns objects that are within maxDistance of the specified position. If none, returns an empty array (not null).

public T[] GetNearby(Vector3 position, float maxDistance)

Parameters

position Vector3

The position. Passing as ref to improve performance since it won't have to be copied.

maxDistance float

Maximum distance from the position to consider.

Returns

T[]

Objects within range.

GetNearbyNonAlloc(Ray, float, List<T>)

Returns objects that are within maxDistance of the specified ray. If none, returns false. Uses supplied list for results.

public bool GetNearbyNonAlloc(Ray ray, float maxDistance, List<T> nearBy)

Parameters

ray Ray

The ray. Passing as ref to improve performance since it won't have to be copied.

maxDistance float

Maximum distance from the ray to consider

nearBy List<T>

Pre-initialized list to populate

Returns

bool

True if items are found, false if not

GetNearbyNonAlloc(Vector3, float, List<T>)

Returns objects that are within maxDistance of the specified position. If none, returns false. Uses supplied list for results.

public bool GetNearbyNonAlloc(Vector3 position, float maxDistance, List<T> nearBy)

Parameters

position Vector3
maxDistance float

Maximum distance from the position to consider

nearBy List<T>

Pre-initialized list to populate

Returns

bool

True if items are found, false if not

Remove(T, Vector3)

Removes the specified object at the given position. Makes the assumption that the object only exists once in the tree.

public bool Remove(T obj, Vector3 objPos)

Parameters

obj T

Object to remove.

objPos Vector3

Position of the object.

Returns

bool

True if the object was removed successfully.

Remove(T)

Remove an object. Makes the assumption that the object only exists once in the tree.

public bool Remove(T obj)

Parameters

obj T

Object to remove.

Returns

bool

True if the object was removed successfully.