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

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

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

CollectInBox(Libraries.Game.BoundingBox box, Libraries.Containers.Array<Libraries.Interface.Item3D> results)

This action adds the items overlapping a box to the results.

Parameters

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

  • x number: The x coordinate of the sphere's center.
  • y number: The y coordinate of the sphere's center.
  • z number: The z coordinate of the sphere's center.
  • radius number: The sphere's radius.
  • results Libraries.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

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

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

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

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

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

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

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

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

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

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

Inherited Actions

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