add option to auto spawn cameras

This commit is contained in:
awtterpip
2025-01-28 12:08:46 -06:00
parent 5f79f083bf
commit 0b61473f38
2 changed files with 28 additions and 11 deletions

View File

@@ -64,7 +64,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
.add_before::<RenderPlugin>(OxrInitPlugin::default()) .add_before::<RenderPlugin>(OxrInitPlugin::default())
.add(OxrEventsPlugin) .add(OxrEventsPlugin)
.add(OxrReferenceSpacePlugin::default()) .add(OxrReferenceSpacePlugin::default())
.add(OxrRenderPlugin) .add(OxrRenderPlugin::default())
.add(OxrPassthroughPlugin) .add(OxrPassthroughPlugin)
.add(HandTrackingPlugin::default()) .add(HandTrackingPlugin::default())
.add(XrCameraPlugin) .add(XrCameraPlugin)

View File

@@ -25,7 +25,17 @@ pub struct OxrRenderBegin;
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)] #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)]
pub struct OxrRenderEnd; 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 { impl Plugin for OxrRenderPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
@@ -45,7 +55,12 @@ impl Plugin for OxrRenderPlugin {
( (
wait_frame.run_if(should_run_frame_loop), wait_frame.run_if(should_run_frame_loop),
update_cameras.run_if(should_run_frame_loop), update_cameras.run_if(should_run_frame_loop),
init_views.run_if(resource_added::<OxrSession>), if self.spawn_cameras {
init_views::<true>
} else {
init_views::<false>
}
.run_if(resource_added::<OxrSession>),
) )
.chain() .chain()
.in_set(XrHandleEvents::FrameLoop), .in_set(XrHandleEvents::FrameLoop),
@@ -129,7 +144,7 @@ pub fn clean_views(
} }
} }
pub fn init_views( pub fn init_views<const SPAWN_CAMERAS: bool>(
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>,
@@ -142,13 +157,15 @@ pub fn init_views(
info!("XrCamera resolution: {}", graphics_info.resolution); info!("XrCamera resolution: {}", 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(( if SPAWN_CAMERAS {
Camera { commands.spawn((
target: RenderTarget::TextureView(view_handle), Camera {
..Default::default() target: RenderTarget::TextureView(view_handle),
}, ..Default::default()
XrCamera(index), },
)); XrCamera(index),
));
}
} }
} }