From 99bdbe79858da75606385950cc3e40b9e4872a24 Mon Sep 17 00:00:00 2001 From: Aceeri Date: Tue, 5 Mar 2024 16:57:32 -0800 Subject: [PATCH] Fix up primitives/grid --- crates/bevy_gizmos/src/grid.rs | 30 ++- crates/bevy_gizmos/src/primitives/dim2.rs | 130 ++++++++--- crates/bevy_gizmos/src/primitives/dim3.rs | 233 +++++++++++++++---- crates/bevy_gizmos/src/primitives/helpers.rs | 27 ++- 4 files changed, 329 insertions(+), 91 deletions(-) diff --git a/crates/bevy_gizmos/src/grid.rs b/crates/bevy_gizmos/src/grid.rs index c7b007746849c6..60a565a8c910cb 100644 --- a/crates/bevy_gizmos/src/grid.rs +++ b/crates/bevy_gizmos/src/grid.rs @@ -8,8 +8,12 @@ use bevy_color::LinearRgba; use bevy_math::{Quat, UVec2, Vec2, Vec3}; /// A builder returned by [`Gizmos::grid`] and [`Gizmos::grid_2d`] -pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct GridBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, position: Vec3, rotation: Quat, spacing: Vec2, @@ -19,7 +23,11 @@ pub struct GridBuilder<'a, 'w, 's, T: GizmoConfigGroup> { color: LinearRgba, } -impl GridBuilder<'_, '_, '_, T> { +impl GridBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Skews the grid by `tan(skew)` in the x direction. /// `skew` is in radians pub fn skew_x(mut self, skew: f32) -> Self { @@ -47,7 +55,11 @@ impl GridBuilder<'_, '_, '_, T> { } } -impl Drop for GridBuilder<'_, '_, '_, T> { +impl Drop for GridBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Draws a grid, by drawing lines with the stored [`Gizmos`] fn drop(&mut self) { if !self.gizmos.enabled { @@ -103,7 +115,11 @@ impl Drop for GridBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Draw a 2D grid in 3D. /// /// This should be called for each frame the grid needs to be rendered. @@ -147,7 +163,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { cell_count: UVec2, spacing: Vec2, color: impl Into, - ) -> GridBuilder<'_, 'w, 's, T> { + ) -> GridBuilder<'_, 'w, 's, Config, Clear> { GridBuilder { gizmos: self, position, @@ -203,7 +219,7 @@ impl<'w, 's, T: GizmoConfigGroup> Gizmos<'w, 's, T> { cell_count: UVec2, spacing: Vec2, color: impl Into, - ) -> GridBuilder<'_, 'w, 's, T> { + ) -> GridBuilder<'_, 'w, 's, Config, Clear> { GridBuilder { gizmos: self, position: position.extend(0.), diff --git a/crates/bevy_gizmos/src/primitives/dim2.rs b/crates/bevy_gizmos/src/primitives/dim2.rs index dfc2813b5ee403..1162df7da9056c 100644 --- a/crates/bevy_gizmos/src/primitives/dim2.rs +++ b/crates/bevy_gizmos/src/primitives/dim2.rs @@ -38,7 +38,11 @@ pub trait GizmoPrimitive2d { // direction 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self : 'a; fn primitive_2d( @@ -62,7 +66,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { // circle 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -82,7 +90,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> // ellipse 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -102,7 +114,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T // capsule 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -168,8 +184,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, // line 2d // /// Builder for configuring the drawing options of [`Line2d`]. -pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Line2dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, direction: Dir2, // Direction of the line @@ -180,7 +200,11 @@ pub struct Line2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { draw_arrow: bool, // decides whether to indicate the direction of the line with an arrow } -impl Line2dBuilder<'_, '_, '_, T> { +impl Line2dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the drawing mode of the line (arrow vs. plain line) pub fn draw_arrow(mut self, is_enabled: bool) -> Self { self.draw_arrow = is_enabled; @@ -188,8 +212,12 @@ impl Line2dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { - type Output<'a> = Line2dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Line2dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_2d( &mut self, @@ -209,7 +237,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> } } -impl Drop for Line2dBuilder<'_, '_, '_, T> { +impl Drop for Line2dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -239,7 +271,11 @@ impl Drop for Line2dBuilder<'_, '_, '_, T> { // plane 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -289,8 +325,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T // segment 2d /// Builder for configuring the drawing options of [`Segment2d`]. -pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Segment2dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, direction: Dir2, // Direction of the line segment half_length: f32, // Half-length of the line segment @@ -302,7 +342,11 @@ pub struct Segment2dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { draw_arrow: bool, // decides whether to draw just a line or an arrow } -impl Segment2dBuilder<'_, '_, '_, T> { +impl Segment2dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the drawing mode of the line (arrow vs. plain line) pub fn draw_arrow(mut self, is_enabled: bool) -> Self { self.draw_arrow = is_enabled; @@ -310,8 +354,12 @@ impl Segment2dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { - type Output<'a> = Segment2dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Segment2dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_2d( &mut self, @@ -334,7 +382,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, } } -impl Drop for Segment2dBuilder<'_, '_, '_, T> { +impl Drop for Segment2dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -354,8 +406,11 @@ impl Drop for Segment2dBuilder<'_, '_, '_, T> { // polyline 2d -impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d> - for Gizmos<'w, 's, T> +impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d> + for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, { type Output<'a> = () where Self: 'a; @@ -383,7 +438,11 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d // boxed polyline 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -410,7 +469,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<' // triangle 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -431,7 +494,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's // rectangle 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -459,8 +526,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, // polygon 2d -impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d> - for Gizmos<'w, 's, T> +impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive2d> + for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, { type Output<'a> = () where Self: 'a; @@ -498,7 +568,11 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive2d> // boxed polygon 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( @@ -533,7 +607,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, // regular polygon 2d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive2d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive2d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_2d( diff --git a/crates/bevy_gizmos/src/primitives/dim3.rs b/crates/bevy_gizmos/src/primitives/dim3.rs index eae53b1fcf3b49..96230cbe76654d 100644 --- a/crates/bevy_gizmos/src/primitives/dim3.rs +++ b/crates/bevy_gizmos/src/primitives/dim3.rs @@ -35,7 +35,11 @@ pub trait GizmoPrimitive3d { // direction 3d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_3d( @@ -52,8 +56,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { // sphere /// Builder for configuring the drawing options of [`Sphere`]. -pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct SphereBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the sphere radius: f32, @@ -69,7 +77,11 @@ pub struct SphereBuilder<'a, 'w, 's, T: GizmoConfigGroup> { segments: usize, } -impl SphereBuilder<'_, '_, '_, T> { +impl SphereBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to approximate the sphere geometry. pub fn segments(mut self, segments: usize) -> Self { self.segments = segments; @@ -77,8 +89,12 @@ impl SphereBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = SphereBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = SphereBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -98,7 +114,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> } } -impl Drop for SphereBuilder<'_, '_, '_, T> { +impl Drop for SphereBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -135,8 +155,12 @@ impl Drop for SphereBuilder<'_, '_, '_, T> { // plane 3d /// Builder for configuring the drawing options of [`Sphere`]. -pub struct Plane3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Plane3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // direction of the normal orthogonal to the plane normal: Dir3, @@ -156,7 +180,11 @@ pub struct Plane3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { segment_length: f32, } -impl Plane3dBuilder<'_, '_, '_, T> { +impl Plane3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to hint the plane. pub fn segment_count(mut self, count: usize) -> Self { self.segment_count = count; @@ -176,8 +204,12 @@ impl Plane3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = Plane3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Plane3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -199,7 +231,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T } } -impl Drop for Plane3dBuilder<'_, '_, '_, T> { +impl Drop for Plane3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -243,7 +279,11 @@ impl Drop for Plane3dBuilder<'_, '_, '_, T> { // line 3d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_3d( @@ -270,7 +310,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> // segment 3d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_3d( @@ -293,8 +337,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, // polyline 3d -impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive3d> - for Gizmos<'w, 's, T> +impl<'w, 's, const N: usize, Config, Clear> GizmoPrimitive3d> + for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, { type Output<'a> = () where Self: 'a; @@ -320,7 +367,11 @@ impl<'w, 's, const N: usize, T: GizmoConfigGroup> GizmoPrimitive3d // boxed polyline 3d -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_3d( @@ -347,7 +398,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<' // cuboid -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ type Output<'a> = () where Self: 'a; fn primitive_3d( @@ -402,8 +457,12 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> // cylinder 3d /// Builder for configuring the drawing options of [`Cylinder`]. -pub struct Cylinder3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Cylinder3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the cylinder radius: f32, @@ -423,7 +482,11 @@ pub struct Cylinder3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { segments: usize, } -impl Cylinder3dBuilder<'_, '_, '_, T> { +impl Cylinder3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to approximate the cylinder geometry. pub fn segments(mut self, segments: usize) -> Self { self.segments = segments; @@ -431,8 +494,12 @@ impl Cylinder3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = Cylinder3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Cylinder3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -453,7 +520,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, } } -impl Drop for Cylinder3dBuilder<'_, '_, '_, T> { +impl Drop for Cylinder3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -499,8 +570,12 @@ impl Drop for Cylinder3dBuilder<'_, '_, '_, T> { // capsule 3d /// Builder for configuring the drawing options of [`Capsule3d`]. -pub struct Capsule3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Capsule3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the capsule radius: f32, @@ -520,7 +595,11 @@ pub struct Capsule3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { segments: usize, } -impl Capsule3dBuilder<'_, '_, '_, T> { +impl Capsule3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to approximate the capsule geometry. pub fn segments(mut self, segments: usize) -> Self { self.segments = segments; @@ -528,8 +607,12 @@ impl Capsule3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = Capsule3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Capsule3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -550,7 +633,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, } } -impl Drop for Capsule3dBuilder<'_, '_, '_, T> { +impl Drop for Capsule3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -592,8 +679,12 @@ impl Drop for Capsule3dBuilder<'_, '_, '_, T> { // cone 3d /// Builder for configuring the drawing options of [`Cone`]. -pub struct Cone3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Cone3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the cone radius: f32, @@ -616,7 +707,11 @@ pub struct Cone3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { height_segments: usize, } -impl Cone3dBuilder<'_, '_, '_, T> { +impl Cone3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to approximate the cone geometry for its base and height. pub fn segments(mut self, segments: usize) -> Self { self.base_segments = segments; @@ -643,8 +738,12 @@ impl Cone3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = Cone3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Cone3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -666,7 +765,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { } } -impl Drop for Cone3dBuilder<'_, '_, '_, T> { +impl Drop for Cone3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -710,8 +813,12 @@ impl Drop for Cone3dBuilder<'_, '_, '_, T> { // conical frustum 3d /// Builder for configuring the drawing options of [`ConicalFrustum`]. -pub struct ConicalFrustum3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct ConicalFrustum3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the top circle radius_top: f32, @@ -733,7 +840,11 @@ pub struct ConicalFrustum3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { segments: usize, } -impl ConicalFrustum3dBuilder<'_, '_, '_, T> { +impl ConicalFrustum3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments used to approximate the curved surfaces. pub fn segments(mut self, segments: usize) -> Self { self.segments = segments; @@ -741,8 +852,12 @@ impl ConicalFrustum3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = ConicalFrustum3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = ConicalFrustum3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -764,7 +879,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w } } -impl Drop for ConicalFrustum3dBuilder<'_, '_, '_, T> { +impl Drop for ConicalFrustum3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; @@ -816,8 +935,12 @@ impl Drop for ConicalFrustum3dBuilder<'_, '_, '_, T> { // torus 3d /// Builder for configuring the drawing options of [`Torus`]. -pub struct Torus3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { - gizmos: &'a mut Gizmos<'w, 's, T>, +pub struct Torus3dBuilder<'a, 'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + gizmos: &'a mut Gizmos<'w, 's, Config, Clear>, // Radius of the minor circle (tube) minor_radius: f32, @@ -839,7 +962,11 @@ pub struct Torus3dBuilder<'a, 'w, 's, T: GizmoConfigGroup> { major_segments: usize, } -impl Torus3dBuilder<'_, '_, '_, T> { +impl Torus3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ /// Set the number of segments in the minor (tube) direction. pub fn minor_segments(mut self, minor_segments: usize) -> Self { self.minor_segments = minor_segments; @@ -853,8 +980,12 @@ impl Torus3dBuilder<'_, '_, '_, T> { } } -impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { - type Output<'a> = Torus3dBuilder<'a, 'w, 's, T> where Self: 'a; +impl<'w, 's, Config, Clear> GizmoPrimitive3d for Gizmos<'w, 's, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ + type Output<'a> = Torus3dBuilder<'a, 'w, 's, Config, Clear> where Self: 'a; fn primitive_3d( &mut self, @@ -876,7 +1007,11 @@ impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> } } -impl Drop for Torus3dBuilder<'_, '_, '_, T> { +impl Drop for Torus3dBuilder<'_, '_, '_, Config, Clear> +where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ fn drop(&mut self) { if !self.gizmos.enabled { return; diff --git a/crates/bevy_gizmos/src/primitives/helpers.rs b/crates/bevy_gizmos/src/primitives/helpers.rs index 3de05028295367..a60d0790669794 100644 --- a/crates/bevy_gizmos/src/primitives/helpers.rs +++ b/crates/bevy_gizmos/src/primitives/helpers.rs @@ -51,15 +51,18 @@ pub(crate) fn circle_coordinates(radius: f32, segments: usize) -> impl Iterator< /// This function draws a semi-sphere at the specified `center` point with the given `rotation`, /// `radius`, and `color`. The `segments` parameter determines the level of detail, and the `top` /// argument specifies the shape of the semi-sphere's tip. -pub(crate) fn draw_semi_sphere( - gizmos: &mut Gizmos<'_, '_, T>, +pub(crate) fn draw_semi_sphere( + gizmos: &mut Gizmos<'_, '_, Config, Clear>, radius: f32, segments: usize, rotation: Quat, center: Vec3, top: Vec3, color: Color, -) { +) where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ circle_coordinates(radius, segments) .map(|p| Vec3::new(p.x, 0.0, p.y)) .map(rotate_then_translate_3d(rotation, center)) @@ -75,14 +78,17 @@ pub(crate) fn draw_semi_sphere( /// # Note /// /// This function is necessary to use instead of `gizmos.circle` for certain primitives to ensure that points align correctly. For example, the major circles of a torus are drawn with this method, and using `gizmos.circle` would result in the minor circles not being positioned precisely on the major circles' segment points. -pub(crate) fn draw_circle_3d( - gizmos: &mut Gizmos<'_, '_, T>, +pub(crate) fn draw_circle_3d( + gizmos: &mut Gizmos<'_, '_, Config, Clear>, radius: f32, segments: usize, rotation: Quat, translation: Vec3, color: Color, -) { +) where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ let positions = (0..=segments) .map(|frac| frac as f32 / segments as f32) .map(|percentage| percentage * TAU) @@ -93,15 +99,18 @@ pub(crate) fn draw_circle_3d( } /// Draws the connecting lines of a cylinder between the top circle and the bottom circle. -pub(crate) fn draw_cylinder_vertical_lines( - gizmos: &mut Gizmos<'_, '_, T>, +pub(crate) fn draw_cylinder_vertical_lines( + gizmos: &mut Gizmos<'_, '_, Config, Clear>, radius: f32, segments: usize, half_height: f32, rotation: Quat, center: Vec3, color: Color, -) { +) where + Config: GizmoConfigGroup, + Clear: 'static + Send + Sync, +{ circle_coordinates(radius, segments) .map(move |point_2d| { [1.0, -1.0]