Skip to content

Commit 89cd5f5

Browse files
authored
Add Annulus-gizmos (#13233)
# Objective - Add support for drawing `Annulus`-gizmos using `gizmos.primitive_2d(...)` ## Changelog - Updated the example `math/render_primitives`
1 parent 423a473 commit 89cd5f5

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

crates/bevy_gizmos/src/primitives/dim2.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::helpers::*;
66

77
use bevy_color::Color;
88
use bevy_math::primitives::{
9-
BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
9+
Annulus, BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, Ellipse, Line2d, Plane2d, Polygon,
1010
Polyline2d, Primitive2d, Rectangle, RegularPolygon, Segment2d, Triangle2d,
1111
};
1212
use bevy_math::{Dir2, Mat2, Vec2};
@@ -112,6 +112,32 @@ where
112112
}
113113
}
114114

115+
// annulus 2d
116+
117+
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Annulus> for Gizmos<'w, 's, Config, Clear>
118+
where
119+
Config: GizmoConfigGroup,
120+
Clear: 'static + Send + Sync,
121+
{
122+
type Output<'a> = () where Self: 'a;
123+
124+
fn primitive_2d(
125+
&mut self,
126+
primitive: Annulus,
127+
position: Vec2,
128+
angle: f32,
129+
color: impl Into<Color>,
130+
) -> Self::Output<'_> {
131+
if !self.enabled {
132+
return;
133+
}
134+
135+
let color = color.into();
136+
self.primitive_2d(primitive.inner_circle, position, angle, color);
137+
self.primitive_2d(primitive.outer_circle, position, angle, color);
138+
}
139+
}
140+
115141
// capsule 2d
116142

117143
impl<'w, 's, Config, Clear> GizmoPrimitive2d<Capsule2d> for Gizmos<'w, 's, Config, Clear>

examples/math/render_primitives.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ const CONICAL_FRUSTUM: ConicalFrustum = ConicalFrustum {
240240
height: BIG_3D,
241241
};
242242

243+
const ANNULUS: Annulus = Annulus {
244+
inner_circle: Circle { radius: SMALL_2D },
245+
outer_circle: Circle { radius: BIG_2D },
246+
};
247+
243248
const TORUS: Torus = Torus {
244249
minor_radius: SMALL_3D / 2.0,
245250
major_radius: SMALL_3D * 1.5,
@@ -428,7 +433,7 @@ fn draw_gizmos_2d(mut gizmos: Gizmos, state: Res<State<PrimitiveSelected>>, time
428433
PrimitiveSelected::Cylinder => {}
429434
PrimitiveSelected::Cone => {}
430435
PrimitiveSelected::ConicalFrustum => {}
431-
PrimitiveSelected::Torus => {}
436+
PrimitiveSelected::Torus => gizmos.primitive_2d(ANNULUS, POSITION, angle, color),
432437
}
433438
}
434439

@@ -470,7 +475,7 @@ fn spawn_primitive_2d(
470475
None, // cylinder
471476
None, // cone
472477
None, // conical frustum
473-
None, // torus
478+
Some(ANNULUS.mesh().build()),
474479
]
475480
.into_iter()
476481
.zip(PrimitiveSelected::ALL)

0 commit comments

Comments
 (0)