API

Class Octree<T>

Octrees are a really powerful data structure that can quickly select entities based on space coordinates.

Type Parameters

  • T
Index
blocks: OctreeBlock<T>[]

Blocks within the octree containing objects

dynamicContent: T[] = []

Content stored in the octree

maxDepth: number = 2

[2] Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)

  • Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array

    Parameters

    • sphereCenter: Vector3

      defines the bounding sphere center

    • sphereRadius: number

      defines the bounding sphere radius

    • OptionalallowDuplicate: boolean

      defines if the selection array can contains duplicated entries

    Returns SmartArray<T>

    an array of objects that intersect the sphere

  • Selects an array of meshes within the frustum

    Parameters

    • frustumPlanes: Plane[]

      The frustum planes to use which will select all meshes within it

    • OptionalallowDuplicate: boolean

      If duplicate objects are allowed in the resulting object array

    Returns SmartArray<T>

    array of meshes within the frustum

  • Updates the octree by adding blocks for the passed in meshes within the min and max world parameters

    Parameters

    • worldMin: Vector3

      worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);

    • worldMax: Vector3

      worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);

    • entries: T[]

      meshes to be added to the octree blocks

    Returns void