From b684a2adb9555739bceb884cfb83ff8c35e54d46 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 27 Feb 2024 13:24:16 -0500 Subject: [PATCH 01/50] Initial port of bevy_gizmos --- crates/bevy_gizmos/src/aabb.rs | 11 ++- crates/bevy_gizmos/src/arcs.rs | 26 +++--- crates/bevy_gizmos/src/arrows.rs | 19 ++-- crates/bevy_gizmos/src/circles.rs | 30 +++--- crates/bevy_gizmos/src/gizmos.rs | 98 +++++++++----------- crates/bevy_gizmos/src/lib.rs | 2 +- crates/bevy_gizmos/src/primitives/dim2.rs | 44 ++++----- crates/bevy_gizmos/src/primitives/dim3.rs | 44 ++++----- crates/bevy_gizmos/src/primitives/helpers.rs | 8 +- examples/2d/2d_viewport_to_world.rs | 4 +- examples/2d/bounding_2d.rs | 22 ++--- examples/3d/3d_viewport_to_world.rs | 3 +- examples/3d/irradiance_volumes.rs | 3 +- examples/animation/cubic_curve.rs | 3 +- examples/gizmos/2d_gizmos.rs | 32 +++---- examples/gizmos/3d_gizmos.rs | 24 ++--- examples/math/render_primitives.rs | 7 +- examples/stress_tests/many_gizmos.rs | 7 +- 18 files changed, 184 insertions(+), 203 deletions(-) diff --git a/crates/bevy_gizmos/src/aabb.rs b/crates/bevy_gizmos/src/aabb.rs index 65b726bea9994..ebbfb01b194f2 100644 --- a/crates/bevy_gizmos/src/aabb.rs +++ b/crates/bevy_gizmos/src/aabb.rs @@ -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, @@ -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, @@ -57,7 +58,7 @@ pub struct AabbGizmoConfigGroup { /// A random color is chosen per box if `None`. /// /// Defaults to `None`. - pub default_color: Option, + pub default_color: Option, } /// Add this [`Component`] to an entity to draw its [`Aabb`] component. @@ -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, + pub color: Option, } fn draw_aabbs( @@ -96,7 +97,7 @@ fn draw_all_aabbs( } } -fn color_from_entity(entity: Entity) -> LegacyColor { +fn color_from_entity(entity: Entity) -> Color { let index = entity.index(); // from https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ @@ -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) + Hsla::hsl(hue, 1., 0.5).into() } fn aabb_transform(aabb: Aabb, transform: GlobalTransform) -> GlobalTransform { diff --git a/crates/bevy_gizmos/src/arcs.rs b/crates/bevy_gizmos/src/arcs.rs index 09864b60057b4..246d88def4e42 100644 --- a/crates/bevy_gizmos/src/arcs.rs +++ b/crates/bevy_gizmos/src/arcs.rs @@ -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 === @@ -30,12 +30,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_math::prelude::*; /// # use std::f32::consts::PI; /// 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., Color::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., Color::RED) /// .segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -47,7 +47,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { direction_angle: f32, arc_angle: f32, radius: f32, - color: LegacyColor, + color: Color, ) -> Arc2dBuilder<'_, 'w, 's, T> { Arc2dBuilder { gizmos: self, @@ -68,7 +68,7 @@ pub struct Arc2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { direction_angle: f32, arc_angle: f32, radius: f32, - color: LegacyColor, + color: Color, segments: Option, } @@ -152,7 +152,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// 0.25, /// Vec3::ONE, /// rotation, - /// LegacyColor::ORANGE + /// Color::ORANGE /// ) /// .segments(100); /// } @@ -165,7 +165,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { radius: f32, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Arc3dBuilder<'_, 'w, 's, T> { Arc3dBuilder { gizmos: self, @@ -202,7 +202,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// Vec3::ONE, /// Vec3::ONE + Vec3::NEG_ONE, /// Vec3::ZERO, - /// LegacyColor::ORANGE + /// Color::ORANGE /// ) /// .segments(100); /// } @@ -221,7 +221,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { center: Vec3, from: Vec3, to: Vec3, - color: LegacyColor, + color: Color, ) -> Arc3dBuilder<'_, 'w, 's, T> { self.arc_from_to(center, from, to, color, |x| x) } @@ -248,7 +248,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// Vec3::ONE, /// Vec3::ONE + Vec3::NEG_ONE, /// Vec3::ZERO, - /// LegacyColor::ORANGE + /// Color::ORANGE /// ) /// .segments(100); /// } @@ -267,7 +267,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { center: Vec3, from: Vec3, to: Vec3, - color: LegacyColor, + color: Color, ) -> Arc3dBuilder<'_, 'w, 's, T> { self.arc_from_to(center, from, to, color, |angle| { if angle > 0.0 { @@ -286,7 +286,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { center: Vec3, from: Vec3, to: Vec3, - color: LegacyColor, + color: 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 @@ -331,7 +331,7 @@ pub struct Arc3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { rotation: Quat, angle: f32, radius: f32, - color: LegacyColor, + color: Color, segments: Option, } diff --git a/crates/bevy_gizmos/src/arrows.rs b/crates/bevy_gizmos/src/arrows.rs index 9dc81b77599c5..609d7e7843e97 100644 --- a/crates/bevy_gizmos/src/arrows.rs +++ b/crates/bevy_gizmos/src/arrows.rs @@ -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, } @@ -26,7 +26,7 @@ impl ArrowBuilder<'_, '_, '_, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN) + /// gizmos.arrow(Vec3::ZERO, Vec3::ONE, Color::GREEN) /// .with_tip_length(3.); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -77,16 +77,11 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.arrow(Vec3::ZERO, Vec3::ONE, LegacyColor::GREEN); + /// gizmos.arrow(Vec3::ZERO, Vec3::ONE, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` - pub fn arrow( - &mut self, - start: Vec3, - end: Vec3, - color: LegacyColor, - ) -> ArrowBuilder<'_, 'w, 's, T> { + pub fn arrow(&mut self, start: Vec3, end: Vec3, color: Color) -> ArrowBuilder<'_, 'w, 's, T> { let length = (end - start).length(); ArrowBuilder { gizmos: self, @@ -107,7 +102,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN); + /// gizmos.arrow_2d(Vec2::ZERO, Vec2::X, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` @@ -115,7 +110,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { &mut self, start: Vec2, end: Vec2, - color: LegacyColor, + color: Color, ) -> ArrowBuilder<'_, 'w, 's, T> { self.arrow(start.extend(0.), end.extend(0.), color) } diff --git a/crates/bevy_gizmos/src/circles.rs b/crates/bevy_gizmos/src/circles.rs index c1aedc24cf7fa..58477481c2218 100644 --- a/crates/bevy_gizmos/src/circles.rs +++ b/crates/bevy_gizmos/src/circles.rs @@ -4,9 +4,9 @@ //! and assorted support items. use crate::prelude::{GizmoConfigGroup, Gizmos}; +use bevy_color::Color; use bevy_math::Mat2; use bevy_math::{Direction3d, Quat, Vec2, Vec3}; -use bevy_render::color::LegacyColor; use std::f32::consts::TAU; pub(crate) const DEFAULT_CIRCLE_SEGMENTS: usize = 32; @@ -30,12 +30,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), LegacyColor::GREEN); + /// gizmos.ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(1., 2.), Color::GREEN); /// /// // Ellipses have 32 line-segments by default. /// // You may want to increase this for larger ellipses. /// gizmos - /// .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), LegacyColor::RED) + /// .ellipse(Vec3::ZERO, Quat::IDENTITY, Vec2::new(5., 1.), Color::RED) /// .segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -46,7 +46,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { position: Vec3, rotation: Quat, half_size: Vec2, - color: LegacyColor, + color: Color, ) -> EllipseBuilder<'_, 'w, 's, T> { EllipseBuilder { gizmos: self, @@ -68,12 +68,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), LegacyColor::GREEN); + /// gizmos.ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(2., 1.), Color::GREEN); /// /// // Ellipses have 32 line-segments by default. /// // You may want to increase this for larger ellipses. /// gizmos - /// .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), LegacyColor::RED) + /// .ellipse_2d(Vec2::ZERO, 180.0_f32.to_radians(), Vec2::new(5., 1.), Color::RED) /// .segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -84,7 +84,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { position: Vec2, angle: f32, half_size: Vec2, - color: LegacyColor, + color: Color, ) -> Ellipse2dBuilder<'_, 'w, 's, T> { Ellipse2dBuilder { gizmos: self, @@ -106,12 +106,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.circle(Vec3::ZERO, Direction3d::Z, 1., LegacyColor::GREEN); + /// gizmos.circle(Vec3::ZERO, Direction3d::Z, 1., Color::GREEN); /// /// // Circles have 32 line-segments by default. /// // You may want to increase this for larger circles. /// gizmos - /// .circle(Vec3::ZERO, Direction3d::Z, 5., LegacyColor::RED) + /// .circle(Vec3::ZERO, Direction3d::Z, 5., Color::RED) /// .segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -122,7 +122,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { position: Vec3, normal: Direction3d, radius: f32, - color: LegacyColor, + color: Color, ) -> EllipseBuilder<'_, 'w, 's, T> { EllipseBuilder { gizmos: self, @@ -144,12 +144,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.circle_2d(Vec2::ZERO, 1., LegacyColor::GREEN); + /// gizmos.circle_2d(Vec2::ZERO, 1., Color::GREEN); /// /// // Circles have 32 line-segments by default. /// // You may want to increase this for larger circles. /// gizmos - /// .circle_2d(Vec2::ZERO, 5., LegacyColor::RED) + /// .circle_2d(Vec2::ZERO, 5., Color::RED) /// .segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -159,7 +159,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { &mut self, position: Vec2, radius: f32, - color: LegacyColor, + color: Color, ) -> Ellipse2dBuilder<'_, 'w, 's, T> { Ellipse2dBuilder { gizmos: self, @@ -178,7 +178,7 @@ pub struct EllipseBuilder<'a, 'w, 's, T: GizmoConfigGroup> { position: Vec3, rotation: Quat, half_size: Vec2, - color: LegacyColor, + color: Color, segments: usize, } @@ -209,7 +209,7 @@ pub struct Ellipse2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { position: Vec2, rotation: Mat2, half_size: Vec2, - color: LegacyColor, + color: Color, segments: usize, } diff --git a/crates/bevy_gizmos/src/gizmos.rs b/crates/bevy_gizmos/src/gizmos.rs index adb18fff5cc4f..baff62c39ac64 100644 --- a/crates/bevy_gizmos/src/gizmos.rs +++ b/crates/bevy_gizmos/src/gizmos.rs @@ -3,14 +3,13 @@ use std::{iter, marker::PhantomData}; use crate::circles::DEFAULT_CIRCLE_SEGMENTS; -use bevy_color::LinearRgba; +use bevy_color::{Color, LinearRgba}; use bevy_ecs::{ component::Tick, system::{Deferred, ReadOnlySystemParam, Res, Resource, SystemBuffer, SystemMeta, SystemParam}, world::{unsafe_world_cell::UnsafeWorldCell, World}, }; use bevy_math::{Direction3d, Mat2, Quat, Vec2, Vec3}; -use bevy_render::color::LegacyColor; use bevy_transform::TransformPoint; use crate::{ @@ -131,12 +130,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.line(Vec3::ZERO, Vec3::X, LegacyColor::GREEN); + /// gizmos.line(Vec3::ZERO, Vec3::X, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn line(&mut self, start: Vec3, end: Vec3, color: LegacyColor) { + pub fn line(&mut self, start: Vec3, end: Vec3, color: Color) { if !self.enabled { return; } @@ -154,18 +153,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.line_gradient(Vec3::ZERO, Vec3::X, LegacyColor::GREEN, LegacyColor::RED); + /// gizmos.line_gradient(Vec3::ZERO, Vec3::X, Color::GREEN, Color::RED); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn line_gradient( - &mut self, - start: Vec3, - end: Vec3, - start_color: LegacyColor, - end_color: LegacyColor, - ) { + pub fn line_gradient(&mut self, start: Vec3, end: Vec3, start_color: Color, end_color: Color) { if !self.enabled { return; } @@ -183,12 +176,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.ray(Vec3::Y, Vec3::X, LegacyColor::GREEN); + /// gizmos.ray(Vec3::Y, Vec3::X, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn ray(&mut self, start: Vec3, vector: Vec3, color: LegacyColor) { + pub fn ray(&mut self, start: Vec3, vector: Vec3, color: Color) { if !self.enabled { return; } @@ -205,7 +198,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.ray_gradient(Vec3::Y, Vec3::X, LegacyColor::GREEN, LegacyColor::RED); + /// gizmos.ray_gradient(Vec3::Y, Vec3::X, Color::GREEN, Color::RED); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` @@ -214,8 +207,8 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { &mut self, start: Vec3, vector: Vec3, - start_color: LegacyColor, - end_color: LegacyColor, + start_color: Color, + end_color: Color, ) { if !self.enabled { return; @@ -233,12 +226,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.linestrip([Vec3::ZERO, Vec3::X, Vec3::Y], LegacyColor::GREEN); + /// gizmos.linestrip([Vec3::ZERO, Vec3::X, Vec3::Y], Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn linestrip(&mut self, positions: impl IntoIterator, color: LegacyColor) { + pub fn linestrip(&mut self, positions: impl IntoIterator, color: Color) { if !self.enabled { return; } @@ -259,15 +252,15 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { /// gizmos.linestrip_gradient([ - /// (Vec3::ZERO, LegacyColor::GREEN), - /// (Vec3::X, LegacyColor::RED), - /// (Vec3::Y, LegacyColor::BLUE) + /// (Vec3::ZERO, Color::GREEN), + /// (Vec3::X, Color::RED), + /// (Vec3::Y, Color::BLUE) /// ]); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn linestrip_gradient(&mut self, points: impl IntoIterator) { + pub fn linestrip_gradient(&mut self, points: impl IntoIterator) { if !self.enabled { return; } @@ -302,12 +295,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.sphere(Vec3::ZERO, Quat::IDENTITY, 1., LegacyColor::BLACK); + /// gizmos.sphere(Vec3::ZERO, Quat::IDENTITY, 1., Color::BLACK); /// /// // Each circle has 32 line-segments by default. /// // You may want to increase this for larger spheres. /// gizmos - /// .sphere(Vec3::ZERO, Quat::IDENTITY, 5., LegacyColor::BLACK) + /// .sphere(Vec3::ZERO, Quat::IDENTITY, 5., Color::BLACK) /// .circle_segments(64); /// } /// # bevy_ecs::system::assert_is_system(system); @@ -318,7 +311,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { position: Vec3, rotation: Quat, radius: f32, - color: LegacyColor, + color: Color, ) -> SphereBuilder<'_, 'w, 's, T> { SphereBuilder { gizmos: self, @@ -340,12 +333,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.rect(Vec3::ZERO, Quat::IDENTITY, Vec2::ONE, LegacyColor::GREEN); + /// gizmos.rect(Vec3::ZERO, Quat::IDENTITY, Vec2::ONE, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn rect(&mut self, position: Vec3, rotation: Quat, size: Vec2, color: LegacyColor) { + pub fn rect(&mut self, position: Vec3, rotation: Quat, size: Vec2, color: Color) { if !self.enabled { return; } @@ -363,12 +356,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_transform::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.cuboid(Transform::IDENTITY, LegacyColor::GREEN); + /// gizmos.cuboid(Transform::IDENTITY, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn cuboid(&mut self, transform: impl TransformPoint, color: LegacyColor) { + pub fn cuboid(&mut self, transform: impl TransformPoint, color: Color) { if !self.enabled { return; } @@ -401,12 +394,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.line_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN); + /// gizmos.line_2d(Vec2::ZERO, Vec2::X, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn line_2d(&mut self, start: Vec2, end: Vec2, color: LegacyColor) { + pub fn line_2d(&mut self, start: Vec2, end: Vec2, color: Color) { if !self.enabled { return; } @@ -423,7 +416,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.line_gradient_2d(Vec2::ZERO, Vec2::X, LegacyColor::GREEN, LegacyColor::RED); + /// gizmos.line_gradient_2d(Vec2::ZERO, Vec2::X, Color::GREEN, Color::RED); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` @@ -432,8 +425,8 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { &mut self, start: Vec2, end: Vec2, - start_color: LegacyColor, - end_color: LegacyColor, + start_color: Color, + end_color: Color, ) { if !self.enabled { return; @@ -451,12 +444,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.linestrip_2d([Vec2::ZERO, Vec2::X, Vec2::Y], LegacyColor::GREEN); + /// gizmos.linestrip_2d([Vec2::ZERO, Vec2::X, Vec2::Y], Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn linestrip_2d(&mut self, positions: impl IntoIterator, color: LegacyColor) { + pub fn linestrip_2d(&mut self, positions: impl IntoIterator, color: Color) { if !self.enabled { return; } @@ -474,18 +467,15 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { /// gizmos.linestrip_gradient_2d([ - /// (Vec2::ZERO, LegacyColor::GREEN), - /// (Vec2::X, LegacyColor::RED), - /// (Vec2::Y, LegacyColor::BLUE) + /// (Vec2::ZERO, Color::GREEN), + /// (Vec2::X, Color::RED), + /// (Vec2::Y, Color::BLUE) /// ]); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn linestrip_gradient_2d( - &mut self, - positions: impl IntoIterator, - ) { + pub fn linestrip_gradient_2d(&mut self, positions: impl IntoIterator) { if !self.enabled { return; } @@ -506,12 +496,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.ray_2d(Vec2::Y, Vec2::X, LegacyColor::GREEN); + /// gizmos.ray_2d(Vec2::Y, Vec2::X, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn ray_2d(&mut self, start: Vec2, vector: Vec2, color: LegacyColor) { + pub fn ray_2d(&mut self, start: Vec2, vector: Vec2, color: Color) { if !self.enabled { return; } @@ -528,7 +518,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.line_gradient(Vec3::Y, Vec3::X, LegacyColor::GREEN, LegacyColor::RED); + /// gizmos.line_gradient(Vec3::Y, Vec3::X, Color::GREEN, Color::RED); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` @@ -537,8 +527,8 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { &mut self, start: Vec2, vector: Vec2, - start_color: LegacyColor, - end_color: LegacyColor, + start_color: Color, + end_color: Color, ) { if !self.enabled { return; @@ -556,12 +546,12 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { /// # use bevy_render::prelude::*; /// # use bevy_math::prelude::*; /// fn system(mut gizmos: Gizmos) { - /// gizmos.rect_2d(Vec2::ZERO, 0., Vec2::ONE, LegacyColor::GREEN); + /// gizmos.rect_2d(Vec2::ZERO, 0., Vec2::ONE, Color::GREEN); /// } /// # bevy_ecs::system::assert_is_system(system); /// ``` #[inline] - pub fn rect_2d(&mut self, position: Vec2, rotation: f32, size: Vec2, color: LegacyColor) { + pub fn rect_2d(&mut self, position: Vec2, rotation: f32, size: Vec2, color: Color) { if !self.enabled { return; } @@ -578,14 +568,14 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { } #[inline] - fn extend_list_colors(&mut self, colors: impl IntoIterator) { + fn extend_list_colors(&mut self, colors: impl IntoIterator) { self.buffer .list_colors .extend(colors.into_iter().map(LinearRgba::from)); } #[inline] - fn add_list_color(&mut self, color: LegacyColor, count: usize) { + fn add_list_color(&mut self, color: Color, count: usize) { self.buffer .list_colors .extend(iter::repeat(LinearRgba::from(color)).take(count)); @@ -608,7 +598,7 @@ pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> { position: Vec3, rotation: Quat, radius: f32, - color: LegacyColor, + color: Color, circle_segments: usize, } diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 1dd86c5ac577f..c77f38eee0aaa 100644 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -6,7 +6,7 @@ //! # use bevy_render::prelude::*; //! # use bevy_math::prelude::*; //! fn system(mut gizmos: Gizmos) { -//! gizmos.line(Vec3::ZERO, Vec3::X, LegacyColor::GREEN); +//! gizmos.line(Vec3::ZERO, Vec3::X, Color::GREEN); //! } //! # bevy_ecs::system::assert_is_system(system); //! ``` diff --git a/crates/bevy_gizmos/src/primitives/dim2.rs b/crates/bevy_gizmos/src/primitives/dim2.rs index a47e01dbd43cc..393a01a50b535 100644 --- a/crates/bevy_gizmos/src/primitives/dim2.rs +++ b/crates/bevy_gizmos/src/primitives/dim2.rs @@ -4,12 +4,12 @@ use std::f32::consts::PI; use super::helpers::*; +use bevy_color::Color; use bevy_math::primitives::{ BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d, }; use bevy_math::{Direction2d, Mat2, Vec2}; -use bevy_render::color::LegacyColor; use crate::prelude::{GizmoConfigGroup, Gizmos}; @@ -32,7 +32,7 @@ pub trait GizmoPrimitive2d { primitive: P, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_>; } @@ -46,7 +46,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, ' primitive: Direction2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -70,7 +70,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> primitive: Circle, position: Vec2, _angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -90,7 +90,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T primitive: Ellipse, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -110,7 +110,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, primitive: Capsule2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -165,9 +165,9 @@ pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { direction: Direction2d, // Direction of the line - position: Vec2, // position of the center of the line - rotation: Mat2, // rotation of the line - color: LegacyColor, // color of the line + position: Vec2, // position of the center of the line + rotation: Mat2, // rotation of the line + color: Color, // color of the line draw_arrow: bool, // decides whether to indicate the direction of the line with an arrow } @@ -188,7 +188,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> primitive: Line2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Line2dBuilder { gizmos: self, @@ -239,7 +239,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T primitive: Plane2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -285,9 +285,9 @@ pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { direction: Direction2d, // Direction of the line segment half_length: f32, // Half-length of the line segment - position: Vec2, // position of the center of the line segment - rotation: Mat2, // rotation of the line segment - color: LegacyColor, // color of the line segment + position: Vec2, // position of the center of the line segment + rotation: Mat2, // rotation of the line segment + color: Color, // color of the line segment draw_arrow: bool, // decides whether to draw just a line or an arrow } @@ -308,7 +308,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, primitive: Segment2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Segment2dBuilder { gizmos: self, @@ -354,7 +354,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d primitive: Polyline2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -381,7 +381,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<' primitive: BoxedPolyline2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -408,7 +408,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's primitive: Triangle2d, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -429,7 +429,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, primitive: Rectangle, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -459,7 +459,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d> primitive: Polygon, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -496,7 +496,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, primitive: BoxedPolygon, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -531,7 +531,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w primitive: RegularPolygon, position: Vec2, angle: f32, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; diff --git a/crates/bevy_gizmos/src/primitives/dim3.rs b/crates/bevy_gizmos/src/primitives/dim3.rs index 78d9f75897b6c..eec4f4b22804d 100644 --- a/crates/bevy_gizmos/src/primitives/dim3.rs +++ b/crates/bevy_gizmos/src/primitives/dim3.rs @@ -3,12 +3,12 @@ use super::helpers::*; use std::f32::consts::TAU; +use bevy_color::Color; use bevy_math::primitives::{ BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d, Polyline3d, Primitive3d, Segment3d, Sphere, Torus, }; use bevy_math::{Direction3d, Quat, Vec3}; -use bevy_render::color::LegacyColor; use crate::prelude::{GizmoConfigGroup, Gizmos}; @@ -29,7 +29,7 @@ pub trait GizmoPrimitive3d { primitive: P, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_>; } @@ -43,7 +43,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, ' primitive: Direction3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { self.arrow(position, position + (rotation * *primitive), color); } @@ -63,7 +63,7 @@ pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // Center position of the sphere in 3D space position: Vec3, // Color of the sphere - color: LegacyColor, + color: Color, // Number of segments used to approximate the sphere geometry segments: usize, @@ -85,7 +85,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> primitive: Sphere, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { SphereBuilder { gizmos: self, @@ -146,7 +146,7 @@ pub struct Plane3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // Center position of the sphere in 3D space position: Vec3, // Color of the sphere - color: LegacyColor, + color: Color, // Number of axis to hint the plane axis_count: usize, @@ -184,7 +184,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T primitive: Plane3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Plane3dBuilder { gizmos: self, @@ -251,7 +251,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> primitive: Line3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -278,7 +278,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, primitive: Segment3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -303,7 +303,7 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive3d primitive: Polyline3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -328,7 +328,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<' primitive: BoxedPolyline3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -355,7 +355,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> primitive: Cuboid, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { if !self.enabled { return; @@ -417,7 +417,7 @@ pub struct Cylinder3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // default orientation is: the cylinder is aligned with `Vec3::Y` axis rotation: Quat, // Color of the cylinder - color: LegacyColor, + color: Color, // Number of segments used to approximate the cylinder geometry segments: usize, @@ -439,7 +439,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, primitive: Cylinder, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Cylinder3dBuilder { gizmos: self, @@ -514,7 +514,7 @@ pub struct Capsule3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // default orientation is: the capsule is aligned with `Vec3::Y` axis rotation: Quat, // Color of the capsule - color: LegacyColor, + color: Color, // Number of segments used to approximate the capsule geometry segments: usize, @@ -536,7 +536,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, primitive: Capsule3d, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Capsule3dBuilder { gizmos: self, @@ -607,7 +607,7 @@ pub struct Cone3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // default orientation is: cone base normal is aligned with the `Vec3::Y` axis rotation: Quat, // Color of the cone - color: LegacyColor, + color: Color, // Number of segments used to approximate the cone geometry segments: usize, @@ -629,7 +629,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { primitive: Cone, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Cone3dBuilder { gizmos: self, @@ -703,7 +703,7 @@ pub struct ConicalFrustum3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // default orientation is: conical frustum base shape normals are aligned with `Vec3::Y` axis rotation: Quat, // Color of the conical frustum - color: LegacyColor, + color: Color, // Number of segments used to approximate the curved surfaces segments: usize, @@ -725,7 +725,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w primitive: ConicalFrustum, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { ConicalFrustum3dBuilder { gizmos: self, @@ -807,7 +807,7 @@ pub struct Torus3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { // default orientation is: major circle normal is aligned with `Vec3::Y` axis rotation: Quat, // Color of the torus - color: LegacyColor, + color: Color, // Number of segments in the minor (tube) direction minor_segments: usize, @@ -837,7 +837,7 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> primitive: Torus, position: Vec3, rotation: Quat, - color: LegacyColor, + color: Color, ) -> Self::Output<'_> { Torus3dBuilder { gizmos: self, diff --git a/crates/bevy_gizmos/src/primitives/helpers.rs b/crates/bevy_gizmos/src/primitives/helpers.rs index 54669930c9d68..3de0502829536 100644 --- a/crates/bevy_gizmos/src/primitives/helpers.rs +++ b/crates/bevy_gizmos/src/primitives/helpers.rs @@ -1,7 +1,7 @@ use std::f32::consts::TAU; +use bevy_color::Color; use bevy_math::{Mat2, Quat, Vec2, Vec3}; -use bevy_render::color::LegacyColor; use crate::prelude::{GizmoConfigGroup, Gizmos}; @@ -58,7 +58,7 @@ pub(crate) fn draw_semi_sphere( rotation: Quat, center: Vec3, top: Vec3, - color: LegacyColor, + color: Color, ) { circle_coordinates(radius, segments) .map(|p| Vec3::new(p.x, 0.0, p.y)) @@ -81,7 +81,7 @@ pub(crate) fn draw_circle_3d( segments: usize, rotation: Quat, translation: Vec3, - color: LegacyColor, + color: Color, ) { let positions = (0..=segments) .map(|frac| frac as f32 / segments as f32) @@ -100,7 +100,7 @@ pub(crate) fn draw_cylinder_vertical_lines( half_height: f32, rotation: Quat, center: Vec3, - color: LegacyColor, + color: Color, ) { circle_coordinates(radius, segments) .map(move |point_2d| { diff --git a/examples/2d/2d_viewport_to_world.rs b/examples/2d/2d_viewport_to_world.rs index 59717973ab975..acfd9da84a61c 100644 --- a/examples/2d/2d_viewport_to_world.rs +++ b/examples/2d/2d_viewport_to_world.rs @@ -1,6 +1,6 @@ //! This example demonstrates how to use the `Camera::viewport_to_world_2d` method. -use bevy::prelude::*; +use bevy::{color::palettes::basic::WHITE, prelude::*}; fn main() { App::new() @@ -26,7 +26,7 @@ fn draw_cursor( return; }; - gizmos.circle_2d(point, 10., LegacyColor::WHITE); + gizmos.circle_2d(point, 10., WHITE.into()); } fn setup(mut commands: Commands) { diff --git a/examples/2d/bounding_2d.rs b/examples/2d/bounding_2d.rs index cc296c0647f1f..1f6e4a216157c 100644 --- a/examples/2d/bounding_2d.rs +++ b/examples/2d/bounding_2d.rs @@ -1,6 +1,6 @@ //! This example demonstrates bounding volume intersections. -use bevy::{math::bounding::*, prelude::*}; +use bevy::{color::palettes::css::*, math::bounding::*, prelude::*}; fn main() { App::new() @@ -97,7 +97,7 @@ enum Shape { } fn render_shapes(mut gizmos: Gizmos, query: Query<(&Shape, &Transform)>) { - let color = LegacyColor::GRAY; + let color = GRAY.into(); for (shape, transform) in query.iter() { let translation = transform.translation.xy(); let rotation = transform.rotation.to_euler(EulerRot::YXZ).2; @@ -178,9 +178,9 @@ fn update_volumes( fn render_volumes(mut gizmos: Gizmos, query: Query<(&CurrentVolume, &Intersects)>) { for (volume, intersects) in query.iter() { let color = if **intersects { - LegacyColor::CYAN + CYAN.into() } else { - LegacyColor::ORANGE_RED + ORANGE_RED.into() }; match volume { CurrentVolume::Aabb(a) => { @@ -292,10 +292,10 @@ fn draw_ray(gizmos: &mut Gizmos, ray: &RayCast2d) { gizmos.line_2d( ray.ray.origin, ray.ray.origin + *ray.ray.direction * ray.max, - LegacyColor::WHITE, + WHITE.into(), ); for r in [1., 2., 3.] { - gizmos.circle_2d(ray.ray.origin, r, LegacyColor::FUCHSIA); + gizmos.circle_2d(ray.ray.origin, r, FUCHSIA.into()); } } @@ -331,7 +331,7 @@ fn ray_cast_system( gizmos.circle_2d( ray_cast.ray.origin + *ray_cast.ray.direction * toi, r, - LegacyColor::GREEN, + GREEN.into(), ); } } @@ -363,7 +363,7 @@ fn aabb_cast_system( + aabb_cast.aabb.center(), 0., aabb_cast.aabb.half_size() * 2., - LegacyColor::GREEN, + GREEN.into(), ); } } @@ -393,7 +393,7 @@ fn bounding_circle_cast_system( + *circle_cast.ray.ray.direction * toi + circle_cast.circle.center(), circle_cast.circle.radius(), - LegacyColor::GREEN, + GREEN.into(), ); } } @@ -412,7 +412,7 @@ fn aabb_intersection_system( ) { let center = get_intersection_position(&time); let aabb = Aabb2d::new(center, Vec2::splat(50.)); - gizmos.rect_2d(center, 0., aabb.half_size() * 2., LegacyColor::YELLOW); + gizmos.rect_2d(center, 0., aabb.half_size() * 2., YELLOW.into()); for (volume, mut intersects) in volumes.iter_mut() { let hit = match volume { @@ -431,7 +431,7 @@ fn circle_intersection_system( ) { let center = get_intersection_position(&time); let circle = BoundingCircle::new(center, 50.); - gizmos.circle_2d(center, circle.radius(), LegacyColor::YELLOW); + gizmos.circle_2d(center, circle.radius(), YELLOW.into()); for (volume, mut intersects) in volumes.iter_mut() { let hit = match volume { diff --git a/examples/3d/3d_viewport_to_world.rs b/examples/3d/3d_viewport_to_world.rs index 22aef131b09e2..7dfb7344b8927 100644 --- a/examples/3d/3d_viewport_to_world.rs +++ b/examples/3d/3d_viewport_to_world.rs @@ -1,5 +1,6 @@ //! This example demonstrates how to use the `Camera::viewport_to_world` method. +use bevy::color::palettes::basic::WHITE; use bevy::math::Direction3d; use bevy::prelude::*; @@ -41,7 +42,7 @@ fn draw_cursor( point + ground.up() * 0.01, Direction3d::new_unchecked(ground.up()), // Up vector is already normalized. 0.2, - LegacyColor::WHITE, + WHITE.into(), ); } diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index 34f0608fcebd5..f001e909cfbee 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -13,6 +13,7 @@ //! //! * Clicking anywhere moves the object. +use bevy::color::palettes::css::*; use bevy::core_pipeline::Skybox; use bevy::math::{uvec3, vec3}; use bevy::pbr::irradiance_volume::IrradianceVolume; @@ -47,7 +48,7 @@ static SWITCH_TO_SPHERE_HELP_TEXT: &str = "Tab: Switch to a plain sphere mesh"; static CLICK_TO_MOVE_HELP_TEXT: &str = "Left click: Move the object"; -static GIZMO_COLOR: LegacyColor = LegacyColor::YELLOW; +static GIZMO_COLOR: Color = Color::Srgba(YELLOW); static VOXEL_TRANSFORM: Mat4 = Mat4::from_cols_array_2d(&[ [-42.317566, 0.0, 0.0, 0.0], diff --git a/examples/animation/cubic_curve.rs b/examples/animation/cubic_curve.rs index c6eb26dc24537..c9227fe3d75a7 100644 --- a/examples/animation/cubic_curve.rs +++ b/examples/animation/cubic_curve.rs @@ -1,6 +1,7 @@ //! Demonstrates how to work with Cubic curves. use bevy::{ + color::palettes::basic::WHITE, math::{cubic_splines::CubicCurve, vec3}, prelude::*, }; @@ -77,7 +78,7 @@ fn animate_cube(time: Res