Octree3D

Package: Libraries.Game.Graphics.Trees · Inherits from: Libraries.Language.Object, Libraries.Game.Graphics.Trees.StaticDynamicRenderTree3D, Libraries.Game.Graphics.Trees.RenderTree3D

Octree3D is a render tree that divides space into cubes, and each cube into eight smaller cubes, as needed. It is a good choice for a scene spread out in every direction, such as space, or a city with tall buildings. Set the region the cubes cover with SetRegion, ideally before adding items. Items outside the region still work, but are tested one by one. Its two parts are RenderCellTree3D grids that split all three directions. The cubes themselves are made and searched by RenderCellTree3D, which QuadTree3D also uses. The cubes are loose, so an item is placed by its center and size alone, and moving an item rarely changes the tree. Everything else, the actions every render tree has, comes from StaticDynamicRenderTree3D.

Example Code

use Libraries.Game.Graphics.Trees.Octree3D
use Libraries.Interface.Item3D
use Libraries.Containers.Array

Octree3D tree
tree:SetRegion(-100, -100, -100, 100, 100, 100)
Item3D box
box:SetDimensions(1, 1, 1)
tree:Add(box)
Array<Item3D> found
tree:CollectInSphere(0, 0, 0, 5, found)
output found:GetSize()

Actions

GetMaximumDepth()

This action returns how many times a cube can be divided.

Returns

integer: The deepest level a cube can be at.

SetMaximumDepth(integer depth)

This action sets how many times a cube can be divided. Each level halves the size. Deeper cubes fit small items more tightly, but searches visit more cubes. The default is 8. Items already in the tree are placed again.

Parameters

  • depth integer: The deepest level, at least 0.

SetRegion(number minimumX, number minimumY, number minimumZ, number maximumX, number maximumY, number maximumZ)

This action sets the region of the world the cubes cover. The top cube is as big as the region's largest side, centered on the region. Items already in the tree are placed again.

Parameters

  • minimumX number: The smallest x of the region.
  • minimumY number: The smallest y of the region.
  • minimumZ number: The smallest z of the region.
  • maximumX number: The largest x of the region.
  • maximumY number: The largest y of the region.
  • maximumZ number: The largest z of the region.

Inherited Actions

7 actions from Libraries.Game.Graphics.Trees.RenderTree3D
26 actions from Libraries.Game.Graphics.Trees.StaticDynamicRenderTree3D
3 actions from Libraries.Language.Object