diff --git a/src/main.rs b/src/main.rs index 171f361..84c797a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ use bevy_mod_openxr::render::{OxrRenderPlugin, OxrWaitFrameSystem}; use bevy_mod_openxr::resources::{OxrFrameState, OxrFrameWaiter, OxrSessionConfig}; use bevy_mod_openxr::types::AppInfo; use bevy_mod_xr::camera::XrProjection; -use bevy_mod_xr::session::{XrFirst, XrHandleEvents}; +use bevy_mod_xr::session::{XrFirst, XrHandleEvents, XrSessionPlugin}; use clap::Parser; use core::client::{Client, tick_internal_client}; use core::entity_handle::EntityHandlePlugin; @@ -271,7 +271,8 @@ fn bevy_loop( .add(ScenePlugin) .add(GltfPlugin::default()) .add(AudioPlugin::default()) - .add(GizmoPlugin); + .add(GizmoPlugin) + .add(WindowPlugin::default()); let mut task_pool_plugin = TaskPoolPlugin::default(); // make tokio work let handle = tokio::runtime::Handle::current(); @@ -298,8 +299,8 @@ fn bevy_loop( .disable::() .add(FlatscreenInputPlugin); } - app.add_plugins( - add_xr_plugins(plugins.add(WindowPlugin::default())) + app.add_plugins(if !args.flatscreen { + add_xr_plugins(plugins) .set(OxrInitPlugin { app_info: AppInfo { name: "Stardust XR".into(), @@ -328,8 +329,11 @@ fn bevy_loop( .disable::() // we don't do any action stuff that needs to integrate with the ecosystem .disable::() - .disable::(), - ); + .disable::() + } else { + // enable a event + plugins.add(XrSessionPlugin { auto_handle: false }) + }); app.add_plugins(( bevy_sk::hand::HandPlugin, @@ -447,6 +451,4 @@ fn xr_step(world: &mut World) { tick_internal_client(); #[cfg(feature = "wayland")] wayland.update(); - // drawable::draw(token); - // audio::update(); } diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index f58d73d..32bb927 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -29,25 +29,7 @@ pub struct LinesNodePlugin; impl Plugin for LinesNodePlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, (build_line_mesh/* , update_visibillity */).chain()); - } -} - -fn update_visibillity(mut cmds: Commands) { - for lines in LINES_REGISTRY.get_valid_contents().into_iter() { - let Some(entity) = lines.entity.get().map(|e| **e) else { - continue; - }; - match lines.spatial.node().map(|n| n.enabled()).unwrap_or(false) { - true => { - cmds.entity(entity) - .insert_recursive::(Visibility::Visible); - } - false => { - cmds.entity(entity) - .insert_recursive::(Visibility::Hidden); - } - } + app.add_systems(Update, build_line_mesh); } } diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index 43c5519..582a211 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -33,7 +33,7 @@ impl Plugin for ModelNodePlugin { PostUpdate, ( gen_model_parts, - apply_materials, /* , update_visibillity */ + apply_materials, ) .chain(), ); @@ -43,24 +43,6 @@ impl Plugin for ModelNodePlugin { #[derive(Component)] struct ModelNode(Weak); -fn update_visibillity(mut cmds: Commands) { - for model in MODEL_REGISTRY.get_valid_contents().into_iter() { - let Some(entity) = model.bevy_scene_entity.get() else { - continue; - }; - match model.spatial.node().map(|n| n.enabled()).unwrap_or(false) { - true => { - cmds.entity(entity.0) - .insert_recursive::(Visibility::Visible); - } - false => { - cmds.entity(entity.0) - .insert_recursive::(Visibility::Hidden); - } - } - } -} - fn load_models( asset_server: Res, mut cmds: Commands, diff --git a/src/objects/input/oxr_controller.rs b/src/objects/input/oxr_controller.rs index eceeefe..40db76f 100644 --- a/src/objects/input/oxr_controller.rs +++ b/src/objects/input/oxr_controller.rs @@ -60,7 +60,7 @@ impl Plugin for ControllerPlugin { ); app.add_systems(XrPreDestroySession, destroy_spaces); app.add_systems(Startup, setup.run_if(resource_exists::)); - app.add_systems(PreFrameWait, update); + app.add_systems(PreFrameWait, update.run_if(resource_exists::)); } } diff --git a/src/objects/input/oxr_hand.rs b/src/objects/input/oxr_hand.rs index ba695d7..1641c8f 100644 --- a/src/objects/input/oxr_hand.rs +++ b/src/objects/input/oxr_hand.rs @@ -31,7 +31,7 @@ use super::{CaptureManager, get_sorted_handlers}; pub struct HandPlugin; impl Plugin for HandPlugin { fn build(&self, app: &mut App) { - app.add_systems(PreFrameWait, update_hands); + app.add_systems(PreFrameWait, update_hands.run_if(resource_exists::)); app.add_systems(XrSessionCreated, create_trackers); app.add_systems(XrPreDestroySession, destroy_trackers); app.add_systems(PostUpdate, update_hand_material);