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
depthinteger: 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
minimumXnumber: The smallest x of the region.minimumYnumber: The smallest y of the region.minimumZnumber: The smallest z of the region.maximumXnumber: The largest x of the region.maximumYnumber: The largest y of the region.maximumZnumber: The largest z of the region.
Inherited Actions
7 actions from Libraries.Game.Graphics.Trees.RenderTree3D
- Add(Libraries.Interface.Item3D item, Libraries.Game.BoundingBox localBounds)
- Add(Libraries.Interface.Item3D item, boolean isStatic)
- Add(Libraries.Interface.Item3D item)
- CollectVisible(Libraries.Game.Graphics.Camera camera, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
- GetIterator()
- IsShowing(Libraries.Interface.Item3D item)
- IsShowingWithParents(Libraries.Interface.Item3D item)
26 actions from Libraries.Game.Graphics.Trees.StaticDynamicRenderTree3D
- Add(Libraries.Interface.Item3D item, Libraries.Game.BoundingBox localBounds, boolean isStatic)
- CollectDirectionalShadowCasters(Libraries.Game.Graphics.DirectionalLight light, Libraries.Game.Graphics.Camera camera, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
- CollectDirectionalShadowCasters(Libraries.Game.Graphics.DirectionalLight light, integer cascade, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
- CollectInBox(Libraries.Game.BoundingBox box, Libraries.Containers.Array<Libraries.Interface.Item3D> results)
- CollectInSphere(number x, number y, number z, number radius, Libraries.Containers.Array<Libraries.Interface.Item3D> results)
- CollectPointShadowCasters(Libraries.Game.Graphics.PointLight light, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
- CollectVisible(Libraries.Compute.Matrix4 viewProjection, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
- CollectsPointShadowCasters()
- Empty()
- EndFrame()
- GetDynamicHeight()
- GetDynamicSize()
- GetFirstLeaf()
- GetLeaf(Libraries.Interface.Item3D item)
- GetNextLeaf(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)
- GetSize()
- GetStaticHeight()
- GetStaticSize()
- GetStaticVersion()
- Has(Libraries.Interface.Item3D item)
- IsStatic(Libraries.Interface.Item3D item)
- Moved(Libraries.Interface.Item3D item)
- Moved(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)
- Remove(Libraries.Interface.Item3D item)
- SetLocalBounds(Libraries.Interface.Item3D item, Libraries.Game.BoundingBox localBounds)
- SetParts(Libraries.Game.Graphics.Trees.RenderTreePart3D staticItems, Libraries.Game.Graphics.Trees.RenderTreePart3D dynamicItems)