make the XrCameras children of the OxrTrackingRoot to allow moving of the Tracking Root

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-04-30 00:13:47 +02:00
parent 13890ddb53
commit c2f8d65040

View File

@@ -1,4 +1,5 @@
use bevy::{ use bevy::{
ecs::query::QuerySingleError,
prelude::*, prelude::*,
render::{ render::{
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget}, camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
@@ -14,7 +15,7 @@ use openxr::ViewStateFlags;
use crate::resources::*; use crate::resources::*;
use crate::{ use crate::{
init::{session_started, OxrPreUpdateSet}, init::{session_started, OxrPreUpdateSet, OxrTrackingRoot},
layer_builder::ProjectionLayer, layer_builder::ProjectionLayer,
}; };
@@ -74,29 +75,44 @@ pub fn init_views(
graphics_info: Res<OxrGraphicsInfo>, graphics_info: Res<OxrGraphicsInfo>,
mut manual_texture_views: ResMut<ManualTextureViews>, mut manual_texture_views: ResMut<ManualTextureViews>,
swapchain_images: Res<OxrSwapchainImages>, swapchain_images: Res<OxrSwapchainImages>,
root: Query<Entity, With<OxrTrackingRoot>>,
mut commands: Commands, mut commands: Commands,
) { ) {
let _span = info_span!("xr_init_views"); let _span = info_span!("xr_init_views");
let temp_tex = swapchain_images.first().unwrap(); let temp_tex = swapchain_images.first().unwrap();
// this for loop is to easily add support for quad or mono views in the future. // this for loop is to easily add support for quad or mono views in the future.
let mut views = vec![]; let mut views = Vec::with_capacity(2);
for index in 0..2 { for index in 0..2 {
info!("{}", graphics_info.resolution); info!("{}", graphics_info.resolution);
let view_handle = let view_handle =
add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index); add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index);
commands.spawn(( let cam = commands
XrCameraBundle { .spawn((
camera: Camera { XrCameraBundle {
target: RenderTarget::TextureView(view_handle), camera: Camera {
target: RenderTarget::TextureView(view_handle),
..Default::default()
},
view: XrCamera(index),
..Default::default() ..Default::default()
}, },
view: XrCamera(index), // OpenXrTracker,
..Default::default() // XrRoot::default(),
}, ))
// OpenXrTracker, .id();
// XrRoot::default(), match root.get_single() {
)); Ok(root) => {
commands.entity(root).add_child(cam);
}
Err(QuerySingleError::NoEntities(_)) => {
warn!("No OxrTrackingRoot!");
}
Err(QuerySingleError::MultipleEntities(_)) => {
warn!("Multiple OxrTrackingRoots! this is not allowed");
}
}
views.push(default()); views.push(default());
} }
commands.insert_resource(OxrViews(views)); commands.insert_resource(OxrViews(views));