Table of Contents

Class BoundsOctreeNode<T>

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

Type Parameters

T
Inheritance
object
BoundsOctreeNode<T>

Constructors

BoundsOctreeNode(float, float, float, Vector3)

Constructor.

public BoundsOctreeNode(float baseLengthVal, float minSizeVal, float loosenessVal, Vector3 centerVal)

Parameters

baseLengthVal float

Length of this node, not taking looseness into account.

minSizeVal float

Minimum size of nodes in this octree.

loosenessVal float

Multiplier for baseLengthVal to get the actual size.

centerVal Vector3

Centre position of this node.

Properties

BaseLength

public float BaseLength { get; }

Property Value

float

Center

public Vector3 Center { get; }

Property Value

Vector3

Methods

Add(T, Bounds)

Add an object.

public bool Add(T obj, Bounds objBounds)

Parameters

obj T

Object to add.

objBounds Bounds

3D bounding box around the object.

Returns

bool

True if the object fits entirely within this node.

BestFitChild(Vector3)

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

public int BestFitChild(Vector3 objBoundsCenter)

Parameters

objBoundsCenter Vector3

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.

public void DrawAllObjects()

GetBounds()

public Bounds GetBounds()

Returns

Bounds

GetColliding(ref Bounds, List<T>)

Returns an array of objects that intersect with the specified bounds, if any. Otherwise returns an empty array. See also: IsColliding.

public void GetColliding(ref Bounds checkBounds, List<T> result)

Parameters

checkBounds Bounds

Bounds to check. Passing by ref as it improves performance with structs.

result List<T>

List result.

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

Returns an array of objects that intersect with the specified ray, if any. Otherwise returns an empty array. See also: IsColliding.

public void GetColliding(ref Ray checkRay, List<T> result, float maxDistance = Infinity)

Parameters

checkRay Ray

Ray to check. Passing by ref as it improves performance with structs.

result List<T>

List result.

maxDistance float

Distance to check.

GetWithinFrustum(Plane[], List<T>)

public void GetWithinFrustum(Plane[] planes, List<T> result)

Parameters

planes Plane[]
result List<T>

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

IsColliding(ref Bounds)

Check if the specified bounds intersect with anything in the tree. See also: GetColliding.

public bool IsColliding(ref Bounds checkBounds)

Parameters

checkBounds Bounds

Bounds to check.

Returns

bool

True if there was a collision.

IsColliding(ref Ray, float)

Check if the specified ray intersects with anything in the tree. See also: GetColliding.

public bool IsColliding(ref Ray checkRay, float maxDistance = Infinity)

Parameters

checkRay Ray

Ray to check.

maxDistance float

Distance to check.

Returns

bool

True if there was a collision.

Remove(T, Bounds)

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, Bounds objBounds)

Parameters

obj T

Object to remove.

objBounds Bounds

3D bounding box around 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(BoundsOctreeNode<T>[])

Set the 8 children of this octree.

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

Parameters

childOctrees BoundsOctreeNode<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 BoundsOctreeNode<T> ShrinkIfPossible(float minLength)

Parameters

minLength float

Minimum dimensions of a node in this octree.

Returns

BoundsOctreeNode<T>

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