Merge pull request #99 from Schmarni-Dev/root-cameras

Refactor - Parent the Cameras to the OxrTrackingRoot
This commit is contained in:
ForTehLose
2024-05-14 23:16:38 -04:00
committed by GitHub

View File

@@ -1,4 +1,5 @@
use bevy::{
ecs::query::QuerySingleError,
prelude::*,
render::{
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
@@ -14,7 +15,7 @@ use openxr::ViewStateFlags;
use crate::{reference_space::OxrPrimaryReferenceSpace, resources::*};
use crate::{
init::{session_started, OxrPreUpdateSet},
init::{session_started, OxrPreUpdateSet, OxrTrackingRoot},
layer_builder::ProjectionLayer,
};
@@ -74,18 +75,20 @@ pub fn init_views(
graphics_info: Res<OxrGraphicsInfo>,
mut manual_texture_views: ResMut<ManualTextureViews>,
swapchain_images: Res<OxrSwapchainImages>,
root: Query<Entity, With<OxrTrackingRoot>>,
mut commands: Commands,
) {
let _span = info_span!("xr_init_views");
let temp_tex = swapchain_images.first().unwrap();
// 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 {
info!("{}", graphics_info.resolution);
let view_handle =
add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index);
commands.spawn((
let cam = commands
.spawn((
XrCameraBundle {
camera: Camera {
target: RenderTarget::TextureView(view_handle),
@@ -96,7 +99,20 @@ pub fn init_views(
},
// OpenXrTracker,
// XrRoot::default(),
));
))
.id();
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());
}
commands.insert_resource(OxrViews(views));