diff --git a/.gitignore b/.gitignore index 1a7f33a3..7b6a0165 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ sponza* # Checking in a socket is probably a terrible idea *.socket + +# Ignore vscode settings +.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c66e9925..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "[glsl]": { - "editor.formatOnSave": false - }, - "files.insertFinalNewline": true, - "files.trimFinalNewlines": true, - "files.trimTrailingWhitespace": true, - "webgl-glsl-editor.format.placeSpaceAfterKeywords": true, - "rust-analyzer.check.extraArgs": [ - "--target-dir", - "C:/windows/temp/rust-analyzer-check" - ], -} diff --git a/examples/simple-scene/src/lib.rs b/examples/simple-scene/src/lib.rs index 26b35dc7..d928b3cc 100644 --- a/examples/simple-scene/src/lib.rs +++ b/examples/simple-scene/src/lib.rs @@ -2,7 +2,7 @@ use hotham::{ asset_importer::{self, add_model_to_world}, components::{ hand::Handedness, physics::SharedShape, Collider, GlobalTransform, Info, LocalTransform, - Mesh, RigidBody, HMD, + Mesh, }, hecs::World, systems::{ @@ -69,7 +69,7 @@ fn sync_with_editor( world: &mut World, editor: &mut hotham_editor_protocol::EditorClient, ) -> HothamResult<()> { - use hotham::hecs::{Entity, Or}; + use hotham::hecs::Entity; let entities = world .query_mut::<(&GlobalTransform, &Info)>() .with::<&Mesh>() diff --git a/hotham-editor/README.md b/hotham-editor/README.md new file mode 100644 index 00000000..73677c74 --- /dev/null +++ b/hotham-editor/README.md @@ -0,0 +1,22 @@ +# Hotham Editor +> 🚧 **UNDER CONSTRUCTION** 🚧 +> +> **WARNING**: Even more so than the rest of Hotham, this crate is under *heavy* construction. While it is technically usable in its current state its design may change: at any time. You have been warned! + +## Future plans +The ideal state for the Hotham editor is that it will make it easier to build VR games. That's a pretty ambitious goal, but that is, after all, the whole *point* of Hotham. + +Game Editors are notoriously tricky pieces of technology to define, but here are a couple of things we'd like to be able to do: + +1. Define the *initial state* for some part of a game (eg. a "scene" or a "level") +1. Inspect the *current state* of the game to debug it + +That shouldn't be too hard, right? + +It's also worth noting that the editor will *completely replace* Hotham simulator. + +## Current state +Currently, it's possible to do the following: + +- Run `simple-scene-example` with the `editor` feature +- Manipulate the transform of an entity diff --git a/hotham-editor/src/gui.rs b/hotham-editor/src/gui.rs index 3fc5e5b2..a5660c4a 100644 --- a/hotham-editor/src/gui.rs +++ b/hotham-editor/src/gui.rs @@ -1,48 +1,50 @@ use glam::Vec2; -use yakui::widgets::{List, Panel}; +use hotham_editor_protocol::scene::EditorEntity; +use yakui::widgets::{List, Pad}; use yakui::{ - column, expanded, image, label, row, text, textbox, use_state, CrossAxisAlignment, TextureId, + column, image, label, pad, row, slider, text, textbox, use_state, CrossAxisAlignment, TextureId, }; -pub fn gui(gui_state: GuiState) { - let scene = gui_state.scene; +pub fn gui(gui_state: &mut GuiState) { + let scene = &gui_state.scene; + let updates = &mut gui_state.updates; + let mut main_row = List::row(); row(|| { column(|| { image(gui_state.texture_id, Vec2::new(500., 500.)); }); - column(|| { - text(42., scene.name); - expanded(|| { - let panel = Panel::side(); - panel.show(|| { - let mut column = List::column(); - column.cross_axis_alignment = CrossAxisAlignment::Start; - - column.show(|| { - for entity in scene.entities { - row(|| { - text(20., "Name"); - }); - row(|| { - text(20., entity.name); - }); - row(|| { - text(20., "Translation"); - }); - row(|| { - text(20., format!("{:?}", entity.transform.translation)); - }); - } + pad(Pad::all(20.0), || { + let mut column = List::column(); + column.cross_axis_alignment = CrossAxisAlignment::Start; - label("Input"); - let name = use_state(|| String::from("Hello")); + column.show(|| { + text(42., scene.name.clone()); + for entity in &scene.entities { + row(|| { + label("Name"); + }); + row(|| { + text(20., entity.name.clone()); + }); + row(|| { + label("Translation"); + }); + row(|| { + yakui::column(|| { + label("x"); + let x = entity.transform.translation.x as f64; + let x_state = use_state(move || x); + label(x_state.get().to_string()); - let res = textbox(name.borrow().clone()); - if let Some(new_name) = res.text.as_ref() { - name.set(new_name.clone()); - } + if let Some(new_x) = slider(x_state.get(), -5.0, 5.0).value { + let mut new_entity = entity.clone(); + x_state.set(new_x); + new_entity.transform.translation.x = new_x as _; + updates.push(new_entity); + } + }); }); - }); + } }); }); }); @@ -51,4 +53,5 @@ pub fn gui(gui_state: GuiState) { pub struct GuiState { pub texture_id: TextureId, pub scene: hotham_editor_protocol::scene::Scene, + pub updates: Vec, } diff --git a/hotham-editor/src/main.rs b/hotham-editor/src/main.rs index e09d43fa..2732c5fb 100644 --- a/hotham-editor/src/main.rs +++ b/hotham-editor/src/main.rs @@ -132,6 +132,9 @@ pub fn main() -> Result<()> { let mut winit_initializing = true; let mut focused = false; let mut right_mouse_clicked = false; + let mut updates = EditorUpdates { + entity_updates: vec![], + }; event_loop.run_return(|event, _, control_flow| { *control_flow = ControlFlow::Poll; @@ -183,25 +186,13 @@ pub fn main() -> Result<()> { openxr_server.send_response(&framebuffer_index).unwrap(); let scene: hotham_editor_protocol::scene::Scene = game_server.get_json().unwrap(); - - let entity_updates = if right_mouse_clicked { - let mut helmet = scene - .entities - .iter() - .find(|e| e.name.as_str() == "Damaged Helmet") - .unwrap() - .clone(); - helmet.transform.translation.y += 0.1; - debug!("Sending update: {helmet:?}"); - vec![helmet] - } else { - vec![] - }; - + let mut gui_state = GuiState { texture_id: yak_images[framebuffer_index as usize], scene, updates: vec![] }; game_server - .send_json(&EditorUpdates { entity_updates }) + .send_json(&updates) .unwrap(); + updates.entity_updates.clear(); + // game has finished rendering its frame here check_request(&mut openxr_server, RequestType::LocateView).unwrap(); @@ -210,15 +201,14 @@ pub fn main() -> Result<()> { check_request(&mut openxr_server, RequestType::EndFrame).unwrap(); openxr_server.send_response(&0).unwrap(); - let gui_state = GuiState { - texture_id: yak_images[framebuffer_index as usize], - scene, - }; yak.start(); - gui(gui_state); + gui(&mut gui_state); yak.finish(); + updates.entity_updates = gui_state.updates; + + let context = lazy_vulkan.context(); let yakui_vulkan_context = yakui_vulkan::VulkanContext::new( &context.device, diff --git a/hotham-openxr-client/test.ps1 b/hotham-openxr-client/test.ps1 index aea1e4dc..9fdfad98 100644 --- a/hotham-openxr-client/test.ps1 +++ b/hotham-openxr-client/test.ps1 @@ -1,6 +1,11 @@ Write-Output "All your OpenXR are belong to crab" ${Env:RUST_BACKTRACE} = 1 +Write-Output "Starting editor.." Start-Job -ScriptBlock { cargo run --bin hotham-editor } -Start-Sleep -Seconds 1 + +Write-Output "Sleeping.." +Start-Sleep -Seconds 5 + +Write-Output "Starting game.." cargo run --release --bin hotham_simple_scene_example --features editor