Scene save/load (.mrscene) #8

Merged
dev merged 4 commits from devin/1795937342-scene-files into main 2026-12-01 00:57:49 -05:00
Owner

Adds scene save/load. Stacked on #7 (multi-model, stages, grid, scale); merge #7 first.

  • Format (src/scene/SceneFile.{h,cpp}, in mr_core so the vtuber fork can reuse it): .mrscene, JSON via nlohmann/json 3.11.3 (FetchContent, header-only). "format": "mr-scene", "version": 1; files from a newer version are refused. Paths are stored relative to the scene file with / separators, and resolved against the scene's folder on load. Saves go to a temp file and are renamed, so a failed save never truncates an existing scene.
  • Contents: each model/stage (path, stage, visible, position, rotationY, scale, dance .vmd, non-rest bone poses and non-zero manual morph weights keyed by name), active model, camera .vmd, audio, frame, loop, camera follow, volume, the 3D view's eye/center/up, View settings (grid, physics, IK, GPU skinning, skeleton, wireframe, culling, light follows camera, shading) and Render size/options. Morphs driven by the dance are skipped, since playback overwrites them.
  • Editor (src/app/SceneIo.cpp): File > New scene / Open... (Ctrl+O) / Save scene (Ctrl+S) / Save scene as... (Ctrl+Shift+S); Cmd on macOS through ImGui's key swap. The file browser has a Save mode with a file-name field and lists .mrscene and .x files. The menu bar shows the scene's file name and "Saved ..." after a save. Missing files are listed in the error box and the rest of the scene still loads.
  • CLI: model_renderer scene.mrscene opens a scene (its view/physics/grid are kept unless --orbit/--physics/--no-grid are given); --save-scene FILE saves after loading.
  • Tests: testSceneFile round-trips a scene with Japanese names and checks the relative paths and that a foreign JSON file is rejected. Manually: saved Karin + WinterWorld (stage scale 3, posed arm, blink), reopened it, re-saved, and got identical JSON apart from float rounding.

Follow-up fixes

  • macOS double-click: OSG's Cocoa backend sends the second press of a double-click as DOUBLECLICK, and ImGuiOsg ignored it, so ImGui never saw a double-click and files couldn't be opened from the file browser on macOS. It is now forwarded as a press. The browser also has an Open button for the highlighted file.
  • File > Open scene... (Ctrl/Cmd+O) lists only .mrscene files.
  • Memory: newScene() calls malloc_trim (glibc) / malloc_zone_pressure_relief (macOS). --reload-test N reopens a scene N times and prints memory use (phys_footprint on macOS). Karin + Miku + WinterWorld + Hi-Fi Raver over 40 reloads on Linux stays at 310–350 MB. On the Mac, 15 reloads stay at about 790 MB, and after New scene memory drops back to the 41 MB empty-app level within about 15 s, as macOS reclaims the purgeable texture memory.
Adds scene save/load. Stacked on #7 (multi-model, stages, grid, scale); merge #7 first. - **Format** (`src/scene/SceneFile.{h,cpp}`, in `mr_core` so the vtuber fork can reuse it): `.mrscene`, JSON via nlohmann/json 3.11.3 (FetchContent, header-only). `"format": "mr-scene"`, `"version": 1`; files from a newer version are refused. Paths are stored relative to the scene file with `/` separators, and resolved against the scene's folder on load. Saves go to a temp file and are renamed, so a failed save never truncates an existing scene. - **Contents**: each model/stage (path, stage, visible, position, rotationY, scale, dance `.vmd`, non-rest bone poses and non-zero manual morph weights keyed by **name**), active model, camera `.vmd`, audio, frame, loop, camera follow, volume, the 3D view's eye/center/up, View settings (grid, physics, IK, GPU skinning, skeleton, wireframe, culling, light follows camera, shading) and Render size/options. Morphs driven by the dance are skipped, since playback overwrites them. - **Editor** (`src/app/SceneIo.cpp`): File > New scene / Open... (Ctrl+O) / Save scene (Ctrl+S) / Save scene as... (Ctrl+Shift+S); Cmd on macOS through ImGui's key swap. The file browser has a Save mode with a file-name field and lists `.mrscene` and `.x` files. The menu bar shows the scene's file name and "Saved ..." after a save. Missing files are listed in the error box and the rest of the scene still loads. - **CLI**: `model_renderer scene.mrscene` opens a scene (its view/physics/grid are kept unless `--orbit`/`--physics`/`--no-grid` are given); `--save-scene FILE` saves after loading. - **Tests**: `testSceneFile` round-trips a scene with Japanese names and checks the relative paths and that a foreign JSON file is rejected. Manually: saved Karin + WinterWorld (stage scale 3, posed arm, blink), reopened it, re-saved, and got identical JSON apart from float rounding. **Follow-up fixes** - **macOS double-click:** OSG's Cocoa backend sends the second press of a double-click as `DOUBLECLICK`, and `ImGuiOsg` ignored it, so ImGui never saw a double-click and files couldn't be opened from the file browser on macOS. It is now forwarded as a press. The browser also has an **Open** button for the highlighted file. - **File > Open scene...** (Ctrl/Cmd+O) lists only `.mrscene` files. - **Memory:** `newScene()` calls `malloc_trim` (glibc) / `malloc_zone_pressure_relief` (macOS). `--reload-test N` reopens a scene N times and prints memory use (phys_footprint on macOS). Karin + Miku + WinterWorld + Hi-Fi Raver over 40 reloads on Linux stays at 310–350 MB. On the Mac, 15 reloads stay at about 790 MB, and after New scene memory drops back to the 41 MB empty-app level within about 15 s, as macOS reclaims the purgeable texture memory.
dev changed target branch from devin/1795876546-grid-multimodel to main 2026-12-01 00:57:43 -05:00
dev added 4 commits 2026-12-01 00:57:43 -05:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Closing the pop-out's graphics context made OSG delete GL objects shared with the main window
(textures lose their CPU images after upload, so models came back black). Docking now hides the
window and reuses it; the window's close button docks instead of closing.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
dev merged commit 30d8c98891 into main 2026-12-01 00:57:49 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dev/3d-model-renderer#8