add openxr specific session running and available conditions
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -14,5 +14,6 @@ bevy = { version = "0.14.0", default-features = false, features = [
|
|||||||
"bevy_render",
|
"bevy_render",
|
||||||
"bevy_core_pipeline",
|
"bevy_core_pipeline",
|
||||||
"bevy_winit",
|
"bevy_winit",
|
||||||
|
"bevy_pbr",
|
||||||
"x11",
|
"x11",
|
||||||
] }
|
] }
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::session::OxrSession;
|
use crate::{openxr_session_running, session::OxrSession};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_mod_xr::session::session_running;
|
|
||||||
|
|
||||||
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct OxrActionSetSyncSet;
|
pub struct OxrActionSetSyncSet;
|
||||||
@@ -10,7 +9,9 @@ impl Plugin for OxrActionSyncingPlugin {
|
|||||||
app.add_event::<OxrSyncActionSet>();
|
app.add_event::<OxrSyncActionSet>();
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
sync_sets.in_set(OxrActionSetSyncSet).run_if(session_running), // .in_set(OxrPreUpdateSet::SyncActions),
|
sync_sets
|
||||||
|
.in_set(OxrActionSetSyncSet)
|
||||||
|
.run_if(openxr_session_running),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy_mod_xr::hands::{HandBone, HandBoneRadius};
|
||||||
use bevy_mod_xr::hands::{LeftHand, RightHand, XrHandBoneEntities, HAND_JOINT_COUNT};
|
use bevy_mod_xr::hands::{LeftHand, RightHand, XrHandBoneEntities, HAND_JOINT_COUNT};
|
||||||
use bevy_mod_xr::session::{XrPreDestroySession, XrSessionCreated, XrTrackingRoot};
|
use bevy_mod_xr::session::{XrPreDestroySession, XrSessionCreated, XrTrackingRoot};
|
||||||
use bevy_mod_xr::spaces::{XrPrimaryReferenceSpace, XrReferenceSpace, XrVelocity};
|
use bevy_mod_xr::spaces::{XrPrimaryReferenceSpace, XrReferenceSpace, XrVelocity};
|
||||||
use bevy_mod_xr::{
|
|
||||||
hands::{HandBone, HandBoneRadius},
|
|
||||||
session::session_running,
|
|
||||||
};
|
|
||||||
use openxr::{SpaceLocationFlags, SpaceVelocityFlags};
|
use openxr::{SpaceLocationFlags, SpaceVelocityFlags};
|
||||||
|
|
||||||
use crate::helper_traits::ToVec3;
|
use crate::helper_traits::ToVec3;
|
||||||
|
use crate::openxr_session_running;
|
||||||
use crate::resources::OxrFrameState;
|
use crate::resources::OxrFrameState;
|
||||||
use crate::resources::Pipelined;
|
use crate::resources::Pipelined;
|
||||||
use crate::session::OxrSession;
|
use crate::session::OxrSession;
|
||||||
@@ -27,7 +25,7 @@ impl Default for HandTrackingPlugin {
|
|||||||
|
|
||||||
impl Plugin for HandTrackingPlugin {
|
impl Plugin for HandTrackingPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(PreUpdate, locate_hands.run_if(session_running));
|
app.add_systems(PreUpdate, locate_hands.run_if(openxr_session_running));
|
||||||
if self.default_hands {
|
if self.default_hands {
|
||||||
app.add_systems(XrPreDestroySession, clean_up_default_hands)
|
app.add_systems(XrPreDestroySession, clean_up_default_hands)
|
||||||
.add_systems(XrSessionCreated, spawn_default_hands);
|
.add_systems(XrSessionCreated, spawn_default_hands);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_mod_xr::session::session_available;
|
|
||||||
use openxr::sys;
|
use openxr::sys;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
next_chain::{OxrNextChainStructBase, OxrNextChainStructProvider},
|
next_chain::{OxrNextChainStructBase, OxrNextChainStructProvider},
|
||||||
openxr::exts::OxrEnabledExtensions,
|
openxr::exts::OxrEnabledExtensions,
|
||||||
|
openxr_session_available,
|
||||||
session::{OxrSessionCreateNextChain, OxrSessionCreateNextProvider},
|
session::{OxrSessionCreateNextChain, OxrSessionCreateNextProvider},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,7 +16,10 @@ impl Plugin for OxrOverlayPlugin {
|
|||||||
fn build(&self, app: &mut bevy::prelude::App) {
|
fn build(&self, app: &mut bevy::prelude::App) {
|
||||||
app.add_event::<OxrOverlaySessionEvent>();
|
app.add_event::<OxrOverlaySessionEvent>();
|
||||||
app.init_resource::<OxrOverlaySettings>();
|
app.init_resource::<OxrOverlaySettings>();
|
||||||
app.add_systems(First, add_overlay_info_to_chain.run_if(session_available));
|
app.add_systems(
|
||||||
|
First,
|
||||||
|
add_overlay_info_to_chain.run_if(openxr_session_available),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use bevy::ecs::system::RunSystemOnce;
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::render::extract_resource::ExtractResource;
|
|
||||||
use bevy::render::extract_resource::ExtractResourcePlugin;
|
use bevy::render::extract_resource::ExtractResourcePlugin;
|
||||||
use bevy::render::renderer::RenderAdapter;
|
use bevy::render::renderer::RenderAdapter;
|
||||||
use bevy::render::renderer::RenderAdapterInfo;
|
use bevy::render::renderer::RenderAdapterInfo;
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
// use actions::XrActionPlugin;
|
// use actions::XrActionPlugin;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{PluginGroup, PluginGroupBuilder},
|
app::{PluginGroup, PluginGroupBuilder},
|
||||||
|
prelude::Res,
|
||||||
render::RenderPlugin,
|
render::RenderPlugin,
|
||||||
utils::default,
|
utils::default,
|
||||||
window::{PresentMode, Window, WindowPlugin},
|
window::{PresentMode, Window, WindowPlugin},
|
||||||
};
|
};
|
||||||
use bevy_mod_xr::camera::XrCameraPlugin;
|
|
||||||
use bevy_mod_xr::session::XrSessionPlugin;
|
use bevy_mod_xr::session::XrSessionPlugin;
|
||||||
|
use bevy_mod_xr::{camera::XrCameraPlugin, session::XrState};
|
||||||
use init::OxrInitPlugin;
|
use init::OxrInitPlugin;
|
||||||
use render::OxrRenderPlugin;
|
use render::OxrRenderPlugin;
|
||||||
|
use resources::OxrInstance;
|
||||||
|
use session::OxrSession;
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
features::{handtracking::HandTrackingPlugin, passthrough::OxrPassthroughPlugin},
|
features::{handtracking::HandTrackingPlugin, passthrough::OxrPassthroughPlugin},
|
||||||
@@ -33,6 +36,23 @@ pub mod session;
|
|||||||
pub mod spaces;
|
pub mod spaces;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the OpenXR session is available.
|
||||||
|
pub fn openxr_session_available(
|
||||||
|
status: Option<Res<XrState>>,
|
||||||
|
instance: Option<Res<OxrInstance>>,
|
||||||
|
) -> bool {
|
||||||
|
status.is_some_and(|s| *s != XrState::Unavailable) && instance.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the OpenXR is running.
|
||||||
|
/// use this when working with OpenXR specific things
|
||||||
|
pub fn openxr_session_running(
|
||||||
|
status: Option<Res<XrState>>,
|
||||||
|
session: Option<Res<OxrSession>>,
|
||||||
|
) -> bool {
|
||||||
|
matches!(status.as_deref(), Some(XrState::Running)) & session.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||||
plugins
|
plugins
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use bevy_mod_xr::{
|
|||||||
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace},
|
spaces::{XrPrimaryReferenceSpace, XrReferenceSpace},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{init::create_xr_session, session::OxrSession};
|
use crate::session::OxrSession;
|
||||||
|
|
||||||
pub struct OxrReferenceSpacePlugin {
|
pub struct OxrReferenceSpacePlugin {
|
||||||
pub default_primary_ref_space: openxr::ReferenceSpaceType,
|
pub default_primary_ref_space: openxr::ReferenceSpaceType,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::{mem::MaybeUninit, ptr, sync::Mutex};
|
|||||||
|
|
||||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||||
use bevy_mod_xr::{
|
use bevy_mod_xr::{
|
||||||
session::{session_available, session_running, XrFirst, XrHandleEvents},
|
session::{XrFirst, XrHandleEvents},
|
||||||
spaces::{XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrVelocity},
|
spaces::{XrDestroySpace, XrPrimaryReferenceSpace, XrReferenceSpace, XrSpace, XrVelocity},
|
||||||
types::XrPose,
|
types::XrPose,
|
||||||
};
|
};
|
||||||
@@ -13,6 +13,7 @@ use openxr::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
helper_traits::{ToPosef, ToQuat, ToVec3},
|
helper_traits::{ToPosef, ToQuat, ToVec3},
|
||||||
|
openxr_session_available, openxr_session_running,
|
||||||
resources::{OxrFrameState, OxrInstance, Pipelined},
|
resources::{OxrFrameState, OxrInstance, Pipelined},
|
||||||
session::OxrSession,
|
session::OxrSession,
|
||||||
};
|
};
|
||||||
@@ -24,7 +25,10 @@ pub struct OxrSpaceSyncSet;
|
|||||||
pub struct OxrSpacePatchingPlugin;
|
pub struct OxrSpacePatchingPlugin;
|
||||||
impl Plugin for OxrSpacePatchingPlugin {
|
impl Plugin for OxrSpacePatchingPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, patch_destroy_space.run_if(session_available));
|
app.add_systems(
|
||||||
|
Startup,
|
||||||
|
patch_destroy_space.run_if(openxr_session_available),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,13 +40,13 @@ impl Plugin for OxrSpatialPlugin {
|
|||||||
XrFirst,
|
XrFirst,
|
||||||
destroy_space_event
|
destroy_space_event
|
||||||
.before(XrHandleEvents::Poll)
|
.before(XrHandleEvents::Poll)
|
||||||
.run_if(session_available),
|
.run_if(openxr_session_available),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
PreUpdate,
|
PreUpdate,
|
||||||
update_space_transforms
|
update_space_transforms
|
||||||
.in_set(OxrSpaceSyncSet)
|
.in_set(OxrSpaceSyncSet)
|
||||||
.run_if(session_running),
|
.run_if(openxr_session_running),
|
||||||
)
|
)
|
||||||
.observe(add_location_flags)
|
.observe(add_location_flags)
|
||||||
.observe(add_velocity_flags);
|
.observe(add_velocity_flags);
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ pub fn status_changed_to(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the XR session is available. Returns true as long as [`XrState`] exists and isn't [`Unavailable`](XrStatus::Unavailable).
|
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the XR session is available. Returns true as long as [`XrState`] exists and isn't [`Unavailable`](XrStatus::Unavailable).
|
||||||
|
/// When using backend specific resources use the backend specific condition
|
||||||
pub fn session_available(status: Option<Res<XrState>>) -> bool {
|
pub fn session_available(status: Option<Res<XrState>>) -> bool {
|
||||||
status.is_some_and(|s| *s != XrState::Unavailable)
|
status.is_some_and(|s| *s != XrState::Unavailable)
|
||||||
}
|
}
|
||||||
@@ -282,7 +283,8 @@ pub fn session_ready_or_running(status: Option<Res<XrState>>) -> bool {
|
|||||||
matches!(status.as_deref(), Some(XrState::Ready | XrState::Running))
|
matches!(status.as_deref(), Some(XrState::Ready | XrState::Running))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the XR session is running
|
/// A [`Condition`](bevy::ecs::schedule::Condition) system that says if the XR session is running.
|
||||||
|
/// When using backend specific resources use the backend specific condition
|
||||||
pub fn session_running(status: Option<Res<XrState>>) -> bool {
|
pub fn session_running(status: Option<Res<XrState>>) -> bool {
|
||||||
matches!(status.as_deref(), Some(XrState::Running))
|
matches!(status.as_deref(), Some(XrState::Running))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user