Class BoundsOctreeNode<T>
- Namespace
- VoxelPlayground.Utility
- Assembly
- GamePlay.dll
public class BoundsOctreeNode<T>
Type Parameters
T
- Inheritance
-
objectBoundsOctreeNode<T>
Constructors
BoundsOctreeNode(float, float, float, Vector3)
Constructor.
public BoundsOctreeNode(float baseLengthVal, float minSizeVal, float loosenessVal, Vector3 centerVal)
Parameters
baseLengthValfloatLength of this node, not taking looseness into account.
minSizeValfloatMinimum size of nodes in this octree.
loosenessValfloatMultiplier for baseLengthVal to get the actual size.
centerValVector3Centre position of this node.
Properties
BaseLength
public float BaseLength { get; }
Property Value
- float
Center
public Vector3 Center { get; }
Property Value
Methods
Add(T, Bounds)
Add an object.
public bool Add(T obj, Bounds objBounds)
Parameters
objTObject to add.
objBoundsBounds3D 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
objBoundsCenterVector3
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
depthfloatUsed 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
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
checkBoundsBoundsBounds to check. Passing by ref as it improves performance with structs.
resultList<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
checkRayRayRay to check. Passing by ref as it improves performance with structs.
resultList<T>List result.
maxDistancefloatDistance to check.
GetWithinFrustum(Plane[], List<T>)
public void GetWithinFrustum(Plane[] planes, List<T> result)
Parameters
planesPlane[]resultList<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
checkBoundsBoundsBounds 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
checkRayRayRay to check.
maxDistancefloatDistance 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
objTObject to remove.
objBoundsBounds3D 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
objTObject 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
childOctreesBoundsOctreeNode<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
minLengthfloatMinimum dimensions of a node in this octree.
Returns
- BoundsOctreeNode<T>
The new root, or the existing one if we didn't shrink.