Table of Contents

Class PointOctreeNode<T>

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

Type Parameters

T
Inheritance
object
PointOctreeNode<T>

Constructors

PointOctreeNode(float, float, Vector3)

Constructor.

public PointOctreeNode(float baseLengthVal, float minSizeVal, Vector3 centerVal)

Parameters

baseLengthVal float

Length of this node, not taking looseness into account.

minSizeVal float

Minimum size of nodes in this octree.

centerVal Vector3

Centre position of this node.

Properties

Center

public Vector3 Center { get; }

Property Value

Vector3

SideLength

public float SideLength { get; }

Property Value

float

Methods

Add(T, Vector3)

Add an object.

public bool Add(T obj, Vector3 objPos)

Parameters

obj T

Object to add.

objPos Vector3

Position of the object.

Returns

bool

BestFitChild(Vector3)

Find which child node this object would be most likely to fit in.

public int BestFitChild(Vector3 objPos)

Parameters

objPos Vector3

The object's position.

Returns

int

One of the eight child octants.

DrawAllBounds(float)

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

public void DrawAllBounds(float depth = 0)

Parameters

depth float

Used for recurcive calls to this method.

DrawAllObjects()

Draws the bounds of all objects in the tree visually for debugging. Must be called from OnDrawGizmos externally. See also: DrawAllBounds. NOTE: marker.tif must be placed in your Unity /Assets/Gizmos subfolder for this to work.

public void DrawAllObjects()

GetAll(List<T>)

Return all objects in the tree.

public void GetAll(List<T> result)

Parameters

result List<T>

GetNearby(ref Ray, float, List<T>)

Return objects that are within maxDistance of the specified ray.

public void GetNearby(ref Ray ray, float maxDistance, List<T> result)

Parameters

ray Ray

The ray.

maxDistance float

Maximum distance from the ray to consider.

result List<T>

List result.

GetNearby(ref Vector3, float, List<T>)

Return objects that are within maxDistance of the specified position.

public void GetNearby(ref Vector3 position, float maxDistance, List<T> result)

Parameters

position Vector3

The position.

maxDistance float

Maximum distance from the position to consider.

result List<T>

List result.

HasAnyObjects()

Checks if this node or anything below it has something in it.

public bool HasAnyObjects()

Returns

bool

True if this node or any of its children, grandchildren etc have something in them

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.

SetChildren(PointOctreeNode<T>[])

Set the 8 children of this octree.

public void SetChildren(PointOctreeNode<T>[] childOctrees)

Parameters

childOctrees PointOctreeNode<T>[]

The 8 new child nodes.

ShrinkIfPossible(float)

We can shrink the octree if:

  • This node is >= double minLength in length
  • All objects in the root node are within one octant
  • This node doesn't have children, or does but 7/8 children are empty We can also shrink it if there are no objects left at all!
public PointOctreeNode<T> ShrinkIfPossible(float minLength)

Parameters

minLength float

Minimum dimensions of a node in this octree.

Returns

PointOctreeNode<T>

The new root, or the existing one if we didn't shrink.

SqrDistanceToRay(Ray, Vector3)

Returns the closest distance to the given ray from a point.

public static float SqrDistanceToRay(Ray ray, Vector3 point)

Parameters

ray Ray

The ray.

point Vector3

The point to check distance from the ray.

Returns

float

Squared distance from the point to the closest point of the ray.