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