diff --git a/crates/bevy_openxr/Cargo.toml b/crates/bevy_openxr/Cargo.toml index 6093bfc..88541d4 100644 --- a/crates/bevy_openxr/Cargo.toml +++ b/crates/bevy_openxr/Cargo.toml @@ -8,6 +8,9 @@ default = ["vulkan", "passthrough"] vulkan = ["dep:ash"] passthrough = [] +[dev-dependencies] +bevy_xr_utils.path = "../bevy_xr_utils" + # bevy can't be placed behind target or proc macros won't work properly [dependencies] bevy.workspace = true diff --git a/crates/bevy_openxr/examples/3d_scene.rs b/crates/bevy_openxr/examples/3d_scene.rs index fa0c4a0..65e778a 100644 --- a/crates/bevy_openxr/examples/3d_scene.rs +++ b/crates/bevy_openxr/examples/3d_scene.rs @@ -6,6 +6,7 @@ use bevy_openxr::add_xr_plugins; fn main() { App::new() .add_plugins(add_xr_plugins(DefaultPlugins)) + .add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin) .add_systems(Startup, setup) .run(); } @@ -38,5 +39,8 @@ fn setup( }, transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() + }); commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() }); } diff --git a/crates/bevy_openxr/examples/android/src/lib.rs b/crates/bevy_openxr/examples/android/src/lib.rs index 6ac9124..e3c66c1 100644 --- a/crates/bevy_openxr/examples/android/src/lib.rs +++ b/crates/bevy_openxr/examples/android/src/lib.rs @@ -1,10 +1,7 @@ //! A simple 3D scene with light shining over a cube sitting on a plane. use bevy::prelude::*; -use bevy_openxr::{ - add_xr_plugins, features::handtracking::HandTrackingPlugin, init::OxrInitPlugin, - reference_space::OxrReferenceSpacePlugin, types::OxrExtensions, -}; +use bevy_openxr::{add_xr_plugins, init::OxrInitPlugin, types::OxrExtensions}; #[bevy_main] fn main() { @@ -23,8 +20,6 @@ fn main() { resolutions: default(), synchronous_pipeline_compilation: default(), })) - .add_plugins(HandTrackingPlugin::default()) - .add_plugins(OxrReferenceSpacePlugin::default()) .add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin) .add_systems(Startup, setup) .insert_resource(ClearColor(Color::NONE)) diff --git a/crates/bevy_openxr/src/openxr/action_set_attaching.rs b/crates/bevy_openxr/src/openxr/action_set_attaching.rs index f9abac8..b788458 100644 --- a/crates/bevy_openxr/src/openxr/action_set_attaching.rs +++ b/crates/bevy_openxr/src/openxr/action_set_attaching.rs @@ -14,6 +14,7 @@ impl Plugin for OxrActionAttachingPlugin { fn attach_sets(session: Res, mut events: EventReader) { let sets = events.read().map(|v| &v.0).collect::>(); + if sets.is_empty() {return;} info!("attaching {} sessions", sets.len()); match session.attach_action_sets(&sets) { Ok(_) => {info!("attached sessions!")} diff --git a/crates/bevy_openxr/src/openxr/features/handtracking.rs b/crates/bevy_openxr/src/openxr/features/handtracking.rs index 069e0c0..9305c55 100644 --- a/crates/bevy_openxr/src/openxr/features/handtracking.rs +++ b/crates/bevy_openxr/src/openxr/features/handtracking.rs @@ -6,7 +6,9 @@ use bevy_xr::{ use openxr::SpaceLocationFlags; use crate::{ - init::OxrTrackingRoot, reference_space::{OxrPrimaryReferenceSpace, OxrReferenceSpace}, resources::{OxrSession, OxrTime} + init::OxrTrackingRoot, + reference_space::{OxrPrimaryReferenceSpace, OxrReferenceSpace}, + resources::{OxrSession, OxrTime}, }; pub struct HandTrackingPlugin { @@ -124,9 +126,7 @@ fn locate_hands( )>, mut bone_query: Query<(&HandBone, &mut HandBoneRadius, &mut Transform)>, ) { - info!("updating hands 0 "); for (tracker, ref_space, hand_entities) in &tracker_query { - info!("updating hands 1 "); let ref_space = ref_space.map(|v| &v.0).unwrap_or(&default_ref_space.0); // relate_hand_joints also provides velocities let joints = match ref_space.locate_hand_joints(tracker, **time) { @@ -149,7 +149,6 @@ fn locate_hands( } }; for (bone, mut bone_radius, mut transform) in bone_entities { - info!("updating hands"); let joint = joints[*bone as usize]; **bone_radius = joint.radius; diff --git a/crates/bevy_openxr/src/openxr/features/passthrough.rs b/crates/bevy_openxr/src/openxr/features/passthrough.rs index 3262210..f8fcea8 100644 --- a/crates/bevy_openxr/src/openxr/features/passthrough.rs +++ b/crates/bevy_openxr/src/openxr/features/passthrough.rs @@ -83,6 +83,9 @@ pub fn create_passthrough( #[inline] pub fn supports_passthrough(instance: &OxrInstance, system: OxrSystemId) -> Result { + if instance.exts().fb_passthrough.is_none() { + return Ok(false); + } unsafe { let mut hand = openxr::sys::SystemPassthroughProperties2FB { ty: SystemPassthroughProperties2FB::TYPE, diff --git a/crates/bevy_openxr/src/openxr/init.rs b/crates/bevy_openxr/src/openxr/init.rs index ae72bcd..ab91dbd 100644 --- a/crates/bevy_openxr/src/openxr/init.rs +++ b/crates/bevy_openxr/src/openxr/init.rs @@ -93,7 +93,7 @@ impl Plugin for OxrInitPlugin { )) .add_systems(First, reset_per_frame_resources) .add_systems( - First, + PreUpdate, ( poll_events .run_if(session_available) diff --git a/crates/bevy_openxr/src/openxr/mod.rs b/crates/bevy_openxr/src/openxr/mod.rs index 923f5fb..9edaa7f 100644 --- a/crates/bevy_openxr/src/openxr/mod.rs +++ b/crates/bevy_openxr/src/openxr/mod.rs @@ -10,21 +10,25 @@ use bevy_xr::session::XrSessionPlugin; use init::OxrInitPlugin; use render::OxrRenderPlugin; -use self::{exts::OxrExtensions, features::passthrough::OxrPassthroughPlugin}; +use self::{ + exts::OxrExtensions, + features::{handtracking::HandTrackingPlugin, passthrough::OxrPassthroughPlugin}, + reference_space::OxrReferenceSpacePlugin, +}; +pub mod action_binding; +pub mod action_set_attaching; pub mod error; mod exts; pub mod features; pub mod graphics; +pub mod helper_traits; pub mod init; pub mod layer_builder; +pub mod reference_space; pub mod render; pub mod resources; pub mod types; -pub mod action_binding; -pub mod action_set_attaching; -pub mod reference_space; -pub mod helper_traits; pub fn add_xr_plugins(plugins: G) -> PluginGroupBuilder { plugins @@ -37,6 +41,7 @@ pub fn add_xr_plugins(plugins: G) -> PluginGroupBuilder { exts: { let mut exts = OxrExtensions::default(); exts.enable_fb_passthrough(); + exts.enable_hand_tracking(); exts }, blend_modes: default(), @@ -45,8 +50,10 @@ pub fn add_xr_plugins(plugins: G) -> PluginGroupBuilder { resolutions: default(), synchronous_pipeline_compilation: default(), }) + .add(OxrReferenceSpacePlugin::default()) .add(OxrRenderPlugin) .add(OxrPassthroughPlugin) + .add(HandTrackingPlugin::default()) .add(XrCameraPlugin) .add(action_set_attaching::OxrActionAttachingPlugin) .add(action_binding::OxrActionBindingPlugin) diff --git a/crates/bevy_openxr/src/openxr/reference_space.rs b/crates/bevy_openxr/src/openxr/reference_space.rs index 03d1807..f4cd3ec 100644 --- a/crates/bevy_openxr/src/openxr/reference_space.rs +++ b/crates/bevy_openxr/src/openxr/reference_space.rs @@ -14,7 +14,7 @@ pub struct OxrReferenceSpacePlugin { impl Default for OxrReferenceSpacePlugin { fn default() -> Self { Self { - default_primary_ref_space: openxr::ReferenceSpaceType::LOCAL_FLOOR_EXT, + default_primary_ref_space: openxr::ReferenceSpaceType::STAGE, } } } diff --git a/crates/bevy_openxr/src/openxr/render.rs b/crates/bevy_openxr/src/openxr/render.rs index a5d52ae..3179b01 100644 --- a/crates/bevy_openxr/src/openxr/render.rs +++ b/crates/bevy_openxr/src/openxr/render.rs @@ -9,7 +9,7 @@ use bevy::{ }, transform::TransformSystem, }; -use bevy_xr::camera::{XrCamera, XrCameraBundle, XrProjection}; +use bevy_xr::{camera::{XrCamera, XrCameraBundle, XrProjection}, session::session_running}; use openxr::ViewStateFlags; use crate::{reference_space::OxrPrimaryReferenceSpace, resources::*}; @@ -28,17 +28,17 @@ impl Plugin for OxrRenderPlugin { ( init_views.run_if(resource_added::), wait_frame.run_if(session_started), - locate_views.run_if(session_started), - update_views.run_if(session_started), + locate_views.run_if(session_running), + update_views.run_if(session_running), ) .chain() - .after(OxrPreUpdateSet::HandleEvents), + .after(OxrPreUpdateSet::UpdateNonCriticalComponents), ) .add_systems( PostUpdate, (locate_views, update_views) .chain() - .run_if(session_started) + .run_if(session_running) .before(TransformSystem::TransformPropagate), ); app.sub_app_mut(RenderApp) @@ -47,7 +47,7 @@ impl Plugin for OxrRenderPlugin { ( ( insert_texture_views, - locate_views, + locate_views.run_if(resource_exists::), update_views_render_world, ) .chain()