Skip to content

Commit

Permalink
[Editor] Finish first pass at editor GUI
Browse files Browse the repository at this point in the history
Fixes #419
  • Loading branch information
kanerogers committed Mar 1, 2023
1 parent 4219b67 commit 901a0c9
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ sponza*

# Checking in a socket is probably a terrible idea
*.socket

# Ignore vscode settings
.vscode/settings.json
14 changes: 0 additions & 14 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions examples/simple-scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -69,7 +69,7 @@ fn sync_with_editor(
world: &mut World,
editor: &mut hotham_editor_protocol::EditorClient<uds_windows::UnixStream>,
) -> HothamResult<()> {
use hotham::hecs::{Entity, Or};
use hotham::hecs::Entity;
let entities = world
.query_mut::<(&GlobalTransform, &Info)>()
.with::<&Mesh>()
Expand Down
22 changes: 22 additions & 0 deletions hotham-editor/README.md
Original file line number Diff line number Diff line change
@@ -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
71 changes: 37 additions & 34 deletions hotham-editor/src/gui.rs
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
});
}
});
});
});
Expand All @@ -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<EditorEntity>,
}
32 changes: 11 additions & 21 deletions hotham-editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion hotham-openxr-client/test.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 901a0c9

Please sign in to comment.