Octree<T>

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

see

https://doc.babylonjs.com/how_to/optimizing_your_scene_with_octrees

Type parameters

  • T

Hierarchy

  • Octree

Index

Constructors

constructor

Find examples in Playground
  • new Octree(creationFunc: function, maxBlockCapacity?: number, maxDepth?: number): Octree
  • Parameters

    • creationFunc: function

      function to be used to instatiate the octree

    • Optional maxBlockCapacity: number

      defines the maximum number of meshes you want on your octree's leaves (default: 64)

    • Optional maxDepth: number

      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.)

    Returns Octree

Properties

blocks

Find examples in Playground
blocks: Array<OctreeBlock<T>>

Blocks within the octree containing objects

dynamicContent

Find examples in Playground
dynamicContent: T[]

Content stored in the octree

maxDepth

Find examples in Playground
maxDepth: number

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.)

Static CreationFuncForMeshes

Find examples in Playground
CreationFuncForMeshes: function

Adds a mesh into the octree block if it intersects the block

Type declaration

Static CreationFuncForSubMeshes

Find examples in Playground
CreationFuncForSubMeshes: function

Adds a submesh into the octree block if it intersects the block

Type declaration

Methods

addMesh

Find examples in Playground
  • addMesh(entry: T): void
  • Adds a mesh to the octree

    Parameters

    • entry: T

      Mesh to add to the octree

    Returns void

intersects

Find examples in Playground
  • intersects(sphereCenter: Vector3, sphereRadius: number, allowDuplicate?: boolean): SmartArray<T>
  • 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

    • Optional allowDuplicate: boolean

      defines if the selection array can contains duplicated entries

    Returns SmartArray<T>

    an array of objects that intersect the sphere

intersectsRay

Find examples in Playground
  • Test if the octree intersect with the given ray and if yes, then add its content to resulting array

    Parameters

    • ray: Ray

      defines the ray to test with

    Returns SmartArray<T>

    array of intersected objects

select

Find examples in Playground
  • Selects an array of meshes within the frustum

    Parameters

    • frustumPlanes: Plane[]

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

    • Optional allowDuplicate: boolean

      If duplicate objects are allowed in the resulting object array

    Returns SmartArray<T>

    array of meshes within the frustum

update

Find examples in Playground
  • 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

Generated using TypeDoc