Options
All
  • Public
  • Public/Protected
  • All
Menu

Class 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

  • new Octree(creationFunc: (entry: T, block: OctreeBlock<T>) => void, maxBlockCapacity?: number, maxDepth?: number): Octree
  • Parameters

    • creationFunc: (entry: T, block: OctreeBlock<T>) => void

      function to be used to instantiate 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

blocksSearch playground for blocks

blocks: Array<OctreeBlock<T>>

Blocks within the octree containing objects

dynamicContentSearch playground for dynamicContent

dynamicContent: T[]

Content stored in the octree

maxDepthSearch playground for maxDepth

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 CreationFuncForMeshesSearch playground for CreationFuncForMeshes

CreationFuncForMeshes: (entry: AbstractMesh, block: OctreeBlock<AbstractMesh>) => void

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

param
param

Type declaration

Static CreationFuncForSubMeshesSearch playground for CreationFuncForSubMeshes

CreationFuncForSubMeshes: (entry: SubMesh, block: OctreeBlock<SubMesh>) => void

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

param
param

Type declaration

Methods

addMeshSearch playground for addMesh

  • addMesh(entry: T): void
  • Adds a mesh to the octree

    Parameters

    • entry: T

      Mesh to add to the octree

    Returns void

intersectsSearch playground for intersects

  • 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

intersectsRaySearch playground for intersectsRay

  • 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

removeMeshSearch playground for removeMesh

  • removeMesh(entry: T): void
  • Remove an element from the octree

    Parameters

    • entry: T

      defines the element to remove

    Returns void

selectSearch playground for select

  • 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

updateSearch playground for update

  • 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

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method