From fe777d5c3fba64bec250b8ced3a6ba98fbd07a64 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Thu, 15 Feb 2024 15:56:37 -0800 Subject: [PATCH] Implement and register Reflect (value) for CameraRenderGraph and CameraMainTextureUsages (#11878) # Objective The new render graph labels do not (and cannot) implement normal Reflect, which breaks spawning scenes with cameras (including GLTF scenes). Likewise, the new `CameraMainTextureUsages` also does not (and cannot) implement normal Reflect because it uses `wgpu::TextureUsages` under the hood. Fixes #11852 ## Solution This implements minimal "reflect value" for `CameraRenderGraph` and `CameraMainTextureUsages` and registers the types, which satisfies our spawn logic. Note that this _does not_ fix scene serialization for these types, which will require more significant changes. We will especially need to think about how (and if) "interned labels" will fit into the scene system. For the purposes of 0.13, I think this is the best we can do. Given that this serialization issue is prevalent throughout Bevy atm, I'm ok with adding a couple more to the pile. When we roll out the new scene system, we will be forced to solve these on a case-by-case basis. --- ## Changelog - Implement Reflect (value) for `CameraMainTextureUsages` and `CameraRenderGraph`, and register those types. --- crates/bevy_render/src/camera/camera.rs | 6 ++++-- crates/bevy_render/src/camera/mod.rs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index de68e0d925..50c1b05c11 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -498,7 +498,8 @@ impl Default for CameraOutputMode { } /// Configures the [`RenderGraph`](crate::render_graph::RenderGraph) name assigned to be run for a given [`Camera`] entity. -#[derive(Component, Deref, DerefMut)] +#[derive(Component, Deref, DerefMut, Reflect, Clone)] +#[reflect_value(Component)] pub struct CameraRenderGraph(InternedRenderSubGraph); impl CameraRenderGraph { @@ -773,7 +774,8 @@ pub fn camera_system( } /// This component lets you control the [`TextureUsages`] field of the main texture generated for the camera -#[derive(Component, ExtractComponent, Clone, Copy)] +#[derive(Component, ExtractComponent, Clone, Copy, Reflect)] +#[reflect_value(Component)] pub struct CameraMainTextureUsages(pub TextureUsages); impl Default for CameraMainTextureUsages { fn default() -> Self { diff --git a/crates/bevy_render/src/camera/mod.rs b/crates/bevy_render/src/camera/mod.rs index 09961a28a7..52387a047b 100644 --- a/crates/bevy_render/src/camera/mod.rs +++ b/crates/bevy_render/src/camera/mod.rs @@ -30,6 +30,8 @@ impl Plugin for CameraPlugin { .register_type::() .register_type::() .register_type::() + .register_type::() + .register_type::() .init_resource::() .init_resource::() .add_plugins((