Export (glTF)
Exports the current player vehicle as a glTF/GLB 3D file, including meshes, materials, textures, part hierarchy, and optionally node/beam data.
Exports the current player vehicle as a glTF/GLB 3D file, including meshes, materials, textures, part hierarchy, and optionally node/beam data.
Overview
util_export (aliased as extensions.export) provides full vehicle-to-glTF export. It captures GPU mesh data (vertices, normals, tangents, UVs, colors), reconstructs the vehicle's part tree, exports materials with PBR textures, and writes glTF JSON or binary GLB format. Supports animated recording.
Extension path: lua/ge/extensions/util/export.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
export | (handler) | Triggers GPU mesh capture, calls handler with glTF root. |
exportFile | (filename) | Exports to a file (JSON or GLB based on gltfBinaryFormat). |
startRecording | (filename) | Begins multi-frame recording. |
stopRecording | () | Stops recording. |
updateGFX | (dt) | Processes export when GPU data is ready. |
suggestFilename | () | Returns next available export filename. |
getGeInfo | () | Returns current export settings. |
Configuration Properties
| Property | Default | Description |
|---|---|---|
M.embedBuffers | true | Embed binary buffers as base64 in JSON. |
M.gltfBinaryFormat | true | Output GLB instead of JSON. |
M.exportNormals | true | Include vertex normals. |
M.exportTangents | false | Include tangents. |
M.exportTexCoords | false | Include UV coordinates. |
M.exportColors | false | Include vertex colors. |
M.exportBeams | true | Include JBeam node/beam data in extras. |
Internals
Export Pipeline
export()triggersGPUMesh.bng_getGPUMesh()to capture current vehicle mesh.- When data is ready,
processExport()builds the glTF structure:- Adds index buffer from GPU mesh.
- Adds vertex attribute buffers (positions, normals, tangents, UVs, colors).
- Creates mesh nodes for flexbodies and prop meshes.
- Maps meshes to vehicle parts via
partToFlexMesh. - Builds part tree from
vehiclePartTreeandslotMap. - Exports materials with PBR textures (v1 and v1.5 material formats).
- Handler receives the completed glTF root object.
Part Tree
The vehicle's JBeam part hierarchy is reconstructed:
- Each part becomes a glTF node.
- Flexbody meshes are assigned as children of their owning part.
- Node/beam data is stored in
BNG_JBeamDataextension. - Vehicle direction stored in
BNG_Directionextension.
Material Export
Supports Material v1 (legacy) and v1.5 (PBR):
- Extracts all texture stages (color, normal, specular, metallic, roughness, emissive, etc.).
- Converts DDS textures to PNG.
- Handles CEF textures (dynamic paint textures via
@prefix). - Creates proper
pbrMetallicRoughnessglTF material structure.
GLB Format
Binary output merges all buffers into a single binary chunk:
- Updates buffer view offsets to reference the merged buffer.
- Writes proper GLB header (magic, version, length).
- Aligns chunks to 4-byte boundaries.
How It Works
- Call
exportFile('vehicle.glb')or use the UI. - GPU mesh data is captured from the current vehicle.
- Mesh geometry, materials, textures, and part hierarchy are assembled into glTF.
- File is written as GLB (binary) or glTF (JSON).
Lua Examples
-- Export current vehicle to GLB
extensions.export.exportFile('vehicles/pickup/export_001.glb')
-- Suggest a filename
local fn = extensions.export.suggestFilename()
extensions.export.exportFile(fn)
-- Export with custom settings
extensions.export.gltfBinaryFormat = false
extensions.export.exportTexCoords = true
extensions.export.exportFile('vehicle.gltf')
-- Record animation frames
extensions.export.startRecording('animation.glb')
-- ... later ...
extensions.export.stopRecording()Additional Exports
M.export- (undocumented)M.exportFile- (undocumented)M.getGeInfo- (undocumented)M.startRecording- (undocumented)M.stopRecording- (undocumented)M.suggestFilename- (undocumented)M.updateGFX- (undocumented)
Doc Creator
Generates JSON data files and resources for the BeamNG documentation / Hugo system. Exports levels, vehicles, materials, JBeam defaults, controller info, and more across all available languages.
Follow The White Rabbit
A minimal text-adventure easter egg that runs in a custom console context.