Skip to content

Commit

Permalink
Merge branch 'main' into color-animatable
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn-lumen authored Mar 21, 2024
2 parents 6b7a656 + 7b842e3 commit 0a052c2
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 77 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_color/src/oklaba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize, Default)]
pub struct Oklaba {
/// The 'l' channel. [0.0, 1.0]
/// The 'lightness' channel. [0.0, 1.0]
pub lightness: f32,
/// The 'a' channel. [-1.0, 1.0]
pub a: f32,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Oklaba {
}
}

/// Return a copy of this color with the 'l' channel set to the given value.
/// Return a copy of this color with the 'lightness' channel set to the given value.
pub const fn with_lightness(self, lightness: f32) -> Self {
Self { lightness, ..self }
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_color/src/oklcha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ impl Oklcha {
}

/// Return a copy of this color with the 'lightness' channel set to the given value.
pub const fn with_l(self, lightness: f32) -> Self {
pub const fn with_lightness(self, lightness: f32) -> Self {
Self { lightness, ..self }
}

/// Return a copy of this color with the 'chroma' channel set to the given value.
pub const fn with_c(self, chroma: f32) -> Self {
pub const fn with_chroma(self, chroma: f32) -> Self {
Self { chroma, ..self }
}

/// Return a copy of this color with the 'hue' channel set to the given value.
pub const fn with_h(self, hue: f32) -> Self {
pub const fn with_hue(self, hue: f32) -> Self {
Self { hue, ..self }
}

Expand Down
39 changes: 31 additions & 8 deletions crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ use bevy_ecs::{
schedule::{common_conditions::resource_changed, IntoSystemConfigs},
system::{Commands, Query, Res, Resource},
};
use bevy_hierarchy::BuildChildren;
use bevy_text::{Font, Text, TextSection, TextStyle};
use bevy_ui::node_bundles::TextBundle;
use bevy_ui::{
node_bundles::{NodeBundle, TextBundle},
PositionType, Style, ZIndex,
};
use bevy_utils::default;

/// Global [`ZIndex`] used to render the fps overlay.
///
/// We use a number slightly under `i32::MAX` so you can render on top of it if you really need to.
pub const FPS_OVERLAY_ZINDEX: i32 = i32::MAX - 32;

/// A plugin that adds an FPS overlay to the Bevy application.
///
Expand Down Expand Up @@ -67,13 +77,26 @@ impl Default for FpsOverlayConfig {
struct FpsText;

fn setup(mut commands: Commands, overlay_config: Res<FpsOverlayConfig>) {
commands.spawn((
TextBundle::from_sections([
TextSection::new("FPS: ", overlay_config.text_config.clone()),
TextSection::from_style(overlay_config.text_config.clone()),
]),
FpsText,
));
commands
.spawn(NodeBundle {
style: Style {
// We need to make sure the overlay doesn't affect the position of other UI nodes
position_type: PositionType::Absolute,
..default()
},
// Render overlay on top of everything
z_index: ZIndex::Global(FPS_OVERLAY_ZINDEX),
..default()
})
.with_children(|c| {
c.spawn((
TextBundle::from_sections([
TextSection::new("FPS: ", overlay_config.text_config.clone()),
TextSection::from_style(overlay_config.text_config.clone()),
]),
FpsText,
));
});
}

fn update_text(diagnostic: Res<DiagnosticsStore>, mut query: Query<&mut Text, With<FpsText>>) {
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_math/src/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ impl TryFrom<Vec2> for Dir2 {
}
}

impl From<Dir2> for Vec2 {
fn from(value: Dir2) -> Self {
value.as_vec2()
}
}

impl std::ops::Deref for Dir2 {
type Target = Vec2;
fn deref(&self) -> &Self::Target {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub struct ComputedCameraValues {
///
/// <https://en.wikipedia.org/wiki/Exposure_(photography)>
#[derive(Component, Clone, Copy, Reflect)]
#[reflect_value(Component)]
#[reflect_value(Component, Default)]
pub struct Exposure {
/// <https://en.wikipedia.org/wiki/Exposure_value#Tabulated_exposure_values>
pub ev100: f32,
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Default for PhysicalCameraParameters {
/// Adding a camera is typically done by adding a bundle, either the `Camera2dBundle` or the
/// `Camera3dBundle`.
#[derive(Component, Debug, Reflect, Clone)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct Camera {
/// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
pub viewport: Option<Viewport>,
Expand Down Expand Up @@ -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
#[derive(Component, ExtractComponent, Clone, Copy, Reflect)]
#[reflect_value(Component)]
#[reflect_value(Component, Default)]
pub struct CameraMainTextureUsages(pub TextureUsages);
impl Default for CameraMainTextureUsages {
fn default() -> Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/camera/clear_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::extract_resource::ExtractResource;
use bevy_color::Color;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// For a camera, specifies the color used to clear the viewport before rendering.
#[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)]
#[reflect(Serialize, Deserialize)]
#[reflect(Serialize, Deserialize, Default)]
pub enum ClearColorConfig {
/// The clear color is taken from the world's [`ClearColor`] resource.
#[default]
Expand All @@ -31,7 +31,7 @@ impl From<Color> for ClearColorConfig {
/// This color appears as the "background" color for simple apps,
/// when there are portions of the screen with nothing rendered.
#[derive(Resource, Clone, Debug, Deref, DerefMut, ExtractResource, Reflect)]
#[reflect(Resource)]
#[reflect(Resource, Default)]
pub struct ClearColor(pub Color);

/// Match the dark gray bevy website code block color by default.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Handle};
use bevy_core::FrameCount;
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
use bevy_reflect::prelude::*;
use bevy_time::Time;

pub const GLOBALS_TYPE_HANDLE: Handle<Shader> = Handle::weak_from_u128(17924628719070609599);
Expand Down Expand Up @@ -45,7 +45,7 @@ fn extract_time(mut commands: Commands, time: Extract<Res<Time>>) {
/// Contains global values useful when writing shaders.
/// Currently only contains values related to time.
#[derive(Default, Clone, Resource, ExtractResource, Reflect, ShaderType)]
#[reflect(Resource)]
#[reflect(Resource, Default)]
pub struct GlobalsUniform {
/// The time since startup in seconds.
/// Wraps to 0 after 1 hour.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/mesh/mesh/skinning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use bevy_ecs::{
reflect::ReflectMapEntities,
};
use bevy_math::Mat4;
use bevy_reflect::{Reflect, TypePath};
use bevy_reflect::prelude::*;
use std::ops::Deref;

#[derive(Component, Debug, Default, Clone, Reflect)]
#[reflect(Component, MapEntities)]
#[reflect(Component, MapEntities, Default)]
pub struct SkinnedMesh {
pub inverse_bindposes: Handle<SkinnedMeshInverseBindposes>,
pub joints: Vec<Entity>,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/mesh/morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy_asset::Handle;
use bevy_ecs::prelude::*;
use bevy_hierarchy::Children;
use bevy_math::Vec3;
use bevy_reflect::Reflect;
use bevy_reflect::prelude::*;
use bytemuck::{Pod, Zeroable};
use std::{iter, mem};
use thiserror::Error;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl MorphTargetImage {
///
/// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation
#[derive(Reflect, Default, Debug, Clone, Component)]
#[reflect(Debug, Component)]
#[reflect(Debug, Component, Default)]
pub struct MorphWeights {
weights: Vec<f32>,
/// The first mesh primitive assigned to these weights
Expand Down Expand Up @@ -173,7 +173,7 @@ impl MorphWeights {
///
/// [morph targets]: https://en.wikipedia.org/wiki/Morph_target_animation
#[derive(Reflect, Default, Debug, Clone, Component)]
#[reflect(Debug, Component)]
#[reflect(Debug, Component, Default)]
pub struct MeshMorphWeights {
weights: Vec<f32>,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_render/src/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Borrow;

use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
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:
/// - a center,
Expand Down Expand Up @@ -31,7 +31,7 @@ use bevy_reflect::Reflect;
/// [`Mesh`]: crate::mesh::Mesh
/// [`Handle<Mesh>`]: crate::mesh::Mesh
#[derive(Component, Clone, Copy, Debug, Default, Reflect, PartialEq)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct Aabb {
pub center: Vec3A,
pub half_extents: Vec3A,
Expand Down Expand Up @@ -212,7 +212,7 @@ impl HalfSpace {
/// [`CameraProjection`]: crate::camera::CameraProjection
/// [`GlobalTransform`]: bevy_transform::components::GlobalTransform
#[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct Frustum {
#[reflect(ignore)]
pub half_spaces: [HalfSpace; 6],
Expand Down Expand Up @@ -303,7 +303,7 @@ impl Frustum {
}

#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct CubemapFrusta {
#[reflect(ignore)]
pub frusta: [Frustum; 6],
Expand All @@ -319,7 +319,7 @@ impl CubemapFrusta {
}

#[derive(Component, Debug, Default, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct CascadesFrusta {
#[reflect(ignore)]
pub frusta: EntityHashMap<Vec<Frustum>>,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy_asset::Asset;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::system::{lifetimeless::SRes, Resource, SystemParamItem};
use bevy_math::{AspectRatio, UVec2, Vec2};
use bevy_reflect::Reflect;
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};
use std::hash::Hash;
use thiserror::Error;
Expand Down Expand Up @@ -112,7 +112,7 @@ impl ImageFormat {
}

#[derive(Asset, Reflect, Debug, Clone)]
#[reflect_value]
#[reflect_value(Default)]
pub struct Image {
pub data: Vec<u8>,
// TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Plugin for ViewPlugin {
#[derive(
Resource, Default, Clone, Copy, ExtractResource, Reflect, PartialEq, PartialOrd, Debug,
)]
#[reflect(Resource)]
#[reflect(Resource, Default)]
pub enum Msaa {
Off = 1,
Sample2 = 2,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct NoFrustumCulling;
/// This component is intended to be attached to the same entity as the [`Camera`] and
/// the [`Frustum`] defining the view.
#[derive(Clone, Component, Default, Debug, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default)]
pub struct VisibleEntities {
#[reflect(ignore)]
pub entities: Vec<Entity>,
Expand Down
Loading

0 comments on commit 0a052c2

Please sign in to comment.