RenderTreeNode3D

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

RenderTreeNode3D is the record a render tree keeps for each item: the item, its bounds, and which half of the tree it is in. It is called a leaf. In a RenderBoundingVolumeTree3D, nodes are also the tree itself. A node is either a leaf, which holds one drawable item and the box around it, or a branch, which holds two children and the box around both. The parent, left, right and height fields are used only there. In a RenderCellTree3D, used by QuadTree3D and Octree3D, a leaf instead records the cell it is in and its place in that cell's list, so it can be removed without searching. Only the tree classes in this package should change a node. The node also does the box calculations the trees need, such as finding its item's bounds in the world, so each tree asks the node rather than sharing private helpers. A node's box can be read two ways. GetBounds returns the node's own box, not a copy, so changing it changes the node. The tree uses it to update boxes in place without making new objects. GetBoundsCopy returns a new box with the same corners, which can be changed freely, but makes a new object on every call.

Example Code

use Libraries.Game.Graphics.Trees.DynamicVolumeRenderTree3D
use Libraries.Game.Graphics.Trees.RenderTreeNode3D
use Libraries.Interface.Item3D

DynamicVolumeRenderTree3D tree
Item3D box
box:SetDimensions(1, 1, 1)
tree:Add(box)

// Keep the leaf, so moves need no lookup.
RenderTreeNode3D leaf = tree:GetLeaf(box)
box:SetPosition(2, 0, 0)
tree:Moved(leaf)
output leaf:GetBounds():GetCenterX()

Actions

CalculateWorldBounds(Libraries.Game.BoundingBox out)

This action puts the leaf's item's bounds in world coordinates into the given box. The item's bounds in its own coordinates are a center and half sizes. The world center is the item's transform applied to the center. The world half size on each axis is the sum of the absolute values of the transform's entries in that row, each times the matching half size. This is the smallest axis-aligned box around the turned box, and needs no corners. The transform includes the item's scale and its parent's offset.

Parameters

Contains(Libraries.Game.BoundingBox box)

This action returns true if the node's box holds all of the given box. Equal edges count as inside, so a flat item, such as a plane, fits a box of the same size.

Parameters

Returns

boolean: True if the node's box holds all of it.

DistanceSquared(number x, number y, number z)

This action returns the squared distance from a point to the nearest point of the node's box, which is 0 when the point is inside it.

Parameters

  • x number: The point's x coordinate.
  • y number: The point's y coordinate.
  • z number: The point's z coordinate.

Returns

number: The squared distance.

GetAddedFrame()

This action returns the frame of the result this leaf's item was last added to, or -1 if it never has been.

Returns

integer: The frame number, or -1.

GetAddedSearch()

This action returns the search count of the result this leaf's item was last added to, or -1 if it never has been.

Returns

integer: The search count, or -1.

GetBounds()

This action returns the box this node covers. The box itself is returned, not a copy, so changing it changes the node. The tree uses this to update boxes in place without making new objects. To look at the box without any risk of changing the node, use GetBoundsCopy.

Returns

Libraries.Game.BoundingBox: The node's own box, not a copy.

GetBoundsCopy()

This action returns a new box with the same corners as the box this node covers. Changing the copy does not change the node. Each call makes a new object, so code that runs every frame should use GetBounds instead, and only read from it.

Returns

Libraries.Game.BoundingBox: A copy of the node's box.

GetCell()

This action returns the RenderCellTree3D cell the leaf is in, or undefined if it is in none.

Returns

Libraries.Game.Graphics.Trees.RenderTreeCell3D: The cell, or undefined.

GetCellIndex()

This action returns the leaf's place in its cell's list of leaves, or in the cell tree's list of leaves outside its region, or -1 if it is in neither.

Returns

integer: The leaf's place, or -1.

GetHeight()

This action returns how many levels are below this node. A leaf is 0.

Returns

integer: The number of levels below this node.

GetItem()

This action returns the item a leaf holds, or undefined for a branch or for a leaf whose item has been removed.

Returns

Libraries.Interface.Item3D: The item, or undefined.

GetLastDrawnFrame()

This action returns the last frame the leaf's item was handed to be drawn, or -1 if it never has been. The tree does not use this. It is kept for the tree's owner, such as Layer3D, so an item found by more than one search in a frame is only drawn once.

Returns

integer: The frame number, or -1.

GetLastMovedFrame()

This action returns the frame the leaf last moved on. The tree uses it to move still items back to the static half.

Returns

integer: The frame number.

GetLeft()

This action returns the first child of a branch, or undefined for a leaf.

Returns

Libraries.Game.Graphics.Trees.RenderTreeNode3D: The first child, or undefined.

GetLocalCenterX()

This action returns the x coordinate of the center of the item's bounds, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: The x coordinate of the center.

GetLocalCenterY()

This action returns the y coordinate of the center of the item's bounds, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: The y coordinate of the center.

GetLocalCenterZ()

This action returns the z coordinate of the center of the item's bounds, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: The z coordinate of the center.

GetLocalHalfX()

This action returns half the size of the item's bounds along x, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: Half the size along x.

GetLocalHalfY()

This action returns half the size of the item's bounds along y, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: Half the size along y.

GetLocalHalfZ()

This action returns half the size of the item's bounds along z, in the item's own coordinates. It is set with SetLocalBounds.

Returns

number: Half the size along z.

GetParentNode()

This action returns the branch above this node, or undefined if this node is the root or is in a RenderCellTree3D.

Returns

Libraries.Game.Graphics.Trees.RenderTreeNode3D: The branch above this node, or undefined.

GetRight()

This action returns the second child of a branch, or undefined for a leaf.

Returns

Libraries.Game.Graphics.Trees.RenderTreeNode3D: The second child, or undefined.

HasBounds(Libraries.Game.BoundingBox box)

This action returns true if the node's box has the same corners as the given box.

Parameters

Returns

boolean: True if the corners are the same.

IsLeaf()

This action returns true if this node is a leaf, which holds an item, and false if it is a branch.

Returns

boolean: True if this node is a leaf.

IsStatic()

This action returns true if the leaf is in the static half of the tree.

Returns

boolean: True if the leaf is static.

Reset()

This action clears the node so it can be reused for another item or branch.

SetAddedFrame(integer frame)

This action sets the frame of the result this leaf's item was added to.

Parameters

  • frame integer: The result's frame number.

SetAddedSearch(integer search)

This action sets the search count of the result this leaf's item was added to.

Parameters

  • search integer: The result's search count.

SetBounds(Libraries.Game.BoundingBox itemBounds, number margin)

This action sets the node's box to the item's bounds, made bigger by the margin on every side.

Parameters

  • itemBounds Libraries.Game.BoundingBox: The item's bounds in the world.
  • margin number: How much bigger to make the box on every side.

SetCell(Libraries.Game.Graphics.Trees.RenderTreeCell3D value)

This action sets the RenderCellTree3D cell the leaf is in.

Parameters

SetCellIndex(integer index)

This action sets the leaf's place in its cell's list of leaves, or in the cell tree's list of leaves outside its region.

Parameters

  • index integer: The leaf's place, or -1 if it is in neither.

SetHeight(integer value)

This action sets how many levels are below this node.

Parameters

  • value integer: The number of levels below this node.

SetItem(Libraries.Interface.Item3D value)

This action sets the item a leaf holds.

Parameters

SetLastDrawnFrame(integer frame)

This action sets the last frame the leaf's item was handed to be drawn.

Parameters

  • frame integer: The frame number.

SetLastMovedFrame(integer frame)

This action sets the frame the leaf last moved on.

Parameters

  • frame integer: The frame number.

SetLeft(Libraries.Game.Graphics.Trees.RenderTreeNode3D node)

This action sets the first child of a branch.

Parameters

SetLocalBounds(Libraries.Game.BoundingBox local)

This action sets the item's bounds in its own coordinates. They are kept as a center and half sizes, and turned into world bounds each time the item moves.

Parameters

SetParentNode(Libraries.Game.Graphics.Trees.RenderTreeNode3D node)

This action sets the branch above this node.

Parameters

SetRight(Libraries.Game.Graphics.Trees.RenderTreeNode3D node)

This action sets the second child of a branch.

Parameters

SetStatic(boolean value)

This action sets whether the leaf is in the static half of the tree.

Parameters

  • value boolean: True if the leaf is static.

Inherited Actions

3 actions from Libraries.Language.Object