RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Ambient SoundUI Apps ManagerUI AudioBindings LegendCamera Distance AppDeveloper ConsoleCredits MusicExternal WebSocket ServerFade ScreenGame BlurGameplay App ContainersGrid SelectorLivery EditorMessages DebuggerMessages/Tasks App ContainersMission InfoPolice InfoTop BarUI ModsNavigation Map DataVehicle Paint EditorVehicle Vicinity AppUI Visibility
Camera ManagementAction Map ManagementEdit Mode State MachineLivery EditorUndo/Redo WrapperLayer ActionsLayer Edit LifecycleLayer DataDecal Texture LoaderLayer SelectionToolsLivery FilesMath Utilities

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 ExtensionsuiliveryEditor

Math Utilities

Math and conversion utilities shared across the livery editor modules.

Math and conversion utilities shared across the livery editor modules.


Overview

ui_liveryEditor_utils provides common math helpers used throughout the livery editor - angle conversions, rounding, coordinate extraction, range cycling, and action map resolution.

Extension path: lua/ge/extensions/ui/liveryEditor/utils.lua


Exports (M)

FunctionSignatureDescription
convertRadiansToDegrees(radians) → numberConverts radians to degrees.
convertDegreesToRadians(degrees) → numberConverts degrees to radians with 14-decimal precision.
getBaseDegreesValue(value) → numberNormalises a degree value to 0–360 range.
roundAndTruncateDecimal(number, decimals) → numberRounds to the specified decimal places (default 1).
getXYCoordinates(decalPos, coordinates) → {x, y}Extracts X/Y from a decal position based on camera coordinate mapping.
cycleRange(value, min, max) → numberWraps a value within [min, max) using modulo.
getActionMapNameByTool(tool) → stringMaps a tool constant to its action map name.

Internals

Angle Conversion

local convertRadiansToDegrees = function(radians)
  return radians * (180 / math.pi)
end

local convertDegreesToRadians = function(degrees)
  local radians = degrees * (math.pi / 180)
  return tonumber(string.format("%.14f", radians))
end

The radians-to-degrees conversion preserves full precision. Degrees-to-radians truncates to 14 decimal places to avoid floating-point drift.

Rounding

local roundAndTruncateDecimal = function(number, decimals)
  decimals = decimals or 1
  local scale = 10 ^ decimals
  return math.ceil(number * scale - 0.5) / scale
end

Uses ceiling-minus-half for symmetric rounding (round-half-up behaviour).

Cycle Range

local cycleRange = function(value, min, max)
  value = value % max
  if value < min then
    value = value + max
  end
  return value
end

Used for wrapping rotation degrees: cycleRange(370, 0, 360) → 10.

Coordinate Extraction

getXYCoordinates reads from a decalPos vector using camera-defined axis indices, allowing the same code to work regardless of camera orientation.


How It Works

  1. Transform modules call convertRadiansToDegrees / convertDegreesToRadians for UI display
  2. roundAndTruncateDecimal keeps displayed values clean (e.g., 0.001 precision for position)
  3. cycleRange ensures rotation values stay within 0–360
  4. getActionMapNameByTool resolves tool names to action map identifiers for input binding

Example Usage

local utils = extensions.ui_liveryEditor_utils

-- Convert rotation for display
local degrees = utils.convertRadiansToDegrees(1.5708)  -- ~90.0

-- Round for UI
local rounded = utils.roundAndTruncateDecimal(0.12345, 2)  -- 0.12

-- Wrap rotation
local wrapped = utils.cycleRange(-10, 0, 360)  -- 350

Additional Exports

The following exports are available but not yet documented in detail:

  • M.convertDegreesToRadians
  • M.convertRadiansToDegrees
  • M.cycleRange
  • M.getActionMapNameByTool
  • M.getBaseDegreesValue
  • M.getXYCoordinates
  • M.roundAndTruncateDecimal

See Also

  • Livery Editor - Camera - Related reference
  • Livery Editor - Controls - Related reference
  • Livery Editor - Edit Mode - Related reference
  • UI System Guide - Guide

Livery Files

Manages livery save files - listing, creating, renaming, and deleting `.dynDecals.json` files.

Decal Cursor

Manages the decal placement cursor - position, scale, skew, rotation, colour, material properties, and mirror settings.

On this page

OverviewExports (M)InternalsAngle ConversionRoundingCycle RangeCoordinate ExtractionHow It WorksExample UsageAdditional ExportsSee Also