StaticDynamicRenderTree3D
Package: Libraries.Game.Graphics.Trees · Inherits from: Libraries.Language.Object, Libraries.Game.Graphics.Trees.RenderTree3D
StaticDynamicRenderTree3D is the work shared by DynamicVolumeRenderTree3D, QuadTree3D and Octree3D. It keeps items in two parts, each a RenderTreePart3D: - The static part holds items that do not move, such as scenery and terrain chunks. - The dynamic part holds items that move. A static item that moves is moved to the dynamic part. A dynamic item that has not moved for a while is moved back to the static part by EndFrame. Because static items never move, what is worked out from them can be kept: the static items within each point light's reach are found once and remembered until the static part changes. The kinds of tree differ only in their parts. Each one makes its two parts and hands them to SetParts when it is created. This class is not meant to be used on its own.
Example Code
use Libraries.Game.Graphics.Trees.StaticDynamicRenderTree3D
use Libraries.Game.Graphics.Trees.DynamicVolumeRenderTree3D
use Libraries.Interface.Item3D
DynamicVolumeRenderTree3D volumeTree
StaticDynamicRenderTree3D tree = volumeTree
Item3D box
box:SetDimensions(1, 1, 1)
tree:Add(box)
box:SetPosition(3, 0, 0)
tree:Moved(box)
output tree:IsStatic(box)
Actions
Add(Libraries.Interface.Item3D item, Libraries.Game.BoundingBox localBounds, boolean isStatic)
This action adds an item with the given bounds in its own coordinates. Use it for items whose bounds the tree cannot find, such as terrain chunks. A terrain chunk should give bounds that hold every level of detail, so changing the level does not change the tree.
Parameters
itemLibraries.Interface.Item3D: The item to add.localBoundsLibraries.Game.BoundingBox: The item's bounds in its own coordinates.isStaticboolean: True if the item is not expected to move.
Returns
boolean: True if the item was added, false if it was already in
the tree.
CollectDirectionalShadowCasters(Libraries.Game.Graphics.DirectionalLight light, Libraries.Game.Graphics.Camera camera, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
This action adds the items that could cast a shadow from a directional light into view to the result: those within the light's culling range of the camera, or, if it has none, those that could cast a shadow into any of its cascades. See RenderTree3D.
Parameters
lightLibraries.Game.Graphics.DirectionalLight: The directional light.cameraLibraries.Game.Graphics.Camera: The camera the light's culling range is measured from.resultLibraries.Game.Graphics.Trees.RenderTree3DResult: The result to add the items to. It puts each item in its visible or invisible list by whether the camera can see it.
CollectDirectionalShadowCasters(Libraries.Game.Graphics.DirectionalLight light, integer cascade, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
This action adds the items that could cast a shadow into one cascade of a directional light's shadows to the result. A light without shadow data for the cascade, such as in OpenGL, adds nothing.
Parameters
lightLibraries.Game.Graphics.DirectionalLight: The directional light.cascadeinteger: Which cascade, counting from 0.resultLibraries.Game.Graphics.Trees.RenderTree3DResult: The result to add the items to. It puts each item in its visible or invisible list by whether the camera can see it.
CollectInBox(Libraries.Game.BoundingBox box, Libraries.Containers.Array<Libraries.Interface.Item3D> results)
This action adds the items overlapping a box to the results.
Parameters
boxLibraries.Game.BoundingBox: The box, in world coordinates.resultsLibraries.Containers.Array<Libraries.Interface.Item3D>: The array to add the items to.
CollectInSphere(number x, number y, number z, number radius, Libraries.Containers.Array<Libraries.Interface.Item3D> results)
This action adds the items overlapping a sphere to the results.
Parameters
xnumber: The x coordinate of the sphere's center.ynumber: The y coordinate of the sphere's center.znumber: The z coordinate of the sphere's center.radiusnumber: The sphere's radius.resultsLibraries.Containers.Array<Libraries.Interface.Item3D>: The array to add the items to.
CollectPointShadowCasters(Libraries.Game.Graphics.PointLight light, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
This action adds the items within a point light's culling range to the result. Static items are found once and remembered, until the light moves, its culling range changes, or the static part changes.
Parameters
lightLibraries.Game.Graphics.PointLight: The point light.resultLibraries.Game.Graphics.Trees.RenderTree3DResult: The result to add the items to. It puts each item in its visible or invisible list by whether the camera can see it.
CollectVisible(Libraries.Compute.Matrix4 viewProjection, Libraries.Game.Graphics.Trees.RenderTree3DResult result)
This action adds the items inside the view of the given view-projection matrix to the result.
Parameters
viewProjectionLibraries.Compute.Matrix4: The view-projection matrix.resultLibraries.Game.Graphics.Trees.RenderTree3DResult: The result to add the items to. It puts each item in its visible or invisible list by whether the camera can see it.
CollectsPointShadowCasters()
This action returns true: this tree finds the items near a point light (CollectPointShadowCasters), so each point light draws only those into its shadows.
Returns
boolean: True.
Empty()
This action removes every item, and forgets what was remembered for point lights.
EndFrame()
This action ends a frame. Call it once per frame, after drawing. Every CHECK_INTERVAL frames, dynamic items that have not moved for FRAMES_UNTIL_STATIC frames are moved to the static part.
GetDynamicHeight()
This action returns how many levels the dynamic part has below its top, or -1 when it is empty.
Returns
integer: The number of levels.
GetDynamicSize()
This action returns how many items are in the dynamic part.
Returns
integer: The number of dynamic items.
GetFirstLeaf()
This action returns the first leaf: the first in the static part, or in the dynamic part if the static part is empty.
Returns
Libraries.Game.Graphics.Trees.RenderTreeNode3D: The first leaf, or undefined when the tree is empty.
GetLeaf(Libraries.Interface.Item3D item)
This action returns the leaf that holds an item, or undefined if the item is not in the tree. See RenderTree3D for how to use it.
Parameters
itemLibraries.Interface.Item3D: The item to find.
Returns
Libraries.Game.Graphics.Trees.RenderTreeNode3D: The item's leaf, or undefined if it is not in the tree.
GetNextLeaf(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)
This action returns the leaf after the given one. The static part's leaves come first, then the dynamic part's.
Parameters
leafLibraries.Game.Graphics.Trees.RenderTreeNode3D: A leaf in this tree.
Returns
Libraries.Game.Graphics.Trees.RenderTreeNode3D: The next leaf, or undefined after the last.
GetSize()
This action returns how many items are in the tree.
Returns
integer: The number of items.
GetStaticHeight()
This action returns how many levels the static part has below its top, or -1 when it is empty.
Returns
integer: The number of levels.
GetStaticSize()
This action returns how many items are in the static part.
Returns
integer: The number of static items.
GetStaticVersion()
This action returns a number that goes up by one every time the static part changes: when an item is added to it or removed from it, when a static item moves and goes to the dynamic part, when a still item comes back from the dynamic part, or when the tree is emptied. The tree uses it itself for point light shadow casters.
Returns
integer: The static version.
Has(Libraries.Interface.Item3D item)
This action returns true if the item is in the tree.
Parameters
itemLibraries.Interface.Item3D: The item to look for.
Returns
boolean: True if the item is in the tree.
IsStatic(Libraries.Interface.Item3D item)
This action returns true if the item is in the static part, and false if it is in the dynamic part or not in the tree.
Parameters
itemLibraries.Interface.Item3D: The item.
Returns
boolean: True if the item is static.
Moved(Libraries.Interface.Item3D item)
This action tells the tree an item's position, rotation or scale has changed. It looks up the item's leaf each time. Moved(leaf) does not.
Parameters
itemLibraries.Interface.Item3D: The item that moved.
Moved(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)
This action tells the tree a leaf's item has moved. A static item that has really moved goes to the dynamic part. A leaf whose item has been removed is ignored.
Parameters
leafLibraries.Game.Graphics.Trees.RenderTreeNode3D: The leaf GetLeaf returned for the item.
Remove(Libraries.Interface.Item3D item)
This action removes an item. If the item is a point light, the static shadow casters remembered for it are also forgotten.
Parameters
itemLibraries.Interface.Item3D: The item to remove.
Returns
boolean: True if the item was in the tree.
SetLocalBounds(Libraries.Interface.Item3D item, Libraries.Game.BoundingBox localBounds)
This action changes an item's bounds in its own coordinates, for example when its mesh or its level of detail changes. It counts as a move.
Parameters
itemLibraries.Interface.Item3D: The item whose bounds changed.localBoundsLibraries.Game.BoundingBox: The item's new bounds in its own coordinates.
SetParts(Libraries.Game.Graphics.Trees.RenderTreePart3D staticItems, Libraries.Game.Graphics.Trees.RenderTreePart3D dynamicItems)
This action sets the two parts. Each kind of tree calls it once, when it is created. It is not meant to be called from anywhere else.
Parameters
staticItemsLibraries.Game.Graphics.Trees.RenderTreePart3D: The part for items that do not move.dynamicItemsLibraries.Game.Graphics.Trees.RenderTreePart3D: The part for items that move.
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)