//! This example demonstrates Bevy's immediate mode drawing API intended for visual debugging. #[path = "../helpers/camera_controller.rs"] mod camera_controller; use bevy::{color::palettes::css::*, prelude::*}; use camera_controller::{CameraController, CameraControllerPlugin}; use std::f32::consts::PI; fn main() { App::new() .add_plugins((DefaultPlugins, CameraControllerPlugin)) .init_gizmo_group::() .add_systems(Startup, setup) .add_systems(Update, (draw_example_collection, update_config)) .run(); } // We can create our own gizmo config group! #[derive(Default, Reflect, GizmoConfigGroup)] struct MyRoundGizmos {} fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( Camera3d::default(), Transform::from_xyz(0., 1.5, 6.).looking_at(Vec3::ZERO, Vec3::Y), CameraController::default(), )); // plane commands.spawn(( Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))), MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), )); // cube commands.spawn(( Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), Transform::from_xyz(0.0, 0.5, 0.0), )); // light commands.spawn(( PointLight { shadows_enabled: true, ..default() }, Transform::from_xyz(4.0, 8.0, 4.0), )); // example instructions commands.spawn(( Text::new( "Press 'T' to toggle drawing gizmos on top of everything else in the scene\n\ Press 'P' to toggle perspective for line gizmos\n\ 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 'B' to show all AABB boxes\n\ Press 'U' or 'I' to cycle through line styles for straight or round gizmos\n\ Press 'J' or 'K' to cycle through line joins for straight or round gizmos", ), Style { position_type: PositionType::Absolute, top: Val::Px(12.0), left: Val::Px(12.0), ..default() }, )); } fn draw_example_collection( mut gizmos: Gizmos, mut my_gizmos: Gizmos, time: Res