Skip to content

Commit 892caff

Browse files
committed
fix: closes shapes for 3d gizmos
1 parent 0b75766 commit 892caff

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

crates/bevy_gizmos/src/gizmos.rs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

crates/bevy_gizmos/src/primitives/dim3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ where
287287

288288
let isometry = isometry.into();
289289
let [a, b, c] = primitive.vertices;
290-
self.linestrip([a, b, c, a].map(|vec3| isometry * vec3), color);
290+
self.lineloop([a, b, c].map(|vec3| isometry * vec3), color);
291291
}
292292
}
293293

0 commit comments

Comments
 (0)