diff --git a/crates/bevy_openxr/src/openxr/render.rs b/crates/bevy_openxr/src/openxr/render.rs index 0d5441d..b226724 100644 --- a/crates/bevy_openxr/src/openxr/render.rs +++ b/crates/bevy_openxr/src/openxr/render.rs @@ -11,7 +11,7 @@ use bevy::{ transform::TransformSystem, }; use bevy_mod_xr::{ - camera::{XrCamera, XrCameraBundle, XrProjection}, + camera::{XrCamera, XrProjection}, session::{ XrFirst, XrHandleEvents, XrPreDestroySession, XrRenderSet, XrRootTransform, XrTrackingRoot, }, @@ -147,20 +147,17 @@ pub fn 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. for index in 0..2 { - info!("{}", graphics_info.resolution); + info!("XrCamera resolution: {}", graphics_info.resolution); let view_handle = add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index); let cam = commands - .spawn( - (XrCameraBundle { - camera: Camera { - target: RenderTarget::TextureView(view_handle), - ..Default::default() - }, - view: XrCamera(index), + .spawn(( + Camera { + target: RenderTarget::TextureView(view_handle), ..Default::default() - }), - ) + }, + XrCamera(index), + )) .remove::() .id(); match root.get_single() { diff --git a/crates/bevy_xr/src/camera.rs b/crates/bevy_xr/src/camera.rs index f616634..562faf0 100644 --- a/crates/bevy_xr/src/camera.rs +++ b/crates/bevy_xr/src/camera.rs @@ -3,25 +3,19 @@ use core::panic; use bevy::app::{App, Plugin, PostUpdate}; use bevy::core_pipeline::core_3d::graph::Core3d; use bevy::core_pipeline::core_3d::Camera3d; -use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping}; -use bevy::ecs::bundle::Bundle; -use bevy::ecs::component::Component; +use bevy::ecs::component::{Component, StorageType}; use bevy::ecs::reflect::ReflectComponent; use bevy::ecs::schedule::IntoSystemConfigs; use bevy::math::{Mat4, Vec3A}; use bevy::pbr::{ build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems, }; +use bevy::prelude::Projection; use bevy::reflect::std_traits::ReflectDefault; use bevy::reflect::Reflect; -use bevy::render::camera::{ - Camera, CameraMainTextureUsages, CameraProjection, CameraProjectionPlugin, CameraRenderGraph, - Exposure, -}; +use bevy::render::camera::{CameraProjection, CameraProjectionPlugin}; use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin}; -use bevy::render::primitives::Frustum; -use bevy::render::view::{update_frusta, ColorGrading, VisibilitySystems, VisibleEntities}; -use bevy::transform::components::{GlobalTransform, Transform}; +use bevy::render::view::{update_frusta, VisibilitySystems}; use bevy::transform::TransformSystem; pub struct XrCameraPlugin; @@ -48,12 +42,21 @@ impl Plugin for XrCameraPlugin { } } -#[derive(Debug, Clone, Component, Reflect, ExtractComponent)] +#[derive(Debug, Clone, Reflect, ExtractComponent)] #[reflect(Component, Default)] pub struct XrProjection { pub projection_matrix: Mat4, pub near: f32, } +impl Component for XrProjection { + const STORAGE_TYPE: StorageType = StorageType::Table; + + fn register_component_hooks(hooks: &mut bevy::ecs::component::ComponentHooks) { + hooks.on_add(|mut world, entity, _| { + world.commands().entity(entity).remove::(); + }); + } +} impl Default for XrProjection { fn default() -> Self { @@ -66,6 +69,7 @@ impl Default for XrProjection { /// Marker component for an XR view. It is the backends responsibility to update this. #[derive(Clone, Copy, Component, ExtractComponent, Debug, Default)] +#[require(Camera3d, XrProjection)] pub struct XrCamera(pub u32); impl CameraProjection for XrProjection { @@ -106,42 +110,3 @@ impl CameraProjection for XrProjection { panic!("sub view not supported for xr camera"); } } - -#[derive(Bundle)] -pub struct XrCameraBundle { - pub camera: Camera, - pub camera_render_graph: CameraRenderGraph, - pub projection: XrProjection, - pub visible_entities: VisibleEntities, - pub frustum: Frustum, - pub transform: Transform, - pub global_transform: GlobalTransform, - pub camera_3d: Camera3d, - pub tonemapping: Tonemapping, - pub dither: DebandDither, - pub color_grading: ColorGrading, - pub exposure: Exposure, - pub main_texture_usages: CameraMainTextureUsages, - pub view: XrCamera, -} - -impl Default for XrCameraBundle { - fn default() -> Self { - Self { - camera_render_graph: CameraRenderGraph::new(Core3d), - camera: Default::default(), - projection: Default::default(), - visible_entities: Default::default(), - frustum: Default::default(), - transform: Default::default(), - global_transform: Default::default(), - camera_3d: Default::default(), - tonemapping: Default::default(), - color_grading: Default::default(), - exposure: Default::default(), - main_texture_usages: Default::default(), - dither: DebandDither::Enabled, - view: XrCamera(0), - } - } -}