Module octree

Octree

Functions

Octree:add (obj, objBounds) Add an object.
Octree:remove (obj) Remove an object.
Octree:is_colliding (checkBounds) Check if the specified bounds intersect with anything in the tree.
Octree:get_colliding (checkBounds) Returns an array of objects that intersect with the specified bounds, if any.
Octree:cast_ray (ray, func, out) Cast a ray through the node and its children
Octree:draw_bounds (cube) Draws node boundaries visually for debugging.
Octree:draw_objects (cube, filter) Draws the bounds of all objects in the tree visually for debugging.
Octree:grow (direction) Grow the octree to fit in all objects.
Octree:shrink () Shrink the octree if possible, else leave it the same.
OctreeNode:add (obj, objBounds) Add an object.
OctreeNode:remove (obj) Remove an object.
OctreeNode:is_colliding (checkBounds) Check if the specified bounds intersect with anything in the tree.
OctreeNode:get_colliding (checkBounds, results) Returns an array of objects that intersect with the specified bounds, if any.
OctreeNode:cast_ray (ray, func, out, depth) Cast a ray through the node and its children
OctreeNode:set_children (childOctrees) Set the 8 children of this octree.
OctreeNode:shrink_if_possible (minLength) We can shrink the octree if: - This node is >= double minLength in length - All objects in the root node are within one octant - This node doesn't have children, or does but 7/8 children are empty We can also shrink it if there are no objects left at all!
OctreeNode:set_values (baseLength, minSize, looseness, center) Set values for this node.
OctreeNode:split () Splits the octree into eight children.
OctreeNode:merge () Merge all children into this node - the opposite of Split.
OctreeNode:best_fit_child (objBounds) Find which child node this object would be most likely to fit in.
OctreeNode:should_merge () Checks if there are few enough objects in this node and its children that the children should all be merged into this.
OctreeNode:has_any_objects () Checks if this node or anything below it has something in it.
OctreeNode:draw_bounds (cube, depth) Draws node boundaries visually for debugging.
OctreeNode:draw_objects (cube, filter) Draws the bounds of all objects in the tree visually for debugging.


Functions

Octree:add (obj, objBounds)
Add an object.

Parameters:

  • obj Object to add
  • objBounds 3D bounding box around the object
Octree:remove (obj)
Remove an object. Makes the assumption that the object only exists once in the tree.

Parameters:

  • obj Object to remove

Returns:

    bool True if the object was removed successfully
Octree:is_colliding (checkBounds)
Check if the specified bounds intersect with anything in the tree. See also: get_colliding.

Parameters:

  • checkBounds bounds to check

Returns:

    bool True if there was a collision
Octree:get_colliding (checkBounds)
Returns an array of objects that intersect with the specified bounds, if any. Otherwise returns an empty array. See also: is_colliding.

Parameters:

  • checkBounds bounds to check

Returns:

    table Objects that intersect with the specified bounds
Octree:cast_ray (ray, func, out)
Cast a ray through the node and its children

Parameters:

  • ray Ray with a position and a direction
  • func Function to execute on any objects within child nodes
  • out Table to store results of func in

Returns:

    boolean True if an intersect detected
Octree:draw_bounds (cube)
Draws node boundaries visually for debugging.

Parameters:

  • cube
Octree:draw_objects (cube, filter)
Draws the bounds of all objects in the tree visually for debugging.

Parameters:

  • cube
  • filter
Octree:grow (direction)
Grow the octree to fit in all objects.

Parameters:

  • direction Direction to grow
Octree:shrink ()
Shrink the octree if possible, else leave it the same.
OctreeNode:add (obj, objBounds)
Add an object.

Parameters:

  • obj Object to add
  • objBounds 3D bounding box around the object

Returns:

    boolean True if the object fits entirely within this node
OctreeNode:remove (obj)
Remove an object. Makes the assumption that the object only exists once in the tree.

Parameters:

  • obj Object to remove

Returns:

    boolean True if the object was removed successfully
OctreeNode:is_colliding (checkBounds)
Check if the specified bounds intersect with anything in the tree. See also: get_colliding.

Parameters:

  • checkBounds Bounds to check

Returns:

    boolean True if there was a collision
OctreeNode:get_colliding (checkBounds, results)
Returns an array of objects that intersect with the specified bounds, if any. Otherwise returns an empty array. See also: is_colliding.

Parameters:

  • checkBounds Bounds to check. Passing by ref as it improve performance with structs
  • results List results

Returns:

    table Objects that intersect with the specified bounds
OctreeNode:cast_ray (ray, func, out, depth)
Cast a ray through the node and its children

Parameters:

  • ray Ray with a position and a direction
  • func Function to execute on any objects within child nodes
  • out Table to store results of func in
  • depth (used internally)

Returns:

    boolean True if an intersect is detected
OctreeNode:set_children (childOctrees)
Set the 8 children of this octree.

Parameters:

  • childOctrees The 8 new child nodes
OctreeNode:shrink_if_possible (minLength)
We can shrink the octree if: - This node is >= double minLength in length - All objects in the root node are within one octant - This node doesn't have children, or does but 7/8 children are empty We can also shrink it if there are no objects left at all!

Parameters:

  • minLength Minimum dimensions of a node in this octree

Returns:

    table The new root, or the existing one if we didn't shrink
OctreeNode:set_values (baseLength, minSize, looseness, center)
Set values for this node.

Parameters:

  • baseLength Length of this node, not taking looseness into account
  • minSize Minimum size of nodes in this octree
  • looseness Multiplier for baseLengthVal to get the actual size
  • center Centre position of this node
OctreeNode:split ()
Splits the octree into eight children.
OctreeNode:merge ()
Merge all children into this node - the opposite of Split. Note: We only have to check one level down since a merge will never happen if the children already have children, since THAT won't happen unless there are already too many objects to merge.
OctreeNode:best_fit_child (objBounds)
Find which child node this object would be most likely to fit in.

Parameters:

  • objBounds The object's bounds

Returns:

    number One of the eight child octants
OctreeNode:should_merge ()
Checks if there are few enough objects in this node and its children that the children should all be merged into this.

Returns:

    boolean True there are less or the same abount of objects in this and its children than numObjectsAllowed
OctreeNode:has_any_objects ()
Checks if this node or anything below it has something in it.

Returns:

    boolean True if this node or any of its children, grandchildren etc have something in the
OctreeNode:draw_bounds (cube, depth)
Draws node boundaries visually for debugging.

Parameters:

  • cube Cube model to draw
  • depth Used for recurcive calls to this method
OctreeNode:draw_objects (cube, filter)
Draws the bounds of all objects in the tree visually for debugging.

Parameters:

  • cube Cube model to draw
  • filter a function returning true or false to determine visibility.
generated by LDoc 1.4.6 Last updated 2022-05-07 22:53:35