Skip to main content

Module scene_io

Module scene_io 

Source
Expand description

Scene serialization helpers.

All scene I/O is project-relative when possible — saves and loads route through crate::project_vfs::ProjectVfs so the editor uses the same AssetService + FileLoader contract as a future runtime. The “Save As” / “Open” file-dialog flows still accept arbitrary paths (that’s intentional — you might want to open a scene from outside the current project) and fall back to direct std::fs only in that case.

Constants§

DEFAULT_SCENE_REL
Canonical relative path of the auto-created default scene.

Functions§

auto_load_or_create_default_scene
Auto-loads the project’s default scene (assets/scenes/default.kscene), creating it from a Camera + Light template if it doesn’t exist yet.
create_default_scene_in_project 🔒
Spawns Main Camera + Directional Light entities, then saves the world to the relative path inside the project (default scenes/default.kscene).
load_scene_from_path
Loads a scene from an absolute path. Used by the “Open…” dialog when the user picks a file outside <project>/assets/.
load_scene_in_project
Loads a scene by its relative path under <project>/assets/ via the project’s AssetService::load_raw. Falls back to a fresh reindex + retry once if the path isn’t yet known to the VFS (e.g. just-saved).
rel_inside_project
If abs_path lives under <project>/assets/, returns the relative path in forward-slash form ready for load_scene_in_project. Otherwise returns None — callers should fall back to load_scene_from_path.
restore_scene
Restores the world from a snapshot produced by snapshot_scene.
save_scene_in_project
Serializes the current world to a .kscene file at rel_path (relative to the project’s assets/ root) via the project’s AssetService. Re- indexes on success so the new scene is immediately resolvable by UUID.
save_scene_in_project_with_goal
Same as save_scene_in_project with an explicit serialization goal.
save_scene_to_path
Serializes the world to a .kscene at an absolute path. Used by the “Save As…” dialog when the user picks a destination outside <project>/assets/. Logs a warning so the divergence from VFS-managed I/O is visible.
save_scene_to_path_with_goal
Same as save_scene_to_path with an explicit serialization goal.
snapshot_scene
Serializes the entire world to an in-memory byte buffer for play-mode restore. Returns an empty Vec on failure (caller logs and proceeds — the worst case is “Stop button leaves the live state in place”, which is preferable to a panic mid-play).