Persist painted maps and HUD layout across sessions

Add MeshPainter.Persistence.cs: auto-save the three canonical paint maps
(albedo, MSO, emission) as PNGs under persistentDataPath on quit/play-stop
and auto-load them as the backend seed on start, so painting survives
sessions. Reuses the existing ReadCanonical/SetupBackend seed round-trip;
no new color-space code.

Add PaintHud.Persistence.cs: auto-save draggable panel positions and the
widget-bound painter values to a small JSON layout file, restored on start
via the painter -> SyncFromPainter -> widgets path. Complete SyncFromPainter
to also cover the spray sliders.
This commit is contained in:
admin committed 2026-06-25 05:11:36 +02:00
1 parent 9dab4a742e
commit 95fa5cc22d
6 files changed
+404 -2

No files matched your search

+11 -1
View File
@@ -295,7 +295,9 @@ public partial class MeshPainter : MonoBehaviour
else if (_materialInstance.HasProperty(ColorId)) _materialInstance.SetColor(ColorId, Color.white);
BuildSeedColors();
SetupBackend(useGpu, _seedCanonical);
// Persistence: seed from the saved maps if present (per-map null falls back to the
// material seed), otherwise from the material as before.
SetupBackend(useGpu, LoadPaintMaps() ?? _seedCanonical);
ConfigureMaterialPbr();
EnsureProceduralMask();
@@ -841,8 +843,16 @@ public partial class MeshPainter : MonoBehaviour
return es && es.IsPointerOverGameObject();
}
// Quit / play-stop (and standalone exit) fire OnApplicationQuit before teardown; persist
// here so the painted maps survive into the next session.
private void OnApplicationQuit() => SavePaintOnTeardown();
private void OnDestroy()
{
// Save before tearing the backend down (ReadCanonical needs the live maps). Covers a
// scene unload that does not raise OnApplicationQuit; the once-guard prevents a re-save.
SavePaintOnTeardown();
if (_bakedMesh) Destroy(_bakedMesh);
if (_materialInstance) Destroy(_materialInstance);
if (_proceduralMask) Destroy(_proceduralMask);