Skip to content

util_tileBake

File: lua/ge/extensions/util/tileBake.lua · VM: Game Engine (GE) · 163 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)

Access: extension util_tileBake: extensions.load("util_tileBake"), then the global util_tileBake

Development-only tool: produces tile proxies for the distant city. It distributes each static mesh (TSStatic) and each large forest object of the level into 200 m tiles, merges each tile into a mesh, bakes it on the GPU into a shared atlas and writes one glTF per tile (via the C++ function bakeTileToGltf). The outputs are then used by the DevTools/instalod tool to produce simplified LODs. Output: /temp/tileBake//tile_/ (atlas PNG, tile_.gltf and tile.json).

Example

extensions.load('util/tileBake')
-- baking starts by itself when a level is loaded

Notes

  • Constants: 200 m tile, 4096 px atlas page, 8 px gutter, minimum radius 4 m for forest objects.
  • Vegetation (paths containing /trees/, /vegetation/, /foliage/, /plants/, bush, shrub, fern, grass, hedge, weed) is ignored because it has its own LOD/impostor system.
  • Sequence: 60 frames of waiting (time for rendering and shaders to settle), one gathering pass (gather), then one tile baked per frame to let the game breathe.
  • Each tile writes a tile.json (level, tx, ty, tileSize, origin, number of statics/forest/instances) to place it back at its world origin.
  • The forest transforms are constant; the code rebuilds a modifiable matrix before applying the scale (see scaledTransform).
  • The level name is taken from getMissionFilename() ('level' by default).

Functions

Function Description Line
util_tileBake.onClientPostStartMission() Hook called at the end of level loading; rearms the baking (same function as onExtensionLoaded). (internal) (hook) 136
util_tileBake.onExtensionLoaded() Arms the baking when the extension is loaded while a level is already in place: enables the pending mode, waits 60 frames, resets the counters. Same function as onClientPostStartMission. (internal) (hook) 136
util_tileBake.onUpdate() Hook called every frame. Once armed: waits for the warmup to end, collects the instances per tile, then bakes one tile per call and logs the progress and the final summary (OK/failures). (internal) (hook) 144

Calls into the engine (C++)

  • obj: getField, getScale, getTransform, getWorldBox, isSubClassOf

tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/util/tileBake.lua.