fix pcvr
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -14,6 +14,7 @@ impl Plugin for OxrActionAttachingPlugin {
|
||||
|
||||
fn attach_sets(session: Res<OxrSession>, mut events: EventReader<OxrAttachActionSet>) {
|
||||
let sets = events.read().map(|v| &v.0).collect::<Vec<_>>();
|
||||
if sets.is_empty() {return;}
|
||||
info!("attaching {} sessions", sets.len());
|
||||
match session.attach_action_sets(&sets) {
|
||||
Ok(_) => {info!("attached sessions!")}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -83,6 +83,9 @@ pub fn create_passthrough(
|
||||
|
||||
#[inline]
|
||||
pub fn supports_passthrough(instance: &OxrInstance, system: OxrSystemId) -> Result<bool> {
|
||||
if instance.exts().fb_passthrough.is_none() {
|
||||
return Ok(false);
|
||||
}
|
||||
unsafe {
|
||||
let mut hand = openxr::sys::SystemPassthroughProperties2FB {
|
||||
ty: SystemPassthroughProperties2FB::TYPE,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
plugins
|
||||
@@ -37,6 +41,7 @@ pub fn add_xr_plugins<G: PluginGroup>(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<G: PluginGroup>(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)
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<OxrGraphicsInfo>),
|
||||
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::<OxrPrimaryReferenceSpace>),
|
||||
update_views_render_world,
|
||||
)
|
||||
.chain()
|
||||
|
||||
Reference in New Issue
Block a user