Class PointOctreeNode<T>
- Namespace
- VoxelPlayground.Utility
- Assembly
- GamePlay.dll
public class PointOctreeNode<T>
Type Parameters
T
- Inheritance
-
objectPointOctreeNode<T>
Constructors
PointOctreeNode(float, float, Vector3)
Constructor.
public PointOctreeNode(float baseLengthVal, float minSizeVal, Vector3 centerVal)
Parameters
baseLengthValfloatLength of this node, not taking looseness into account.
minSizeValfloatMinimum size of nodes in this octree.
centerValVector3Centre position of this node.
Properties
Center
public Vector3 Center { get; }
Property Value
SideLength
public float SideLength { get; }
Property Value
- float
Methods
Add(T, Vector3)
Add an object.
public bool Add(T obj, Vector3 objPos)
Parameters
objTObject to add.
objPosVector3Position 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
objPosVector3The 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
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. 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
resultList<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
rayRayThe ray.
maxDistancefloatMaximum distance from the ray to consider.
resultList<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
positionVector3The position.
maxDistancefloatMaximum distance from the position to consider.
resultList<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
objTObject to remove.
objPosVector3Position 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
objTObject 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
childOctreesPointOctreeNode<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
minLengthfloatMinimum 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
Returns
- float
Squared distance from the point to the closest point of the ray.