Class Octree<T>
Type Parameters
- T
Constructors
constructor
-
new Octree<T>(
creationFunc: (entry: T, block: OctreeBlock<T>) => void,
maxBlockCapacity?: number,
maxDepth?: number,
): Octree<T>Creates a octree
Type Parameters
- T
Parameters
- creationFunc: (entry: T, block: OctreeBlock<T>) => void
function to be used to instantiate the octree
OptionalmaxBlockCapacity: numberdefines the maximum number of meshes you want on your octree's leaves (default: 64)
- maxDepth: number = 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.)
Returns Octree<T>
Properties
blocks
Blocks within the octree containing objects
dynamic Content
Content stored in the octree
max Depth
[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.)
Methods
add Mesh
intersects
-
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: booleandefines if the selection array can contains duplicated entries
Returns SmartArray<T>
an array of objects that intersect the sphere
- sphereCenter: Vector3
intersects Ray
-
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
- ray: Ray
remove Mesh
select
-
Selects an array of meshes within the frustum
Parameters
- frustumPlanes: Plane[]
The frustum planes to use which will select all meshes within it
OptionalallowDuplicate: booleanIf duplicate objects are allowed in the resulting object array
Returns SmartArray<T>
array of meshes within the frustum
- frustumPlanes: Plane[]
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
- worldMin: Vector3
StaticCreation Func For Meshes
-
Adds a mesh into the octree block if it intersects the block
Parameters
- entry: AbstractMesh
defines the mesh to try to add to the block
- block: OctreeBlock<AbstractMesh>
defines the block where the mesh should be added
Returns void
- entry: AbstractMesh
StaticCreation Func For Sub Meshes
-
Adds a submesh into the octree block if it intersects the block
Parameters
- entry: SubMesh
defines the submesh to try to add to the block
- block: OctreeBlock<SubMesh>
defines the block where the submesh should be added
Returns void
- entry: SubMesh
Octrees are a really powerful data structure that can quickly select entities based on space coordinates.
See
https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees