remove XrCameraBundle, use required components and component hooks instead
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ use bevy::{
|
|||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
use bevy_mod_xr::{
|
use bevy_mod_xr::{
|
||||||
camera::{XrCamera, XrCameraBundle, XrProjection},
|
camera::{XrCamera, XrProjection},
|
||||||
session::{
|
session::{
|
||||||
XrFirst, XrHandleEvents, XrPreDestroySession, XrRenderSet, XrRootTransform, XrTrackingRoot,
|
XrFirst, XrHandleEvents, XrPreDestroySession, XrRenderSet, XrRootTransform, XrTrackingRoot,
|
||||||
},
|
},
|
||||||
@@ -147,20 +147,17 @@ pub fn 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.
|
||||||
for index in 0..2 {
|
for index in 0..2 {
|
||||||
info!("{}", 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);
|
||||||
let cam = commands
|
let cam = commands
|
||||||
.spawn(
|
.spawn((
|
||||||
(XrCameraBundle {
|
Camera {
|
||||||
camera: Camera {
|
target: RenderTarget::TextureView(view_handle),
|
||||||
target: RenderTarget::TextureView(view_handle),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
view: XrCamera(index),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
},
|
||||||
)
|
XrCamera(index),
|
||||||
|
))
|
||||||
.remove::<Projection>()
|
.remove::<Projection>()
|
||||||
.id();
|
.id();
|
||||||
match root.get_single() {
|
match root.get_single() {
|
||||||
|
|||||||
@@ -3,25 +3,19 @@ use core::panic;
|
|||||||
use bevy::app::{App, Plugin, PostUpdate};
|
use bevy::app::{App, Plugin, PostUpdate};
|
||||||
use bevy::core_pipeline::core_3d::graph::Core3d;
|
use bevy::core_pipeline::core_3d::graph::Core3d;
|
||||||
use bevy::core_pipeline::core_3d::Camera3d;
|
use bevy::core_pipeline::core_3d::Camera3d;
|
||||||
use bevy::core_pipeline::tonemapping::{DebandDither, Tonemapping};
|
use bevy::ecs::component::{Component, StorageType};
|
||||||
use bevy::ecs::bundle::Bundle;
|
|
||||||
use bevy::ecs::component::Component;
|
|
||||||
use bevy::ecs::reflect::ReflectComponent;
|
use bevy::ecs::reflect::ReflectComponent;
|
||||||
use bevy::ecs::schedule::IntoSystemConfigs;
|
use bevy::ecs::schedule::IntoSystemConfigs;
|
||||||
use bevy::math::{Mat4, Vec3A};
|
use bevy::math::{Mat4, Vec3A};
|
||||||
use bevy::pbr::{
|
use bevy::pbr::{
|
||||||
build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems,
|
build_directional_light_cascades, clear_directional_light_cascades, SimulationLightSystems,
|
||||||
};
|
};
|
||||||
|
use bevy::prelude::Projection;
|
||||||
use bevy::reflect::std_traits::ReflectDefault;
|
use bevy::reflect::std_traits::ReflectDefault;
|
||||||
use bevy::reflect::Reflect;
|
use bevy::reflect::Reflect;
|
||||||
use bevy::render::camera::{
|
use bevy::render::camera::{CameraProjection, CameraProjectionPlugin};
|
||||||
Camera, CameraMainTextureUsages, CameraProjection, CameraProjectionPlugin, CameraRenderGraph,
|
|
||||||
Exposure,
|
|
||||||
};
|
|
||||||
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
|
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
|
||||||
use bevy::render::primitives::Frustum;
|
use bevy::render::view::{update_frusta, VisibilitySystems};
|
||||||
use bevy::render::view::{update_frusta, ColorGrading, VisibilitySystems, VisibleEntities};
|
|
||||||
use bevy::transform::components::{GlobalTransform, Transform};
|
|
||||||
use bevy::transform::TransformSystem;
|
use bevy::transform::TransformSystem;
|
||||||
|
|
||||||
pub struct XrCameraPlugin;
|
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)]
|
#[reflect(Component, Default)]
|
||||||
pub struct XrProjection {
|
pub struct XrProjection {
|
||||||
pub projection_matrix: Mat4,
|
pub projection_matrix: Mat4,
|
||||||
pub near: f32,
|
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::<Projection>();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for XrProjection {
|
impl Default for XrProjection {
|
||||||
fn default() -> Self {
|
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.
|
/// Marker component for an XR view. It is the backends responsibility to update this.
|
||||||
#[derive(Clone, Copy, Component, ExtractComponent, Debug, Default)]
|
#[derive(Clone, Copy, Component, ExtractComponent, Debug, Default)]
|
||||||
|
#[require(Camera3d, XrProjection)]
|
||||||
pub struct XrCamera(pub u32);
|
pub struct XrCamera(pub u32);
|
||||||
|
|
||||||
impl CameraProjection for XrProjection {
|
impl CameraProjection for XrProjection {
|
||||||
@@ -106,42 +110,3 @@ impl CameraProjection for XrProjection {
|
|||||||
panic!("sub view not supported for xr camera");
|
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user