RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

cdefDebugDraw ReferencecdefGpuMesh ReferencecdefImgui ReferencecdefMath Referencecdefs ReferencecontrolSystems Referencecsvlib ReferencedelayLine Referencedequeue ReferencedevUtils ReferenceEvent Referenceextensions Referencefilters Referencegraphpath Referenceguihooks ReferenceinputFilters ReferenceinterpolatedMap Referenceintrospection ReferencejbeamWriter Referencejson-ast Referencejson ReferencejsonDebug ReferencejsonPrettyEncoderCustom Referencekdtreebox2d Referencekdtreebox3d Referencekdtreepoint3d Referencelpack ReferenceluaBinding ReferenceluaCore ReferenceluaProfiler Referencemathlib Referenceparticles Referencequadtree Referencesettings ReferencetcpServer ReferencetimeEvents Referenceutils Reference

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API Referencecommon

kdtreebox3d Reference

Module defined in `lua/common/kdtreebox3d.lua`. K-d tree implementation for 3D axis-aligned bounding boxes (6 dimensions: xmin, ymin, zmin, xmax, ymax, zmax). Efficient spatial range queries for 3D bo

Module defined in lua/common/kdtreebox3d.lua. K-d tree implementation for 3D axis-aligned bounding boxes (6 dimensions: xmin, ymin, zmin, xmax, ymax, zmax). Efficient spatial range queries for 3D bounding volumes.


Exports

Functions

kdtreebox3d.new(itemCount)

Creates a new empty 3D box k-d tree.

  • Parameters:
    • itemCount - number|nil - Expected item count for pre-allocation
  • Returns: kdTree - Tree object

Instance Methods

tree:preLoad(id, xmin, ymin, zmin, xmax, ymax, zmax)

Adds an item to the pre-load buffer.

  • Parameters:
    • id - any - Item identifier
    • xmin, ymin, zmin, xmax, ymax, zmax - number - 3D bounding box coordinates

tree:build()

Constructs the k-d tree from pre-loaded items.

tree:query(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)

Returns an iterator over intersecting items. Safe for nested queries.

  • Returns: function, table - Iterator

tree:queryNotNested(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)

Faster query reusing internal state; not safe for nesting.

  • Returns: function, table - Iterator

tree:export() / tree:import(kdTreeData)

Serialization/deserialization of tree data.

tree:analytics()

Prints tree statistics.

Internal Notes

  • Items stored as flat array: 7 values per item (xmin, ymin, zmin, xmax, ymax, zmax, id)
  • Same LEF Select algorithm and flat-array tree structure as kdtreebox2d, extended to 6 dimensions
  • Tree cycles through 3 split axes (x, y, z) alternating at each level

Additional Exports

KeySignatureDescription
M.new(itemCount)(No description available)

kdtreebox2d Reference

Module defined in `lua/common/kdtreebox2d.lua`. K-d tree implementation for 2D axis-aligned bounding boxes (4 dimensions: xmin, ymin, xmax, ymax). Supports efficient spatial range queries with both ne

kdtreepoint3d Reference

Module defined in `lua/common/kdtreepoint3d.lua`. K-d tree implementation for 3D points with range queries AND nearest-neighbor (closest point) queries.

On this page

ExportsFunctionskdtreebox3d.new(itemCount)Instance Methodstree:preLoad(id, xmin, ymin, zmin, xmax, ymax, zmax)tree:build()tree:query(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)tree:queryNotNested(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)tree:export() / tree:import(kdTreeData)tree:analytics()Internal NotesAdditional Exports