QuadTree3D
Package: Libraries.Game.Graphics.Trees · Inherits from: Libraries.Language.Object, Libraries.Game.Graphics.Trees.StaticDynamicRenderTree3D, Libraries.Game.Graphics.Trees.RenderTree3D
QuadTree3D is a render tree that divides the ground into squares, and each square into four smaller squares, as needed. Each square runs the full height of the region. It is a good choice for a scene that is mostly flat and spread out, such as terrain and the things on it. Set the region the squares 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 do not split the height. The squares themselves are made and searched by RenderCellTree3D, which Octree3D also uses. The squares 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.QuadTree3D
use Libraries.Interface.Item3D
use Libraries.Containers.Array
QuadTree3D tree
tree:SetRegion(-100, -10, -100, 100, 50, 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 square can be divided.
Returns
integer: The deepest level a square can be at.
SetMaximumDepth(integer depth)
This action sets how many times a square can be divided. Each level halves the size. Deeper squares fit small items more tightly, but searches visit more squares. 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 squares cover. The squares are as tall as the region, so its bottom and top should hold everything that is drawn. The top square is as wide as the region's wider side. 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)