Resave Materials
Batch-converts legacy TorqueScript material files (`materials.cs`) to the new JSON format.
Batch-converts legacy TorqueScript material files (materials.cs) to the new JSON format.
Overview
util_resaveMaterials scans the entire filesystem for materials.cs files, executes each via TorqueScript, collects the resulting SimObjects, and re-saves them in the new format using PersistenceManager. This is a one-time migration utility.
Extension path: lua/ge/extensions/util/resaveMaterials.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
onExtensionLoaded | () | Configures log filtering and starts the conversion job. |
work | (job) | Coroutine job that performs the actual conversion. |
Internals
Conversion Flow
- Creates a
PersistenceManagerinstance. - Finds all
materials.csfiles recursively from/. - For each file with size > 0:
- Executes via
TorqueScriptLua.exec(fn). - Collects all SimObjects whose
getFileName()matches the source file. - Marks each object dirty in the PersistenceManager.
- Calls
saveDirtyNewFormat()to write the new format. - Deletes the temporary SimObjects.
- Executes via
- Cleans up the PersistenceManager.
Helper: getSimObjects(fileName)
Iterates scenetree.getAllObjects(), returning those whose getFileName() matches the given path.
Job System
Uses core_jobsystem.create(work, 1) to yield every second, keeping the UI responsive.
Log Filtering
Sets IngameConsoleLogBlacklist and WinConsoleLogBlacklist to "DA" to suppress noisy debug output during conversion.
How It Works
- Load the extension (typically via CLI).
onExtensionLoadedstarts a background job.- The job iterates all
materials.csfiles, executes them, and resaves in new format. - Logs
DONEon completion.
Lua Examples
-- Typically run as a batch tool:
-- beamng.exe -onLevelLoad_ext "util/resaveMaterials"
-- Or load manually:
extensions.load("util/resaveMaterials")Additional Exports
M.onExtensionLoaded- (undocumented)M.work- (undocumented)