Reflect derived traits on all components and resources: bevy_pbr (#15224)

Solves https://github.com/bevyengine/bevy/issues/15187 for bevy_pbr
This commit is contained in:
Blazepaws 2024-09-15 18:07:30 +02:00 committed by GitHub
parent d878e2f8bd
commit b6b28a621f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 37 additions and 27 deletions

View file

@ -6,6 +6,7 @@ use bevy_asset::Handle;
use bevy_derive::{Deref, DerefMut}; use bevy_derive::{Deref, DerefMut};
use bevy_ecs::entity::{Entity, EntityHashMap}; use bevy_ecs::entity::{Entity, EntityHashMap};
use bevy_ecs::{bundle::Bundle, component::Component, reflect::ReflectComponent}; use bevy_ecs::{bundle::Bundle, component::Component, reflect::ReflectComponent};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_render::{ use bevy_render::{
mesh::Mesh, mesh::Mesh,
@ -50,14 +51,14 @@ impl<M: Material> Default for MaterialMeshBundle<M> {
/// This component contains all mesh entities visible from the current light view. /// This component contains all mesh entities visible from the current light view.
/// The collection is updated automatically by [`crate::SimulationLightSystems`]. /// The collection is updated automatically by [`crate::SimulationLightSystems`].
#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)] #[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
#[reflect(Component)] #[reflect(Component, Debug, Default)]
pub struct VisibleMeshEntities { pub struct VisibleMeshEntities {
#[reflect(ignore)] #[reflect(ignore)]
pub entities: Vec<Entity>, pub entities: Vec<Entity>,
} }
#[derive(Component, Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component, Debug, Default)]
pub struct CubemapVisibleEntities { pub struct CubemapVisibleEntities {
#[reflect(ignore)] #[reflect(ignore)]
data: [VisibleMeshEntities; 6], data: [VisibleMeshEntities; 6],

View file

@ -80,7 +80,7 @@ pub struct ClusterZConfig {
/// Configuration of the clustering strategy for clustered forward rendering /// Configuration of the clustering strategy for clustered forward rendering
#[derive(Debug, Copy, Clone, Component, Reflect)] #[derive(Debug, Copy, Clone, Component, Reflect)]
#[reflect(Component)] #[reflect(Component, Debug, Default)]
pub enum ClusterConfig { pub enum ClusterConfig {
/// Disable cluster calculations for this view /// Disable cluster calculations for this view
None, None,

View file

@ -50,7 +50,7 @@ use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
/// [`StandardMaterial`](crate::StandardMaterial) instances via the `fog_enabled` flag. /// [`StandardMaterial`](crate::StandardMaterial) instances via the `fog_enabled` flag.
#[derive(Debug, Clone, Component, Reflect, ExtractComponent)] #[derive(Debug, Clone, Component, Reflect, ExtractComponent)]
#[extract_component_filter(With<Camera>)] #[extract_component_filter(With<Camera>)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct DistanceFog { pub struct DistanceFog {
/// The color of the fog effect. /// The color of the fog effect.
/// ///

View file

@ -16,7 +16,7 @@ use super::*;
/// } /// }
/// ``` /// ```
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)] #[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
#[reflect(Resource)] #[reflect(Resource, Debug, Default)]
pub struct AmbientLight { pub struct AmbientLight {
pub color: Color, pub color: Color,
/// A direct scale factor multiplied with `color` before being passed to the shader. /// A direct scale factor multiplied with `color` before being passed to the shader.

View file

@ -48,7 +48,7 @@ use super::*;
/// .insert_resource(DirectionalLightShadowMap { size: 2048 }); /// .insert_resource(DirectionalLightShadowMap { size: 2048 });
/// ``` /// ```
#[derive(Component, Debug, Clone, Reflect)] #[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct DirectionalLight { pub struct DirectionalLight {
pub color: Color, pub color: Color,
/// Illuminance in lux (lumens per square meter), representing the amount of /// Illuminance in lux (lumens per square meter), representing the amount of

View file

@ -88,7 +88,7 @@ pub mod light_consts {
} }
#[derive(Resource, Clone, Debug, Reflect)] #[derive(Resource, Clone, Debug, Reflect)]
#[reflect(Resource)] #[reflect(Resource, Debug, Default)]
pub struct PointLightShadowMap { pub struct PointLightShadowMap {
pub size: usize, pub size: usize,
} }
@ -105,7 +105,7 @@ pub type WithLight = Or<(With<PointLight>, With<SpotLight>, With<DirectionalLigh
/// Controls the resolution of [`DirectionalLight`] shadow maps. /// Controls the resolution of [`DirectionalLight`] shadow maps.
#[derive(Resource, Clone, Debug, Reflect)] #[derive(Resource, Clone, Debug, Reflect)]
#[reflect(Resource)] #[reflect(Resource, Debug, Default)]
pub struct DirectionalLightShadowMap { pub struct DirectionalLightShadowMap {
pub size: usize, pub size: usize,
} }
@ -130,7 +130,7 @@ impl Default for DirectionalLightShadowMap {
/// }.into(); /// }.into();
/// ``` /// ```
#[derive(Component, Clone, Debug, Reflect)] #[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct CascadeShadowConfig { pub struct CascadeShadowConfig {
/// The (positive) distance to the far boundary of each cascade. /// The (positive) distance to the far boundary of each cascade.
pub bounds: Vec<f32>, pub bounds: Vec<f32>,
@ -271,7 +271,7 @@ impl From<CascadeShadowConfigBuilder> for CascadeShadowConfig {
} }
#[derive(Component, Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component, Debug, Default)]
pub struct Cascades { pub struct Cascades {
/// Map from a view to the configuration of each of its [`Cascade`]s. /// Map from a view to the configuration of each of its [`Cascade`]s.
pub(crate) cascades: EntityHashMap<Vec<Cascade>>, pub(crate) cascades: EntityHashMap<Vec<Cascade>>,
@ -439,7 +439,7 @@ fn calculate_cascade(
} }
/// Add this component to make a [`Mesh`] not cast shadows. /// Add this component to make a [`Mesh`] not cast shadows.
#[derive(Debug, Component, Reflect, Default)] #[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct NotShadowCaster; pub struct NotShadowCaster;
/// Add this component to make a [`Mesh`] not receive shadows. /// Add this component to make a [`Mesh`] not receive shadows.
/// ///
@ -447,7 +447,7 @@ pub struct NotShadowCaster;
/// cause both “regular” shadows as well as diffusely transmitted shadows to be disabled, /// cause both “regular” shadows as well as diffusely transmitted shadows to be disabled,
/// even when [`TransmittedShadowReceiver`] is being used. /// even when [`TransmittedShadowReceiver`] is being used.
#[derive(Debug, Component, Reflect, Default)] #[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct NotShadowReceiver; pub struct NotShadowReceiver;
/// Add this component to make a [`Mesh`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0` /// Add this component to make a [`Mesh`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0`
/// receive shadows on its diffuse transmission lobe. (i.e. its “backside”) /// receive shadows on its diffuse transmission lobe. (i.e. its “backside”)
@ -457,7 +457,7 @@ pub struct NotShadowReceiver;
/// ///
/// **Note:** Using [`NotShadowReceiver`] overrides this component. /// **Note:** Using [`NotShadowReceiver`] overrides this component.
#[derive(Debug, Component, Reflect, Default)] #[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct TransmittedShadowReceiver; pub struct TransmittedShadowReceiver;
/// Add this component to a [`Camera3d`](bevy_core_pipeline::core_3d::Camera3d) /// Add this component to a [`Camera3d`](bevy_core_pipeline::core_3d::Camera3d)
@ -466,7 +466,7 @@ pub struct TransmittedShadowReceiver;
/// The different modes use different approaches to /// The different modes use different approaches to
/// [Percentage Closer Filtering](https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-11-shadow-map-antialiasing). /// [Percentage Closer Filtering](https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-11-shadow-map-antialiasing).
#[derive(Debug, Component, ExtractComponent, Reflect, Clone, Copy, PartialEq, Eq, Default)] #[derive(Debug, Component, ExtractComponent, Reflect, Clone, Copy, PartialEq, Eq, Default)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug, PartialEq)]
pub enum ShadowFilteringMethod { pub enum ShadowFilteringMethod {
/// Hardware 2x2. /// Hardware 2x2.
/// ///

View file

@ -18,7 +18,7 @@ use super::*;
/// ///
/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting)
#[derive(Component, Debug, Clone, Copy, Reflect)] #[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct PointLight { pub struct PointLight {
/// The color of this light source. /// The color of this light source.
pub color: Color, pub color: Color,

View file

@ -5,7 +5,7 @@ use super::*;
/// shines light only in a given direction. The direction is taken from /// shines light only in a given direction. The direction is taken from
/// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at). /// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at).
#[derive(Component, Debug, Clone, Copy, Reflect)] #[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct SpotLight { pub struct SpotLight {
pub color: Color, pub color: Color,
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions. /// Luminous power in lumens, representing the amount of light emitted by this source in all directions.

View file

@ -48,9 +48,11 @@
use bevy_asset::{AssetId, Handle}; use bevy_asset::{AssetId, Handle};
use bevy_ecs::{ use bevy_ecs::{
bundle::Bundle, component::Component, query::QueryItem, system::lifetimeless::Read, bundle::Bundle, component::Component, query::QueryItem, reflect::ReflectComponent,
system::lifetimeless::Read,
}; };
use bevy_math::Quat; use bevy_math::Quat;
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_render::{ use bevy_render::{
extract_instances::ExtractInstance, extract_instances::ExtractInstance,
@ -84,6 +86,7 @@ pub const ENVIRONMENT_MAP_SHADER_HANDLE: Handle<Shader> =
/// ///
/// See [`crate::environment_map`] for detailed information. /// See [`crate::environment_map`] for detailed information.
#[derive(Clone, Component, Reflect)] #[derive(Clone, Component, Reflect)]
#[reflect(Component, Default)]
pub struct EnvironmentMapLight { pub struct EnvironmentMapLight {
/// The blurry image that represents diffuse radiance surrounding a region. /// The blurry image that represents diffuse radiance surrounding a region.
pub diffuse_map: Handle<Image>, pub diffuse_map: Handle<Image>,

View file

@ -132,7 +132,7 @@
//! //!
//! [Why ambient cubes?]: #why-ambient-cubes //! [Why ambient cubes?]: #why-ambient-cubes
use bevy_ecs::component::Component; use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_render::{ use bevy_render::{
render_asset::RenderAssets, render_asset::RenderAssets,
render_resource::{ render_resource::{
@ -145,6 +145,7 @@ use bevy_render::{
use std::{num::NonZero, ops::Deref}; use std::{num::NonZero, ops::Deref};
use bevy_asset::{AssetId, Handle}; use bevy_asset::{AssetId, Handle};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use crate::{ use crate::{
@ -166,6 +167,7 @@ pub(crate) const IRRADIANCE_VOLUMES_ARE_USABLE: bool = cfg!(not(target_arch = "w
/// ///
/// See [`crate::irradiance_volume`] for detailed information. /// See [`crate::irradiance_volume`] for detailed information.
#[derive(Clone, Default, Reflect, Component, Debug)] #[derive(Clone, Default, Reflect, Component, Debug)]
#[reflect(Component, Default, Debug)]
pub struct IrradianceVolume { pub struct IrradianceVolume {
/// The 3D texture that represents the ambient cubes, encoded in the format /// The 3D texture that represents the ambient cubes, encoded in the format
/// described in [`crate::irradiance_volume`]. /// described in [`crate::irradiance_volume`].

View file

@ -103,7 +103,7 @@ pub struct LightProbePlugin;
/// specific technique but rather to a class of techniques. Developers familiar /// specific technique but rather to a class of techniques. Developers familiar
/// with other engines should be aware of this terminology difference. /// with other engines should be aware of this terminology difference.
#[derive(Component, Debug, Clone, Copy, Default, Reflect)] #[derive(Component, Debug, Clone, Copy, Default, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct LightProbe; pub struct LightProbe;
/// A GPU type that stores information about a light probe. /// A GPU type that stores information about a light probe.

View file

@ -20,6 +20,7 @@ use bevy_ecs::{
prelude::*, prelude::*,
system::{lifetimeless::SRes, SystemParamItem}, system::{lifetimeless::SRes, SystemParamItem},
}; };
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_render::{ use bevy_render::{
camera::TemporalJitter, camera::TemporalJitter,
@ -825,6 +826,7 @@ pub fn queue_material_meshes<M: Material>(
/// Default render method used for opaque materials. /// Default render method used for opaque materials.
#[derive(Default, Resource, Clone, Debug, ExtractResource, Reflect)] #[derive(Default, Resource, Clone, Debug, ExtractResource, Reflect)]
#[reflect(Resource, Default, Debug)]
pub struct DefaultOpaqueRendererMethod(OpaqueRendererMethod); pub struct DefaultOpaqueRendererMethod(OpaqueRendererMethod);
impl DefaultOpaqueRendererMethod { impl DefaultOpaqueRendererMethod {

View file

@ -14,6 +14,7 @@ use bevy_ecs::{
system::{Commands, Query, Res, ResMut, Resource}, system::{Commands, Query, Res, ResMut, Resource},
world::{FromWorld, World}, world::{FromWorld, World},
}; };
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_render::{ use bevy_render::{
camera::{ExtractedCamera, TemporalJitter}, camera::{ExtractedCamera, TemporalJitter},
@ -154,7 +155,7 @@ pub struct ScreenSpaceAmbientOcclusionBundle {
/// ///
/// SSAO is not supported on `WebGL2`, and is not currently supported on `WebGPU` or `DirectX12`. /// SSAO is not supported on `WebGL2`, and is not currently supported on `WebGPU` or `DirectX12`.
#[derive(Component, ExtractComponent, Reflect, PartialEq, Eq, Hash, Clone, Default, Debug)] #[derive(Component, ExtractComponent, Reflect, PartialEq, Eq, Hash, Clone, Default, Debug)]
#[reflect(Component)] #[reflect(Component, Debug, Default, Hash, PartialEq)]
#[doc(alias = "Ssao")] #[doc(alias = "Ssao")]
pub struct ScreenSpaceAmbientOcclusion { pub struct ScreenSpaceAmbientOcclusion {
pub quality_level: ScreenSpaceAmbientOcclusionQualityLevel, pub quality_level: ScreenSpaceAmbientOcclusionQualityLevel,

View file

@ -44,6 +44,7 @@ use bevy_math::{
primitives::{Cuboid, Plane3d}, primitives::{Cuboid, Plane3d},
Vec2, Vec3, Vec2, Vec3,
}; };
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect; use bevy_reflect::Reflect;
use bevy_render::{ use bevy_render::{
mesh::{Mesh, Meshable}, mesh::{Mesh, Meshable},
@ -71,14 +72,14 @@ pub struct VolumetricFogPlugin;
/// ///
/// This allows the light to generate light shafts/god rays. /// This allows the light to generate light shafts/god rays.
#[derive(Clone, Copy, Component, Default, Debug, Reflect)] #[derive(Clone, Copy, Component, Default, Debug, Reflect)]
#[reflect(Component)] #[reflect(Component, Default, Debug)]
pub struct VolumetricLight; pub struct VolumetricLight;
/// When placed on a [`bevy_core_pipeline::core_3d::Camera3d`], enables /// When placed on a [`bevy_core_pipeline::core_3d::Camera3d`], enables
/// volumetric fog and volumetric lighting, also known as light shafts or god /// volumetric fog and volumetric lighting, also known as light shafts or god
/// rays. /// rays.
#[derive(Clone, Copy, Component, Debug, Reflect)] #[derive(Clone, Copy, Component, Debug, Reflect)]
#[reflect(Component)] #[reflect(Component, Default, Debug)]
pub struct VolumetricFog { pub struct VolumetricFog {
/// Color of the ambient light. /// Color of the ambient light.
/// ///
@ -138,7 +139,7 @@ pub struct FogVolumeBundle {
} }
#[derive(Clone, Component, Debug, Reflect)] #[derive(Clone, Component, Debug, Reflect)]
#[reflect(Component)] #[reflect(Component, Default, Debug)]
pub struct FogVolume { pub struct FogVolume {
/// The color of the fog. /// The color of the fog.
/// ///

View file

@ -56,7 +56,7 @@ impl Plugin for WireframePlugin {
/// ///
/// This requires the [`WireframePlugin`] to be enabled. /// This requires the [`WireframePlugin`] to be enabled.
#[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)] #[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug, PartialEq)]
pub struct Wireframe; pub struct Wireframe;
/// Sets the color of the [`Wireframe`] of the entity it is attached to. /// Sets the color of the [`Wireframe`] of the entity it is attached to.
@ -69,7 +69,7 @@ pub struct Wireframe;
// This could blow up in size if people use random colored wireframes for each mesh. // This could blow up in size if people use random colored wireframes for each mesh.
// It will also be important to remove unused materials from the cache. // It will also be important to remove unused materials from the cache.
#[derive(Component, Debug, Clone, Default, Reflect)] #[derive(Component, Debug, Clone, Default, Reflect)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug)]
pub struct WireframeColor { pub struct WireframeColor {
pub color: Color, pub color: Color,
} }
@ -79,11 +79,11 @@ pub struct WireframeColor {
/// ///
/// This requires the [`WireframePlugin`] to be enabled. /// This requires the [`WireframePlugin`] to be enabled.
#[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)] #[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)]
#[reflect(Component, Default)] #[reflect(Component, Default, Debug, PartialEq)]
pub struct NoWireframe; pub struct NoWireframe;
#[derive(Resource, Debug, Clone, Default, ExtractResource, Reflect)] #[derive(Resource, Debug, Clone, Default, ExtractResource, Reflect)]
#[reflect(Resource)] #[reflect(Resource, Debug, Default)]
pub struct WireframeConfig { pub struct WireframeConfig {
/// Whether to show wireframes for all meshes. /// Whether to show wireframes for all meshes.
/// Can be overridden for individual meshes by adding a [`Wireframe`] or [`NoWireframe`] component. /// Can be overridden for individual meshes by adding a [`Wireframe`] or [`NoWireframe`] component.