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

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.

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


Exports

Functions

kdtreepoint3d.new(itemCount)

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

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

Instance Methods

tree:preLoad(id, x, y, z)

Adds a point to the pre-load buffer.

  • Parameters:
    • id - any - Item identifier
    • x, y, z - number - Point coordinates

tree:build()

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

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

Range query - returns iterator over all points within the query box. Safe for nested queries.

  • Returns: function, table - Iterator yielding item IDs

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

Faster range query reusing internal state; not safe for nesting.

  • Returns: function, table - Iterator

tree:findNearest(x, y, z)

Finds the closest point to the query position.

  • Parameters:
    • x, y, z - number - Query point coordinates
  • Returns: any, number - ID of nearest item and Euclidean distance to it

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

Serialization/deserialization.

tree:analytics()

Prints tree statistics.

Internal Notes

  • Items stored as flat array: 4 values per item (x, y, z, id)
  • findNearest uses branch-and-bound with the median point as initial best-distance estimate
  • Same LEF Select and flat-array structure as the box variants
  • Nearest-neighbor search prunes branches when the squared distance to the split plane exceeds best distance

Additional Exports

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

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

lpack Reference

Module defined in `lua/common/lpack.lua`. Fast Lua de/serializer supporting three formats: packed text, binary (using `string.buffer`), and Lua source. Handles tables, numbers, strings, booleans, vec3

On this page

ExportsFunctionskdtreepoint3d.new(itemCount)Instance Methodstree:preLoad(id, x, y, z)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:findNearest(x, y, z)tree:export() / tree:import(kdTreeData)tree:analytics()Internal NotesAdditional Exports