diff --git a/studio/Cargo.toml b/studio/Cargo.toml index 7991ccc..6f7cd8e 100644 --- a/studio/Cargo.toml +++ b/studio/Cargo.toml @@ -32,7 +32,7 @@ web-sys = { version = "0.3.65", optional = true, features = [ "HtmlElement", "Window", ] } -space_editor = {git = "https://github.com/rewin123/space_editor", rev = "f3e2e0de52540125b79dad98656382ff473dedc2"} +space_editor = {git = "https://github.com/rewin123/space_editor", rev = "0c3a8eaf1acea181407c43b7226799b2d08b4c89"} [features] wasm = [ diff --git a/studio/src/lib.rs b/studio/src/lib.rs index e11d880..3c2d390 100644 --- a/studio/src/lib.rs +++ b/studio/src/lib.rs @@ -4,7 +4,7 @@ use bevy::{app::PluginGroupBuilder, prelude::*}; use bevy_mod_picking::DefaultPickingPlugins; use space_editor::{ - prelude::space_undo::UndoPlugin, + prelude::{space_undo::UndoPlugin, PersistencePlugin}, space_editor_ui::{EditorPluginGroup, ext::{bevy_egui::EguiPlugin, bevy_inspector_egui::DefaultInspectorConfigPlugin}, EditorPickingPlugin}, }; #[cfg(feature = "wasm")] @@ -70,6 +70,7 @@ impl PluginGroup for CommonPlugins { .add(StudioInputPlugin) .add(UiLayerPlugin) .add(WorldGridPlugin) + .add(persistance::PersistancePlugin) } } @@ -124,6 +125,7 @@ pub fn init(viewport_size: ViewportSize) { SkyboxPlugin, UiLayerPlugin, WorldGridPlugin, + persistance::PersistancePlugin )) .add_systems( Startup, @@ -131,7 +133,8 @@ pub fn init(viewport_size: ViewportSize) { cmd.insert_resource(SkyboxId("gum_trees_4k".to_string())); ew.send(LoadSceneEvent("bookcase".to_string())); }, - ); + ) + .insert_resource(StudioMode::Editor); // Only for registering components for undo use space_editor::prelude::space_undo::AppAutoUndo; diff --git a/studio/src/persistance/mod.rs b/studio/src/persistance/mod.rs index e69de29..405c1c0 100644 --- a/studio/src/persistance/mod.rs +++ b/studio/src/persistance/mod.rs @@ -0,0 +1,39 @@ +use bevy::prelude::*; +use space_editor::prelude::*; + +pub struct PersistancePlugin; + +impl Plugin for PersistancePlugin { + fn build(&self, app: &mut App) { + info!("PersistancePlugin::build"); + app.editor_tab_by_trait(EditorTabName::Other("Persistance".to_string()), DebugPersistanceTab::default()); + } +} + +#[derive(Resource, Default)] +pub struct DebugPersistanceTab { + +} + +impl EditorTab for DebugPersistanceTab { + fn ui(&mut self, ui: &mut bevy_inspector_egui::egui::Ui, commands: &mut Commands, world: &mut World) { + if ui.button("Save").clicked() { + world.send_event(EditorEvent::Save(EditorPrefabPath::MemoryCahce)); + } + + if ui.button("Load").clicked() { + world.send_event(EditorEvent::Load(EditorPrefabPath::MemoryCahce)); + } + + if ui.button("Clear level").clicked() { + let mut query = world.query_filtered::>(); + for e in query.iter(world) { + commands.entity(e).despawn_recursive(); + } + } + } + + fn title(&self) -> bevy_inspector_egui::egui::WidgetText { + "Persistance".into() + } +} \ No newline at end of file diff --git a/studio/src/scene.rs b/studio/src/scene.rs index acf269c..00d38ac 100644 --- a/studio/src/scene.rs +++ b/studio/src/scene.rs @@ -5,7 +5,7 @@ use bevy::{ fxaa::Fxaa, tonemapping::Tonemapping, }, - gltf::Gltf, + gltf::{Gltf, GltfLoader}, math::{vec2, vec3}, pbr::ShadowFilteringMethod, prelude::*, @@ -108,6 +108,12 @@ pub struct LoadSceneEvent(pub String); #[derive(Component)] pub struct SceneElement; +#[derive(Component)] +pub struct SceneData { + pub scene_path: String, +} + + #[derive(Component)] pub struct SceneRoot; @@ -150,20 +156,33 @@ fn init_scene_loading( mut st_next: ResMut>, ) { if let Some(id) = er.read().last() { - let name = &**id; - let path = format!("gltf/{name}.gltf"); + // let name = &**id; + // let path = format!("gltf/{name}.gltf"); - // Avoid trying to re-load this scene if it's already active - if let Some(active_scene_path) = - r_active_scene.and_then(|scene| scene.source.path().cloned()) - { - if active_scene_path == AssetPath::parse(&path) { - return; - } - } + // // Avoid trying to re-load this scene if it's already active + // if let Some(active_scene_path) = + // r_active_scene.and_then(|scene| scene.source.path().cloned()) + // { + // if active_scene_path == AssetPath::parse(&path) { + // return; + // } + // } - cmd.insert_resource(PendingScene(assets.load(path))); - st_next.set(SceneState::Loading); + // cmd.insert_resource(PendingScene(assets.load(path))); + // st_next.set(SceneState::Loading); + + info!("Loading scene: {}", id.0); + + cmd.spawn(( + SpatialBundle::default(), + space_editor::prelude::GltfPrefab { + path: format!("gltf/{}.gltf", id.0), + scene: "Scene0".to_string(), + }, + PrefabMarker, + SceneElement + )); + } }