Class Octree<T>

An octree that subdivides space for fast spatial searches.

This linear implementation offers constant time access to octants at any depth level as well as octant neighbours and parent nodes.

Type Parameters

  • T

    The type of the octant data.

Implements

Constructors

  • Constructs a new octree.

    Each octant can be uniquely identified by a 3D coordinate and a level. The tree depth is defined by the highest number of bits in the key design.

    If the bounds of the octree are defined directly, the cell size will depend on the bounds and the key design. Alternatively, the bounds can be calculated from a desired cell size via KeyDesign.calculateBounds.

    Type Parameters

    • T

    Parameters

    • bounds: Box3

      The bounds of the octree.

    • keyDesign: KeyDesign = ...

      The bit allotments for the octant coordinates.

    Returns Octree<T>

Properties

The root node of this octree.

Accessors

Methods

  • Calculates key coordinates based on a given position and level.

    Parameters

    • position: Vector3

      A position.

    • level: number

      The level.

    • result: Vector3

      A vector to store the result in.

    Returns Vector3

    The key coordinates.

  • Checks if the given point lies inside this octree's boundaries.

    Parameters

    Returns boolean

    Whether the given point lies inside this octree.

  • Removes a specific octant.

    Children and empty intermediate parent octants will be removed as well.

    Parameters

    • keyCoordinates: Vector3

      The key coordinates of the octant that should be removed.

    • level: number = 0

      The level of the octant.

    Returns void

  • Parameters

    • level: number

    Returns Node[]

  • Retrieves data from a specific octant.

    Parameters

    • keyCoordinates: Vector3

      The key coordinates of the octant.

    • level: number

      The level of the octant.

    Returns undefined | null | T

    The data, or undefined if the octant doesn't exist.

  • Returns the size of the cells in the specified grid.

    Parameters

    • level: number

      The level. Must be a positive integer.

    • result: Vector3

      A vector to store the result in.

    Returns Vector3

    The cell size.

  • Returns number

  • Returns the grid of the specified level.

    Parameters

    • level: number

      The level of the grid.

    Returns Map<number, Octant<T>>

    The requested grid.

    Throws

    If the given level is out of bounds.

  • Finds nodes that intersect with the given ray. The intersecting nodes are sorted by distance, closest first.

    Parameters

    Returns OctantWrapper<T>[]

    The intersecting nodes.

  • Returns the amount of depth levels.

    Returns number

    The levels.

  • Retrieves an octant of a specific level that contains the given point.

    Parameters

    • point: Vector3

      A point.

    • level: number = 0

      The level.

    Returns undefined | Octant<T>

    The octant, or undefined if it doesn't exist.

  • Adds data to a specific octant.

    Missing intermediate octants will be created automatically.

    Parameters

    • keyCoordinates: Vector3

      The key coordinates of the octant.

    • level: number

      The level of the octant.

    • data: null | T

      The data.

    Returns void