From 0b61473f382127f2520e512d6ff9c36983efe867 Mon Sep 17 00:00:00 2001 From: awtterpip Date: Tue, 28 Jan 2025 12:08:46 -0600 Subject: [PATCH] add option to auto spawn cameras --- crates/bevy_openxr/src/openxr/mod.rs | 2 +- crates/bevy_openxr/src/openxr/render.rs | 37 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/bevy_openxr/src/openxr/mod.rs b/crates/bevy_openxr/src/openxr/mod.rs index 6e4cb7d..989f30d 100644 --- a/crates/bevy_openxr/src/openxr/mod.rs +++ b/crates/bevy_openxr/src/openxr/mod.rs @@ -64,7 +64,7 @@ pub fn add_xr_plugins(plugins: G) -> PluginGroupBuilder { .add_before::(OxrInitPlugin::default()) .add(OxrEventsPlugin) .add(OxrReferenceSpacePlugin::default()) - .add(OxrRenderPlugin) + .add(OxrRenderPlugin::default()) .add(OxrPassthroughPlugin) .add(HandTrackingPlugin::default()) .add(XrCameraPlugin) diff --git a/crates/bevy_openxr/src/openxr/render.rs b/crates/bevy_openxr/src/openxr/render.rs index 311c452..e2102c7 100644 --- a/crates/bevy_openxr/src/openxr/render.rs +++ b/crates/bevy_openxr/src/openxr/render.rs @@ -25,7 +25,17 @@ pub struct OxrRenderBegin; #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)] pub struct OxrRenderEnd; -pub struct OxrRenderPlugin; +pub struct OxrRenderPlugin { + pub spawn_cameras: bool, +} + +impl Default for OxrRenderPlugin { + fn default() -> Self { + Self { + spawn_cameras: true, + } + } +} impl Plugin for OxrRenderPlugin { fn build(&self, app: &mut App) { @@ -45,7 +55,12 @@ impl Plugin for OxrRenderPlugin { ( wait_frame.run_if(should_run_frame_loop), update_cameras.run_if(should_run_frame_loop), - init_views.run_if(resource_added::), + if self.spawn_cameras { + init_views:: + } else { + init_views:: + } + .run_if(resource_added::), ) .chain() .in_set(XrHandleEvents::FrameLoop), @@ -129,7 +144,7 @@ pub fn clean_views( } } -pub fn init_views( +pub fn init_views( graphics_info: Res, mut manual_texture_views: ResMut, swapchain_images: Res, @@ -142,13 +157,15 @@ pub fn init_views( info!("XrCamera resolution: {}", graphics_info.resolution); let view_handle = add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index); - commands.spawn(( - Camera { - target: RenderTarget::TextureView(view_handle), - ..Default::default() - }, - XrCamera(index), - )); + if SPAWN_CAMERAS { + commands.spawn(( + Camera { + target: RenderTarget::TextureView(view_handle), + ..Default::default() + }, + XrCamera(index), + )); + } } }