diff --git a/crates/bevy_openxr/examples/actions.rs b/crates/bevy_openxr/examples/actions.rs index 81070f8..3a77df4 100644 --- a/crates/bevy_openxr/examples/actions.rs +++ b/crates/bevy_openxr/examples/actions.rs @@ -139,7 +139,7 @@ fn handle_flight_input( let view = views.first(); match view { Some(v) => { - let reference_quat = root_position.rotation.inverse() * v.pose.orientation.to_quat(); + let reference_quat = root_position.rotation * v.pose.orientation.to_quat(); let locomotion_vector = reference_quat.mul_vec3(input_vector); root_position.translation += diff --git a/crates/bevy_openxr/src/openxr/init.rs b/crates/bevy_openxr/src/openxr/init.rs index b07af03..e0c4ccf 100644 --- a/crates/bevy_openxr/src/openxr/init.rs +++ b/crates/bevy_openxr/src/openxr/init.rs @@ -77,7 +77,7 @@ impl Default for OxrInitPlugin { backends: default(), formats: Some(vec![wgpu::TextureFormat::Rgba8UnormSrgb]), resolutions: default(), - synchronous_pipeline_compilation: default(), + synchronous_pipeline_compilation: false, } } } @@ -118,9 +118,10 @@ impl Plugin for OxrInitPlugin { destroy_xr_session, (|v: Res| { v.0.store(true, Ordering::Relaxed); - info!("setting destroy render session"); + debug!("setting destroy render session"); }), ) + .chain() .run_if(state_matches!(XrState::Exiting { .. })) .run_if(on_event::), begin_xr_session @@ -132,6 +133,7 @@ impl Plugin for OxrInitPlugin { request_exit_xr_session .run_if(session_created) .run_if(on_event::), + detect_session_destroyed, ) .in_set(XrHandleEvents::SessionStateUpdateEvents), ) @@ -170,18 +172,37 @@ impl Plugin for OxrInitPlugin { fn finish(&self, app: &mut App) { app.sub_app_mut(RenderApp).add_systems( Render, - (destroy_xr_session, |v: Res| { - v.0.store(false, Ordering::Relaxed) - }) + ( + destroy_xr_session, + |v: Res, mut cmds: Commands| { + v.0.store(false, Ordering::Relaxed); + cmds.insert_resource(XrState::Available); + }, + ) + .chain() .run_if( resource_exists:: .and(|v: Res| v.0.load(Ordering::Relaxed)), - ) - .chain(), + ), ); } } +fn detect_session_destroyed( + mut last_state: Local, + state: Res, + mut sender: EventWriter, + mut cmds: Commands, +) { + let state = state.0.load(Ordering::Relaxed); + if *last_state && !state { + debug!("XrSession was fully destroyed!"); + sender.send_default(); + cmds.insert_resource(XrState::Available); + } + *last_state = state; +} + impl OxrInitPlugin { fn init_xr( &self, diff --git a/crates/bevy_xr/src/session.rs b/crates/bevy_xr/src/session.rs index 56de566..b02a27c 100644 --- a/crates/bevy_xr/src/session.rs +++ b/crates/bevy_xr/src/session.rs @@ -46,10 +46,14 @@ pub struct XrPostSessionBegin; #[derive(Event, Clone, Copy, Default)] pub struct XrEndSessionEvent; -/// Schedule thats rna whenever the XrSession is about to end +/// Schedule thats ran whenever the XrSession is about to end #[derive(Clone, Copy, Default, PartialEq, Eq, Debug, Hash, ScheduleLabel)] pub struct XrPreSessionEnd; +/// Event that is emitted when the XrSession is fully destroyed +#[derive(Clone, Copy, Default, PartialEq, Eq, Debug, Hash, Event)] +pub struct XrSessionDestroyedEvent; + /// Event sent to backends to request the [`XrState`] proceed to [`Exiting`](XrState::Exiting) and for the session to be exited. Can be called at any time a session exists. #[derive(Event, Clone, Copy, Default)] pub struct XrRequestExitEvent; @@ -130,6 +134,7 @@ impl Plugin for XrSessionPlugin { .add_event::() .add_event::() .add_event::() + .add_event::() .init_schedule(XrSessionCreated) .init_schedule(XrPreDestroySession) .init_schedule(XrPostSessionBegin)