RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Auto AnnotationBoosterCalibrate ESCCompile ImpostersCompile MeshesConfig List GeneratorDecal Roads EditorDependency TreeDoc CreatorVehicle ExporterFollow The White RabbitForest GeneratorGround Model DebugInput System UtilsInstanced Line Render DemoJBeam StatsLog StreamsMap TilesNode Beam ExportNode StreamPhotomodePrecompile ShadersPrecompile VehiclesProcedural Track GeneratorRectangle GeneratorRender Components APIResave MaterialsRich PresenceSave Dynamic DataScreenshot CreatorShowroomSort LinesStep HandlerTerrain GeneratorTest Extension ProxiesTest JSON Files SyntaxVehicle Rope DebugBatch WorkerWebSocket Test

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 ReferenceGE Extensionsutil

Rectangle Generator

Generates a planar graph of nodes by recursively subdividing rectangles, used by `procTrack` for gymkhana track generation.

Generates a planar graph of nodes by recursively subdividing rectangles, used by procTrack for gymkhana track generation.


Overview

util_rectangleGen is a helper module (not an extension - it uses require) that takes a set of starting rectangles and parameters, recursively subdivides them, and returns a graph with nodes at rectangle centers and neighbor adjacency information.

Module path: lua/ge/extensions/util/rectangleGen.lua


Exports (M)

FunctionSignatureDescription
getGraph(params) → graph|nilSubdivides starting rectangles and returns a node graph with neighbors.
dist(a,b,x,y) → number2D Euclidean distance helper.

Internals

Graph Structure

graph = {
  nodes = {
    { x, y, neighbours = {{index, dist},...}, name, closestNeighbourDist, force },
    ...
  },
  start = node_or_nil,  -- node with start flag
  finish = node_or_nil  -- node with finish flag
}

Subdivision Algorithm

  1. Copies startingRects (excluding noSplit rects) into a working list.
  2. Iteratively picks the largest rectangle and splits it vertically or horizontally:
    • Direction chosen by params.rectModeParams.vertSplitFunction(width, height).
    • Split position chosen by params.rectModeParams.cutValueFunction(), clamped to respect minXDist/minYDist.
  3. Stops when rectangle count reaches params.rectModeParams.numNodes or no more splits possible.
  4. noSplit rectangles are appended afterwards (fixed nodes with optional start/finish flags).

Neighbor Detection

Two rectangles are neighbors if they share an edge (within floating-point tolerance 0.001):

  • Left/right adjacency: matching X boundary and overlapping Y range.
  • Top/bottom adjacency: matching Y boundary and overlapping X range.

Node Placement

Each rectangle's center becomes a node. The closestNeighbourDist field records the minimum distance to any neighbor, used by procTrack for radius calculations.


How It Works

  1. procTrack.checkParams() calls require('util/rectangleGen').
  2. makeBaseNodePositions() calls getGraph(params).
  3. The returned graph feeds into the Hamiltonian path solver.

Lua Examples

-- Used internally by procTrack, not typically called directly
local rectGen = require('util/rectangleGen')
local graph = rectGen.getGraph(params)
-- graph.nodes contains positioned nodes with neighbor info

Additional Exports

  • M.dist - (undocumented)
  • M.getGraph - (undocumented)

See Also

  • Auto Annotation - Related reference
  • Booster - Related reference
  • Calibrate ESC - Related reference
  • Game Engine Overview - Guide

Procedural Track Generator

Generates randomized gymkhana / autocross tracks from seed-based procedural parameters.

Render Components API

Reads renderer component JSON files and provides an API to get/set rendering settings (shaders, post-effects, etc.).

On this page

OverviewExports (M)InternalsGraph StructureSubdivision AlgorithmNeighbor DetectionNode PlacementHow It WorksLua ExamplesAdditional ExportsSee Also