remove XrCameraBundle, use required components and component hooks instead
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -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::<Projection>();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user