RenderTreeCell3D

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

RenderTreeCell3D is one cell of a RenderCellTree3D, the part used by QuadTree3D and Octree3D. A cell is a square (in a quadtree) or a cube (in an octree) of the world. It holds the leaves of the items that fit in it but not in one of its smaller children, and it can be split into 4 or 8 children, each half its size. The cell is "loose": the box used to test it against a view is twice its size, centered on the same point. An item is placed by its center, so an item up to the size of a cell always fits inside that cell's loose box, even when it crosses the cell's edge. In a quadtree, the loose box runs the full height of the tree's region. The cell counts the leaves in it and in all of its children, so a search can skip a cell with nothing in it.

Example Code

use Libraries.Game.Graphics.Trees.RenderTreeCell3D

// A cube 10 wide centered on the origin. Its loose box is 20 wide.
RenderTreeCell3D cell
cell:SetPlace(0, 0, 0, 10, -10, 10)
output cell:DistanceSquared(13, 0, 0)

Actions

AddChild(Libraries.Game.Graphics.Trees.RenderTreeCell3D child)

This action adds a child to the cell. RenderCellTree3D adds them in the order its ChildIndex action expects.

Parameters

AddLeaf(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)

This action puts a leaf in this cell and records the cell and the leaf's place on the leaf. The counts are not changed; see AddToCount.

Parameters

AddToCount(integer change)

This action changes the count of leaves in this cell and every cell above it.

Parameters

  • change integer: How much to add, such as 1 or -1.

DistanceSquared(number x, number y, number z)

This action returns the squared distance from a point to the nearest point of the cell's loose 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.

GetBounds()

This action returns the cell's loose box, which is twice its size. The box itself is returned, not a copy, so it should only be read.

Returns

Libraries.Game.BoundingBox: The cell's loose box.

GetCenterX()

This action returns the x coordinate of the cell's center.

Returns

number: The x coordinate of the center.

GetCenterY()

This action returns the y coordinate of the cell's center.

Returns

number: The y coordinate of the center.

GetCenterZ()

This action returns the z coordinate of the cell's center.

Returns

number: The z coordinate of the center.

GetChild(integer index)

This action returns one of the cell's children.

Parameters

  • index integer: Which child, counting from 0.

Returns

Libraries.Game.Graphics.Trees.RenderTreeCell3D: The child.

GetChildCount()

This action returns how many children the cell has: 0, 4 or 8.

Returns

integer: The number of children.

GetCount()

This action returns how many leaves are in this cell and all of its children.

Returns

integer: The number of leaves.

GetDepth()

This action returns how many levels this cell is below the top cell, which is 0.

Returns

integer: The cell's level.

GetLeaf(integer index)

This action returns one of the leaves in this cell itself.

Parameters

  • index integer: Which leaf, counting from 0.

Returns

Libraries.Game.Graphics.Trees.RenderTreeNode3D: The leaf.

GetLeafCount()

This action returns how many leaves are in this cell itself, not in its children.

Returns

integer: The number of leaves in this cell.

GetParentCell()

This action returns the cell this cell was split from, or undefined for the top cell.

Returns

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

GetSize()

This action returns the length of the cell's sides. The loose box is twice this.

Returns

number: The length of the cell's sides.

HasChildren()

This action returns true if the cell has been split into children.

Returns

boolean: True if the cell has children.

RemoveLeaf(Libraries.Game.Graphics.Trees.RenderTreeNode3D leaf)

This action takes a leaf out of this cell. The last leaf in the list takes its place, so nothing is shifted, and that leaf's place is updated. The counts are not changed; see AddToCount.

Parameters

SetCount(integer value)

This action sets the count of leaves in this cell and its children, without changing the cells above. AddToCount uses it.

Parameters

  • value integer: The number of leaves.

SetDepth(integer value)

This action sets how many levels this cell is below the top cell.

Parameters

  • value integer: The cell's level, 0 for the top cell.

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

This action sets the cell this cell was split from.

Parameters

SetPlace(number x, number y, number z, number sideLength, number bottom, number top)

This action sets where the cell is. The loose box is twice the size of the cell. Its height is the given bottom and top, so a quadtree can make every cell as tall as its region.

Parameters

  • x number: The x coordinate of the cell's center.
  • y number: The y coordinate of the cell's center.
  • z number: The z coordinate of the cell's center.
  • sideLength number: The length of the cell's sides.
  • bottom number: The lowest y of the loose box.
  • top number: The highest y of the loose box.

Inherited Actions

3 actions from Libraries.Language.Object