Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from LegacyColor to bevy_color::Color #12163

Merged
merged 58 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b684a2a
Initial port of bevy_gizmos
Feb 27, 2024
138e26c
Use impl Into<Color> args in gizmo builder methods
Feb 27, 2024
fa8ad85
Merge remote-tracking branch 'origin/main' into color-externals
Feb 28, 2024
21de265
Use new convenience method in aabb.rs
Feb 28, 2024
e00b6bd
Fix color constants in gizmo docs tests
Feb 28, 2024
c07ec86
Remove unused import
Feb 28, 2024
d0dedbd
Add Color::srgba_u8
Feb 28, 2024
9d1f0d5
Add `Alpha::set_alpha` method
Feb 28, 2024
3829efd
Port over fog
Feb 28, 2024
ba58dc9
Port over ClearColor
Feb 28, 2024
8bc6c4f
Add new deprecated Color convenience methods
Feb 28, 2024
8e8d237
Port wireframes
Feb 28, 2024
1df0713
Port sprites
Feb 28, 2024
1b46fd1
Port text
Feb 28, 2024
0cfe96f
Add Alpha::is_fully_transparent and is_fully_opaque
Feb 28, 2024
c6806fa
Port bevy_ui
Feb 28, 2024
2ae656c
Add Mul and Div for LinearRgba
Feb 28, 2024
0621f62
Port standard material
Feb 28, 2024
5d8212e
Port lights
Feb 28, 2024
fe75eac
Register color types
Feb 28, 2024
a6b8fb4
Fix some doc tests
Feb 28, 2024
00616e2
Port ColorMaterial and MaterialMesh2d
Feb 28, 2024
80cb407
Port UI outlines
Feb 28, 2024
b7598cd
Add RED/GREEN/BLUE color constants
Feb 28, 2024
edd6988
to_array -> to_f32_array
Feb 28, 2024
d88b2fa
Add LinearRgba::as_u32
Feb 28, 2024
58c2eab
Eliminate remaining uses of `LegacyColor`
Feb 28, 2024
c2f52b0
Remove LegacyColor
Feb 28, 2024
1fb2f55
Merge remote-tracking branch 'origin/main' into color-externals
Feb 28, 2024
a094530
Use to_f32_array for fog code
Feb 28, 2024
0dd2ba4
Use WHITE constant
alice-i-cecile Feb 28, 2024
6b50ac6
set_alpha for Oklcha
Feb 28, 2024
948c1ee
Fix fog typo
Feb 28, 2024
6d2848e
Port over newly added code
Feb 28, 2024
ca5f22f
Merge branch 'color-externals' of https://github.com/alice-i-cecile/b…
Feb 28, 2024
fd6616f
Undo Color::NONE -> Color::TRANSPARENT
Feb 28, 2024
6a03503
Clippy
Feb 29, 2024
66833d4
Merge remote-tracking branch 'origin/main' into color-externals
Feb 29, 2024
07500da
Add deprecated rgb_linear methods to ease migration
Feb 29, 2024
86614a9
Fix doc tests failing in CI
Feb 29, 2024
5e52c49
Clean up redundant import
Feb 29, 2024
3d7f8d2
Tidy up examples
rparrett Feb 29, 2024
76567a6
Merge pull request #164 from rparrett/color-externals-examples
alice-i-cecile Feb 29, 2024
2072eee
More CI failures
Feb 29, 2024
4f3115d
Merge branch 'color-externals' of https://github.com/alice-i-cecile/b…
Feb 29, 2024
d2a8e12
Fixup bad rebase
rparrett Feb 29, 2024
c06d915
Fix clippy
rparrett Feb 29, 2024
8181762
Use .into where possible
rparrett Feb 29, 2024
cf8c4c7
Use color mixing in example
alice-i-cecile Feb 29, 2024
075600b
Improve rgb_from_array
alice-i-cecile Feb 29, 2024
1503719
Merge pull request #165 from rparrett/color-externals-clippy
alice-i-cecile Feb 29, 2024
13584c7
Fix more doc tests
Feb 29, 2024
502f9d6
Merge branch 'main' into color-externals
alice-i-cecile Feb 29, 2024
246e65a
Typo in doc test
Feb 29, 2024
03fdefc
Use `LinearRgba` in more rendering doc tests
Feb 29, 2024
ced8cd4
Fix doc test
Feb 29, 2024
c7fd5e3
Remove Add and Sub from LinearRgba
Feb 29, 2024
d400acb
More doc tests
Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/bevy_gizmos/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate as bevy_gizmos;

use bevy_app::{Plugin, PostUpdate};
use bevy_color::{Color, Hsla};
use bevy_ecs::{
component::Component,
entity::Entity,
Expand All @@ -12,7 +13,7 @@ use bevy_ecs::{
system::{Query, Res},
};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{color::LegacyColor, primitives::Aabb};
use bevy_render::primitives::Aabb;
use bevy_transform::{
components::{GlobalTransform, Transform},
TransformSystem,
Expand Down Expand Up @@ -57,7 +58,7 @@ pub struct AabbGizmoConfigGroup {
/// A random color is chosen per box if `None`.
///
/// Defaults to `None`.
pub default_color: Option<LegacyColor>,
pub default_color: Option<Color>,
}

/// Add this [`Component`] to an entity to draw its [`Aabb`] component.
Expand All @@ -67,7 +68,7 @@ pub struct ShowAabbGizmo {
/// The color of the box.
///
/// The default color from the [`AabbGizmoConfigGroup`] config is used if `None`,
pub color: Option<LegacyColor>,
pub color: Option<Color>,
}

fn draw_aabbs(
Expand Down Expand Up @@ -96,7 +97,7 @@ fn draw_all_aabbs(
}
}

fn color_from_entity(entity: Entity) -> LegacyColor {
fn color_from_entity(entity: Entity) -> Color {
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
let index = entity.index();

// from https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
Expand All @@ -108,7 +109,7 @@ fn color_from_entity(entity: Entity) -> LegacyColor {
const RATIO_360: f32 = 360.0 / u32::MAX as f32;
let hue = index.wrapping_mul(FRAC_U32MAX_GOLDEN_RATIO) as f32 * RATIO_360;

LegacyColor::hsl(hue, 1., 0.5)
Color::hsl(hue, 1., 0.5)
}

fn aabb_transform(aabb: Aabb, transform: GlobalTransform) -> GlobalTransform {
Expand Down
36 changes: 20 additions & 16 deletions crates/bevy_gizmos/src/arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

use crate::circles::DEFAULT_CIRCLE_SEGMENTS;
use crate::prelude::{GizmoConfigGroup, Gizmos};
use bevy_color::Color;
use bevy_math::{Quat, Vec2, Vec3};
use bevy_render::color::LegacyColor;
use std::f32::consts::TAU;

// === 2D ===
Expand All @@ -29,13 +29,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use std::f32::consts::PI;
/// # use bevy_color::palettes::basic::{GREEN, RED};
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., LegacyColor::GREEN);
/// gizmos.arc_2d(Vec2::ZERO, 0., PI / 4., 1., GREEN);
///
/// // Arcs have 32 line-segments by default.
/// // You may want to increase this for larger arcs.
/// gizmos
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., LegacyColor::RED)
/// .arc_2d(Vec2::ZERO, 0., PI / 4., 5., RED)
/// .segments(64);
/// }
/// # bevy_ecs::system::assert_is_system(system);
Expand All @@ -47,15 +48,15 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
direction_angle: f32,
arc_angle: f32,
radius: f32,
color: LegacyColor,
color: impl Into<Color>,
) -> Arc2dBuilder<'_, 'w, 's, T> {
Arc2dBuilder {
gizmos: self,
position,
direction_angle,
arc_angle,
radius,
color,
color: color.into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to do some performance testing to confirm, but we probably need to go back over the various From implementations an annotate them with #[inline]. I'm not sure how good the Rust compiler is at inlining these tiny functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed. I want to do perf testing towards the end of this process.

segments: None,
}
}
Expand All @@ -68,7 +69,7 @@ pub struct Arc2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
direction_angle: f32,
arc_angle: f32,
radius: f32,
color: LegacyColor,
color: Color,
segments: Option<usize>,
}

Expand Down Expand Up @@ -142,6 +143,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use std::f32::consts::PI;
/// # use bevy_color::palettes::basic::ORANGE;
/// fn system(mut gizmos: Gizmos) {
/// // rotation rotates normal to point in the direction of `Vec3::NEG_ONE`
/// let rotation = Quat::from_rotation_arc(Vec3::Y, Vec3::NEG_ONE.normalize());
Expand All @@ -152,7 +154,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// 0.25,
/// Vec3::ONE,
/// rotation,
/// LegacyColor::ORANGE
/// ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -165,7 +167,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
radius: f32,
position: Vec3,
rotation: Quat,
color: LegacyColor,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, T> {
Arc3dBuilder {
gizmos: self,
Expand All @@ -174,7 +176,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
rotation,
angle,
radius,
color,
color: color.into(),
segments: None,
}
}
Expand All @@ -197,12 +199,13 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use bevy_color::palettes::basic::ORANGE;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.short_arc_3d_between(
/// Vec3::ONE,
/// Vec3::ONE + Vec3::NEG_ONE,
/// Vec3::ZERO,
/// LegacyColor::ORANGE
/// ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -221,7 +224,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: LegacyColor,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, T> {
self.arc_from_to(center, from, to, color, |x| x)
}
Expand All @@ -243,12 +246,13 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use bevy_color::palettes::basic::ORANGE;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.long_arc_3d_between(
/// Vec3::ONE,
/// Vec3::ONE + Vec3::NEG_ONE,
/// Vec3::ZERO,
/// LegacyColor::ORANGE
/// ORANGE
/// )
/// .segments(100);
/// }
Expand All @@ -267,7 +271,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: LegacyColor,
color: impl Into<Color>,
) -> Arc3dBuilder<'_, 'w, 's, T> {
self.arc_from_to(center, from, to, color, |angle| {
if angle > 0.0 {
Expand All @@ -286,7 +290,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
center: Vec3,
from: Vec3,
to: Vec3,
color: LegacyColor,
color: impl Into<Color>,
angle_fn: impl Fn(f32) -> f32,
) -> Arc3dBuilder<'_, 'w, 's, T> {
// `from` and `to` can be the same here since in either case nothing gets rendered and the
Expand All @@ -308,7 +312,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
rotation,
angle,
radius,
color,
color: color.into(),
segments: None,
}
}
Expand All @@ -331,7 +335,7 @@ pub struct Arc3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
rotation: Quat,
angle: f32,
radius: f32,
color: LegacyColor,
color: Color,
segments: Option<usize>,
}

Expand Down
19 changes: 11 additions & 8 deletions crates/bevy_gizmos/src/arrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
//! and assorted support items.

use crate::prelude::{GizmoConfigGroup, Gizmos};
use bevy_color::Color;
use bevy_math::{Quat, Vec2, Vec3};
use bevy_render::color::LegacyColor;

/// A builder returned by [`Gizmos::arrow`] and [`Gizmos::arrow_2d`]
pub struct ArrowBuilder<'a, 'w, 's, T: GizmoConfigGroup> {
gizmos: &'a mut Gizmos<'w, 's, T>,
start: Vec3,
end: Vec3,
color: LegacyColor,
color: Color,
tip_length: f32,
}

Expand All @@ -25,8 +25,9 @@ impl<T: GizmoConfigGroup> ArrowBuilder<'_, '_, '_, T> {
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use bevy_color::palettes::basic::GREEN;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN)
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, GREEN)
/// .with_tip_length(3.);
/// }
/// # bevy_ecs::system::assert_is_system(system);
Expand Down Expand Up @@ -76,23 +77,24 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use bevy_color::palettes::basic::GREEN;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN);
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, GREEN);
/// }
/// # bevy_ecs::system::assert_is_system(system);
/// ```
pub fn arrow(
&mut self,
start: Vec3,
end: Vec3,
color: LegacyColor,
color: impl Into<Color>,
) -> ArrowBuilder<'_, 'w, 's, T> {
let length = (end - start).length();
ArrowBuilder {
gizmos: self,
start,
end,
color,
color: color.into(),
tip_length: length / 10.,
}
}
Expand All @@ -106,16 +108,17 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> {
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// # use bevy_color::palettes::basic::GREEN;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN);
/// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, GREEN);
/// }
/// # bevy_ecs::system::assert_is_system(system);
/// ```
pub fn arrow_2d(
&mut self,
start: Vec2,
end: Vec2,
color: LegacyColor,
color: impl Into<Color>,
) -> ArrowBuilder<'_, 'w, 's, T> {
self.arrow(start.extend(0.), end.extend(0.), color)
}
Expand Down
Loading
Loading