Reflect default in some types on bevy_render (#12580)

# Objective

- Many types in bevy_render doesn't reflect Default even if it could.

## Solution

- Reflect it.

---

---------

Co-authored-by: Pablo Reinhardt <pabloreinhardt@gmail.com>
This commit is contained in:
Pablo Reinhardt 2024-03-19 19:50:17 -03:00 committed by GitHub
parent d7372f2c75
commit 40f82b867b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 22 additions and 22 deletions

View file

@ -88,7 +88,7 @@ pub struct ComputedCameraValues {
/// ///
/// <https://en.wikipedia.org/wiki/Exposure_(photography)> /// <https://en.wikipedia.org/wiki/Exposure_(photography)>
#[derive(Component, Clone, Copy, Reflect)] #[derive(Component, Clone, Copy, Reflect)]
#[reflect_value(Component)] #[reflect_value(Component, Default)]
pub struct Exposure { pub struct Exposure {
/// <https://en.wikipedia.org/wiki/Exposure_value#Tabulated_exposure_values> /// <https://en.wikipedia.org/wiki/Exposure_value#Tabulated_exposure_values>
pub ev100: f32, pub ev100: f32,
@ -184,7 +184,7 @@ impl Default for PhysicalCameraParameters {
/// Adding a camera is typically done by adding a bundle, either the `Camera2dBundle` or the /// Adding a camera is typically done by adding a bundle, either the `Camera2dBundle` or the
/// `Camera3dBundle`. /// `Camera3dBundle`.
#[derive(Component, Debug, Reflect, Clone)] #[derive(Component, Debug, Reflect, Clone)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct Camera { pub struct Camera {
/// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`]. /// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
pub viewport: Option<Viewport>, pub viewport: Option<Viewport>,
@ -771,7 +771,7 @@ pub fn camera_system<T: CameraProjection + Component>(
/// This component lets you control the [`TextureUsages`] field of the main texture generated for the camera /// This component lets you control the [`TextureUsages`] field of the main texture generated for the camera
#[derive(Component, ExtractComponent, Clone, Copy, Reflect)] #[derive(Component, ExtractComponent, Clone, Copy, Reflect)]
#[reflect_value(Component)] #[reflect_value(Component, Default)]
pub struct CameraMainTextureUsages(pub TextureUsages); pub struct CameraMainTextureUsages(pub TextureUsages);
impl Default for CameraMainTextureUsages { impl Default for CameraMainTextureUsages {
fn default() -> Self { fn default() -> Self {

View file

@ -2,12 +2,12 @@ use crate::extract_resource::ExtractResource;
use bevy_color::Color; use bevy_color::Color;
use bevy_derive::{Deref, DerefMut}; use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// For a camera, specifies the color used to clear the viewport before rendering. /// For a camera, specifies the color used to clear the viewport before rendering.
#[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)] #[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)]
#[reflect(Serialize, Deserialize)] #[reflect(Serialize, Deserialize, Default)]
pub enum ClearColorConfig { pub enum ClearColorConfig {
/// The clear color is taken from the world's [`ClearColor`] resource. /// The clear color is taken from the world's [`ClearColor`] resource.
#[default] #[default]
@ -31,7 +31,7 @@ impl From<Color> for ClearColorConfig {
/// This color appears as the "background" color for simple apps, /// This color appears as the "background" color for simple apps,
/// when there are portions of the screen with nothing rendered. /// when there are portions of the screen with nothing rendered.
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)] #[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)]
#[reflect(Resource)] #[reflect(Resource, Default)]
pub struct ClearColor(pub Color); pub struct ClearColor(pub Color);
/// Match the dark gray bevy website code block color by default. /// Match the dark gray bevy website code block color by default.

View file

@ -9,7 +9,7 @@ use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Handle}; use bevy_asset::{load_internal_asset, Handle};
use bevy_core::FrameCount; use bevy_core::FrameCount;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_reflect::Reflect; use bevy_reflect::prelude::*;
use bevy_time::Time; use bevy_time::Time;
pub const GLOBALS_TYPE_HANDLE: Handle<Shader> = Handle::weak_from_u128(17924628719070609599); pub const GLOBALS_TYPE_HANDLE: Handle<Shader> = Handle::weak_from_u128(17924628719070609599);
@ -45,7 +45,7 @@ fn extract_time(mut commands: Commands, time: Extract<Res<Time>>) {
/// Contains global values useful when writing shaders. /// Contains global values useful when writing shaders.
/// Currently only contains values related to time. /// Currently only contains values related to time.
#[derive(Default, Clone, Resource, ExtractResource, Reflect, ShaderType)] #[derive(Default, Clone, Resource, ExtractResource, Reflect, ShaderType)]
#[reflect(Resource)] #[reflect(Resource, Default)]
pub struct GlobalsUniform { pub struct GlobalsUniform {
/// The time since startup in seconds. /// The time since startup in seconds.
/// Wraps to 0 after 1 hour. /// Wraps to 0 after 1 hour.

View file

@ -6,11 +6,11 @@ use bevy_ecs::{
reflect::ReflectMapEntities, reflect::ReflectMapEntities,
}; };
use bevy_math::Mat4; use bevy_math::Mat4;
use bevy_reflect::{Reflect, TypePath}; use bevy_reflect::prelude::*;
use std::ops::Deref; use std::ops::Deref;
#[derive(Component, Debug, Default, Clone, Reflect)] #[derive(Component, Debug, Default, Clone, Reflect)]
#[reflect(Component, MapEntities)] #[reflect(Component, MapEntities, Default)]
pub struct SkinnedMesh { pub struct SkinnedMesh {
pub inverse_bindposes: Handle<SkinnedMeshInverseBindposes>, pub inverse_bindposes: Handle<SkinnedMeshInverseBindposes>,
pub joints: Vec<Entity>, pub joints: Vec<Entity>,

View file

@ -9,7 +9,7 @@ use bevy_asset::Handle;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_hierarchy::Children; use bevy_hierarchy::Children;
use bevy_math::Vec3; use bevy_math::Vec3;
use bevy_reflect::Reflect; use bevy_reflect::prelude::*;
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::{iter, mem}; use std::{iter, mem};
use thiserror::Error; use thiserror::Error;
@ -128,7 +128,7 @@ impl MorphTargetImage {
/// ///
/// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation /// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation
#[derive(Reflect, Default, Debug, Clone, Component)] #[derive(Reflect, Default, Debug, Clone, Component)]
#[reflect(Debug, Component)] #[reflect(Debug, Component, Default)]
pub struct MorphWeights { pub struct MorphWeights {
weights: Vec<f32>, weights: Vec<f32>,
/// The first mesh primitive assigned to these weights /// The first mesh primitive assigned to these weights
@ -173,7 +173,7 @@ impl MorphWeights {
/// ///
/// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation /// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation
#[derive(Reflect, Default, Debug, Clone, Component)] #[derive(Reflect, Default, Debug, Clone, Component)]
#[reflect(Debug, Component)] #[reflect(Debug, Component, Default)]
pub struct MeshMorphWeights { pub struct MeshMorphWeights {
weights: Vec<f32>, weights: Vec<f32>,
} }

View file

@ -2,7 +2,7 @@ use std::borrow::Borrow;
use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent}; use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
use bevy_math::{Affine3A, Mat3A, Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles}; use bevy_math::{Affine3A, Mat3A, Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles};
use bevy_reflect::Reflect; use bevy_reflect::prelude::*;
/// An axis-aligned bounding box, defined by: /// An axis-aligned bounding box, defined by:
/// - a center, /// - a center,
@ -31,7 +31,7 @@ use bevy_reflect::Reflect;
/// [`Mesh`]: crate::mesh::Mesh /// [`Mesh`]: crate::mesh::Mesh
/// [`Handle<Mesh>`]: crate::mesh::Mesh /// [`Handle<Mesh>`]: crate::mesh::Mesh
#[derive(Component, Clone, Copy, Debug, Default, Reflect, PartialEq)] #[derive(Component, Clone, Copy, Debug, Default, Reflect, PartialEq)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct Aabb { pub struct Aabb {
pub center: Vec3A, pub center: Vec3A,
pub half_extents: Vec3A, pub half_extents: Vec3A,
@ -212,7 +212,7 @@ impl HalfSpace {
/// [`CameraProjection`]: crate::camera::CameraProjection /// [`CameraProjection`]: crate::camera::CameraProjection
/// [`GlobalTransform`]: bevy_transform::components::GlobalTransform /// [`GlobalTransform`]: bevy_transform::components::GlobalTransform
#[derive(Component, Clone, Copy, Debug, Default, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct Frustum { pub struct Frustum {
#[reflect(ignore)] #[reflect(ignore)]
pub half_spaces: [HalfSpace; 6], pub half_spaces: [HalfSpace; 6],
@ -303,7 +303,7 @@ impl Frustum {
} }
#[derive(Component, Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct CubemapFrusta { pub struct CubemapFrusta {
#[reflect(ignore)] #[reflect(ignore)]
pub frusta: [Frustum; 6], pub frusta: [Frustum; 6],
@ -319,7 +319,7 @@ impl CubemapFrusta {
} }
#[derive(Component, Debug, Default, Reflect)] #[derive(Component, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct CascadesFrusta { pub struct CascadesFrusta {
#[reflect(ignore)] #[reflect(ignore)]
pub frusta: EntityHashMap<Vec<Frustum>>, pub frusta: EntityHashMap<Vec<Frustum>>,

View file

@ -15,7 +15,7 @@ use bevy_asset::Asset;
use bevy_derive::{Deref, DerefMut}; use bevy_derive::{Deref, DerefMut};
use bevy_ecs::system::{lifetimeless::SRes, Resource, SystemParamItem}; use bevy_ecs::system::{lifetimeless::SRes, Resource, SystemParamItem};
use bevy_math::{AspectRatio, UVec2, Vec2}; use bevy_math::{AspectRatio, UVec2, Vec2};
use bevy_reflect::Reflect; use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::hash::Hash; use std::hash::Hash;
use thiserror::Error; use thiserror::Error;
@ -112,7 +112,7 @@ impl ImageFormat {
} }
#[derive(Asset, Reflect, Debug, Clone)] #[derive(Asset, Reflect, Debug, Clone)]
#[reflect_value] #[reflect_value(Default)]
pub struct Image { pub struct Image {
pub data: Vec<u8>, pub data: Vec<u8>,
// TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors // TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors

View file

@ -90,7 +90,7 @@ impl Plugin for ViewPlugin {
#[derive( #[derive(
Resource, Default, Clone, Copy, ExtractResource, Reflect, PartialEq, PartialOrd, Debug, Resource, Default, Clone, Copy, ExtractResource, Reflect, PartialEq, PartialOrd, Debug,
)] )]
#[reflect(Resource)] #[reflect(Resource, Default)]
pub enum Msaa { pub enum Msaa {
Off = 1, Off = 1,
Sample2 = 2, Sample2 = 2,

View file

@ -168,7 +168,7 @@ pub struct NoFrustumCulling;
/// This component is intended to be attached to the same entity as the [`Camera`] and /// This component is intended to be attached to the same entity as the [`Camera`] and
/// the [`Frustum`] defining the view. /// the [`Frustum`] defining the view.
#[derive(Clone, Component, Default, Debug, Reflect)] #[derive(Clone, Component, Default, Debug, Reflect)]
#[reflect(Component)] #[reflect(Component, Default)]
pub struct VisibleEntities { pub struct VisibleEntities {
#[reflect(ignore)] #[reflect(ignore)]
pub entities: Vec<Entity>, pub entities: Vec<Entity>,