@@ -507,6 +507,41 @@ where
507507 self . strip_colors . push ( LinearRgba :: NAN ) ;
508508 }
509509
510+ /// Draw a line in 3D made of straight segments between the points, with the first and last connected.
511+ ///
512+ /// # Example
513+ /// ```
514+ /// # use bevy_gizmos::prelude::*;
515+ /// # use bevy_math::prelude::*;
516+ /// # use bevy_color::palettes::basic::GREEN;
517+ /// fn system(mut gizmos: Gizmos) {
518+ /// gizmos.lineloop([Vec3::ZERO, Vec3::X, Vec3::Y], GREEN);
519+ /// }
520+ /// # bevy_ecs::system::assert_is_system(system);
521+ /// ```
522+ #[ inline]
523+ pub fn lineloop ( & mut self , positions : impl IntoIterator < Item = Vec3 > , color : impl Into < Color > ) {
524+ if !self . enabled {
525+ return ;
526+ }
527+
528+ // Loop back to the start; second is needed to ensure that
529+ // the joint on the first corner is drawn.
530+ let mut positions = positions. into_iter ( ) ;
531+ let first = positions. next ( ) ;
532+ let second = positions. next ( ) ;
533+
534+ self . linestrip (
535+ first
536+ . into_iter ( )
537+ . chain ( second)
538+ . chain ( positions)
539+ . chain ( first)
540+ . chain ( second) ,
541+ color,
542+ ) ;
543+ }
544+
510545 /// Draw a line in 3D made of straight segments between the points, with a color gradient.
511546 ///
512547 /// # Example
@@ -576,7 +611,7 @@ where
576611 }
577612 let isometry = isometry. into ( ) ;
578613 let [ tl, tr, br, bl] = rect_inner ( size) . map ( |vec2| isometry * vec2. extend ( 0. ) ) ;
579- self . linestrip ( [ tl, tr, br, bl, tl ] , color) ;
614+ self . lineloop ( [ tl, tr, br, bl] , color) ;
580615 }
581616
582617 /// Draw a wireframe cube in 3D.
@@ -759,23 +794,7 @@ where
759794 if !self . enabled {
760795 return ;
761796 }
762-
763- // Loop back to the start; second is needed to ensure that
764- // the joint on the first corner is drawn.
765- let mut positions = positions. into_iter ( ) ;
766- let first = positions. next ( ) ;
767- let second = positions. next ( ) ;
768-
769- self . linestrip (
770- first
771- . into_iter ( )
772- . chain ( second)
773- . chain ( positions)
774- . chain ( first)
775- . chain ( second)
776- . map ( |vec2| vec2. extend ( 0. ) ) ,
777- color,
778- ) ;
797+ self . lineloop ( positions. into_iter ( ) . map ( |vec2| vec2. extend ( 0. ) ) , color) ;
779798 }
780799
781800 /// Draw a line in 2D made of straight segments between the points, with a color gradient.
0 commit comments