//! This example demonstrates Bevy's immediate mode drawing API intended for visual debugging. use std::f32::consts::{PI, TAU}; use bevy::prelude::*; fn main() { App::new() .init_state::() .add_plugins(DefaultPlugins) .init_gizmo_group::() .add_systems(Startup, setup) .add_systems(Update, (draw_example_collection, update_config)) .add_systems(Update, (draw_primitives, update_primitives)) .run(); } // We can create our own gizmo config group! #[derive(Default, Reflect, GizmoConfigGroup)] struct MyRoundGizmos {} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)] enum PrimitiveState { #[default] Nothing, Circle, Ellipse, Capsule, Line, Plane, Segment, Triangle, Rectangle, RegularPolygon, } impl PrimitiveState { const ALL: [Self; 10] = [ Self::Nothing, Self::Circle, Self::Ellipse, Self::Capsule, Self::Line, Self::Plane, Self::Segment, Self::Triangle, Self::Rectangle, Self::RegularPolygon, ]; fn next(self) -> Self { Self::ALL .into_iter() .cycle() .skip_while(|&x| x != self) .nth(1) .unwrap() } fn last(self) -> Self { Self::ALL .into_iter() .rev() .cycle() .skip_while(|&x| x != self) .nth(1) .unwrap() } } fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); // text commands.spawn(TextBundle::from_section( "Hold 'Left' or 'Right' to change the line width of straight gizmos\n\ Hold 'Up' or 'Down' to change the line width of round gizmos\n\ Press '1' or '2' to toggle the visibility of straight gizmos or round gizmos\n\ Press 'K' or 'J' to cycle through primitives rendered with gizmos", TextStyle { font: asset_server.load("fonts/FiraMono-Medium.ttf"), font_size: 24., color: Color::WHITE, }, )); } fn draw_example_collection( mut gizmos: Gizmos, mut my_gizmos: Gizmos, time: Res