Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/beat-saber-clone/assets/beat_saber.glb
Git LFS file not shown
139 changes: 120 additions & 19 deletions examples/beat-saber-clone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,47 @@ mod components;
pub mod resources;
mod systems;

use crate::components::{Colour, Saber};
use crate::resources::GameState;
use crate::systems::cube_spawner::{create_cubes, cube_spawner_system};
use crate::systems::game_system;
use crate::{
components::{Colour, Saber},
resources::GameState,
systems::{
cube_spawner::{create_cubes, cube_spawner_system},
game_system,
sabers::{add_saber_physics, sabers_system},
update_ui_system,
},
};
use hotham_debug_server::DebugServer;
use rapier3d::prelude::{ColliderBuilder, InteractionGroups};
use std::collections::HashMap;

use hotham::gltf_loader::add_model_to_world;
use hotham::legion::{Resources, Schedule, World};
use hotham::resources::{PhysicsContext, RenderContext, XrContext};
use hotham::schedule_functions::{begin_frame, end_frame, physics_step, sync_debug_server};
use hotham::systems::rendering::rendering_system;
use hotham::systems::{
collision_system, update_parent_transform_matrix_system, update_rigid_body_transforms_system,
update_transform_matrix_system,
use hotham::{
components::{
hand::Handedness,
panel::{create_panel, PanelButton},
Collider, Pointer,
},
gltf_loader::{self, add_model_to_world},
legion::{Resources, Schedule, World},
resources::{
physics_context::PANEL_COLLISION_GROUP, GuiContext, HapticContext, PhysicsContext,
RenderContext, XrContext,
},
schedule_functions::{
apply_haptic_feedback, begin_frame, begin_pbr_renderpass, end_frame, end_pbr_renderpass,
physics_step, sync_debug_server,
},
systems::{
collision_system, draw_gui_system, pointers_system, rendering_system,
update_parent_transform_matrix_system, update_rigid_body_transforms_system,
update_transform_matrix_system,
},
util::entity_to_u64,
App, HothamResult,
};
use hotham::{gltf_loader, App, HothamResult};

use nalgebra::{Matrix4, Vector3};
use nalgebra::{vector, Matrix4, Vector3};
use serde::{Deserialize, Serialize};
use systems::sabers::{add_saber_physics, sabers_system};

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
pub fn main() {
Expand All @@ -45,6 +65,7 @@ struct DebugInfo {
pub fn real_main() -> HothamResult<()> {
let (xr_context, vulkan_context) = XrContext::new()?;
let render_context = RenderContext::new(&vulkan_context, &xr_context)?;
let gui_context = GuiContext::new(&vulkan_context);
let mut physics_context = PhysicsContext::default();
let mut world = World::default();
let glb_bufs: Vec<&[u8]> = vec![include_bytes!("../assets/beat_saber.glb")];
Expand All @@ -53,6 +74,7 @@ pub fn real_main() -> HothamResult<()> {
&vulkan_context,
&render_context.descriptor_set_layouts,
)?;
let haptic_context = HapticContext::default();

// Add Environment
add_environment_models(&models, &mut world, &vulkan_context, &render_context);
Expand All @@ -77,48 +99,127 @@ pub fn real_main() -> HothamResult<()> {
&mut physics_context,
);

// Add Blue Saber
add_saber(
// // Add Blue Saber
// add_saber(
// Colour::Blue,
// &models,
// &mut world,
// &vulkan_context,
// &render_context,
// &mut physics_context,
// );

// Add pointer
add_pointer(
Colour::Blue,
&models,
&mut world,
&vulkan_context,
&render_context,
&mut physics_context,
);

// Add a panel
let mut panel_components = create_panel(
"Not clicked!",
800,
800,
&vulkan_context,
&render_context,
&gui_context,
vec![PanelButton::new("Test")],
);
let t = &mut panel_components.3.translation;
t[1] = 1.5;
t[2] = -2.;

let panel_entity = world.push(panel_components);
let collider = ColliderBuilder::cuboid(0.5, 0.5, 0.)
.sensor(true)
.collision_groups(InteractionGroups::new(
PANEL_COLLISION_GROUP,
PANEL_COLLISION_GROUP,
))
.translation(vector![0.0, 1.5, -2.])
.user_data(entity_to_u64(panel_entity).into())
.build();
let handle = physics_context.colliders.insert(collider);
let collider = Collider {
collisions_this_frame: Vec::new(),
handle,
};
let mut panel_entry = world.entry(panel_entity).unwrap();
panel_entry.add_component(collider);

let debug_server = DebugServer::new();

let mut resources = Resources::default();
resources.insert(xr_context);
resources.insert(vulkan_context);
resources.insert(gui_context);
resources.insert(physics_context);
resources.insert(debug_server);
resources.insert(render_context);
resources.insert(models);
resources.insert(0 as usize);
resources.insert(GameState::default());
resources.insert(haptic_context);

let schedule = Schedule::builder()
.add_thread_local_fn(begin_frame)
.add_system(sabers_system())
.add_system(pointers_system())
.add_thread_local_fn(physics_step)
.add_system(collision_system())
.add_system(cube_spawner_system(SPAWN_RATE))
.add_system(update_rigid_body_transforms_system())
.add_system(update_transform_matrix_system())
.add_system(update_parent_transform_matrix_system())
.add_system(game_system())
.add_system(update_ui_system())
.add_system(draw_gui_system())
.add_thread_local_fn(begin_pbr_renderpass)
.add_system(rendering_system())
.add_thread_local_fn(sync_debug_server)
.add_thread_local_fn(end_pbr_renderpass)
.add_thread_local_fn(apply_haptic_feedback)
.add_thread_local_fn(end_frame)
.add_thread_local_fn(sync_debug_server)
.build();

let mut app = App::new(world, resources, schedule)?;
app.run()?;
Ok(())
}

fn add_pointer(
colour: Colour,
models: &HashMap<String, World>,
world: &mut World,
vulkan_context: &hotham::resources::vulkan_context::VulkanContext,
render_context: &RenderContext,
) {
let (handedness, model_name) = match colour {
Colour::Red => (Handedness::Left, "Red Pointer"),
Colour::Blue => (Handedness::Right, "Blue Pointer"),
};
let pointer = add_model_to_world(
model_name,
models,
world,
None,
vulkan_context,
&render_context.descriptor_set_layouts,
)
.unwrap();
{
let mut pointer_entry = world.entry(pointer).unwrap();
pointer_entry.add_component(Pointer {
handedness,
trigger_value: 0.,
});
pointer_entry.add_component(colour);
}
}

fn add_saber(
colour: Colour,
models: &HashMap<String, World>,
Expand Down
4 changes: 1 addition & 3 deletions examples/beat-saber-clone/src/systems/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use legion::{system, systems::CommandBuffer, world::SubWorld, Entity, EntityStor

use crate::{
components::{Colour, Cube},
resources::{game_state, GameState},
resources::GameState,
};

#[system(for_each)]
Expand Down Expand Up @@ -63,8 +63,6 @@ pub fn game(
#[cfg(test)]
mod tests {
use hotham::resources::PhysicsContext;
use hotham::schedule_functions::physics_step;
use hotham::systems::collision_system;
use legion::Schedule;
use legion::{Resources, World};
use nalgebra::{vector, UnitQuaternion};
Expand Down
2 changes: 2 additions & 0 deletions examples/beat-saber-clone/src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod cube_spawner;
pub mod game;
pub mod sabers;
pub mod update_ui;
pub use game::game_system;
pub use sabers::sabers_system;
pub use update_ui::update_ui_system;
6 changes: 3 additions & 3 deletions examples/beat-saber-clone/src/systems/sabers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn sabers(
.unwrap();

let mut position = posef_to_isometry(pose);
apply_offset(&mut position);
apply_grip_offset(&mut position);
rigid_body.set_next_kinematic_position(position);
}

Expand All @@ -77,7 +77,7 @@ pub fn add_saber_physics(world: &mut World, physics_context: &mut PhysicsContext
saber_entry.add_component(rigid_body);
}

fn apply_offset(position: &mut Isometry3<f32>) {
pub fn apply_grip_offset(position: &mut Isometry3<f32>) {
let updated_rotation = position.rotation.quaternion() * ROTATION_OFFSET;
let updated_translation = position.translation.vector
- vector!(POSITION_OFFSET[0], POSITION_OFFSET[1], POSITION_OFFSET[2]);
Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {
));
let t = Translation3::new(0.2, 1.4, 2.);
let mut position = Isometry3::from_parts(t, q1);
apply_offset(&mut position);
apply_grip_offset(&mut position);

let expected_rotation = Quaternion::new(
-0.5493369162990798,
Expand Down
11 changes: 11 additions & 0 deletions examples/beat-saber-clone/src/systems/update_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use hotham::components::Panel;
use legion::system;

use crate::resources::GameState;

#[system(for_each)]
pub fn update_ui(panel: &mut Panel, #[resource] game_state: &GameState) {
let score = game_state.current_score;
let new_string = format!("Current score: {}", score);
panel.text = new_string;
}
2 changes: 2 additions & 0 deletions hotham-simulator/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ pub unsafe extern "system" fn attach_action_sets(
Result::SUCCESS
}

// TODO: Handle aim pose.
pub unsafe extern "system" fn create_action_space(
_session: Session,
create_info: *const ActionSpaceCreateInfo,
Expand Down Expand Up @@ -1066,6 +1067,7 @@ unsafe fn build_swapchain(state: &mut MutexGuard<State>) -> vk::SwapchainKHR {
.with_drag_and_drop(false)
.build(&event_loop)
.unwrap();
println!("WINDOW SCALE FACTOR, {:?}", window.scale_factor());
println!("[HOTHAM_SIMULATOR] ..done.");
let extent = vk::Extent2D {
height: VIEWPORT_HEIGHT,
Expand Down
17 changes: 5 additions & 12 deletions hotham.code-workspace
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
{
"folders": [
{
"path": "hotham"
"path": "."
},
{
"path": "hotham-debug-frontend"
},
{
"path": "hotham-simulator"
},
{
"path": "examples\\beat-saber-clone"
},
{
"path": "hotham-debug-server"
"path": "..\\egui-winit-ash-integration"
}
],
"settings": {
Expand All @@ -26,7 +17,9 @@
"hotham",
"hotham-debug-server",
"hotham-simulator",
"beat-saber-clone"
"beat-saber-clone",
"test_assets"
],
"jest.rootPath": "hotham_debug_frontend",
}
}
4 changes: 3 additions & 1 deletion hotham/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ash = "0.33.2"
console = "0.14"
crossbeam = "0.8.1"
ctrlc = {version = "3", features = ["termination"]}
egui = "0.15"
gltf = {version = "0.16", features = ["KHR_materials_pbrSpecularGlossiness"]}
hotham-debug-server = {path = "../hotham-debug-server"}
image = "0.23"
Expand All @@ -25,7 +26,8 @@ mint = "0.5.6"
nalgebra = {features = ["convert-mint", "serde-serialize"], version = "0.29.0"}
openxr = {features = ["loaded", "mint"], version = "0.15.4"}
rand = "0.8"
rapier3d = "0.11"
rapier3d = "0.11.1"
renderdoc = "0.10"
schemars = "0.8"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
Expand Down
Binary file added hotham/capture_capture.rdc
Binary file not shown.
Binary file added hotham/shaders/gui.frag.spv
Binary file not shown.
Binary file added hotham/shaders/gui.vert.spv
Binary file not shown.
32 changes: 0 additions & 32 deletions hotham/shaders/model.frag

This file was deleted.

Binary file removed hotham/shaders/model.frag.spv
Binary file not shown.
Loading