use std::f32::consts::PI; use bevy::{ color::palettes, prelude::*, render::{ render_asset::RenderAssetUsages, render_resource::{Extent3d, TextureDimension, TextureFormat}, }, }; /// A marker component for our shapes so we can query them separately from the ground plane #[derive(Component)] pub struct Shape; /// A marker component for the 3d camera #[derive(Component)] pub struct PrimaryCamera; const X_EXTENT: f32 = 14.5; // Setup 3d shapes pub fn setup( mut commands: Commands, mut meshes: ResMut>, mut images: ResMut>, mut materials: ResMut>, ) { let debug_material = materials.add(StandardMaterial { base_color_texture: Some(images.add(uv_debug_texture())), ..default() }); let shapes = [ meshes.add(Cuboid::default()), meshes.add(Capsule3d::default()), meshes.add(Torus::default()), meshes.add(Cylinder::default()), meshes.add(Sphere::default().mesh().ico(5).unwrap()), meshes.add(Sphere::default().mesh().uv(32, 18)), ]; let num_shapes = shapes.len(); for (i, shape) in shapes.into_iter().enumerate() { commands.spawn(( PbrBundle { mesh: shape, material: debug_material.clone(), transform: Transform::from_xyz( -X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * X_EXTENT, 2.0, 0.0, ) .with_rotation(Quat::from_rotation_x(-PI / 4.)), ..default() }, Shape, )); } commands.spawn(PointLightBundle { point_light: PointLight { // intensity: 9000.0, intensity: 10000000.0, range: 100., shadows_enabled: true, ..default() }, transform: Transform::from_xyz(8.0, 16.0, 8.0), ..default() }); // ground plane commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(50.0, 50.0)), material: materials.add(Color::from(palettes::css::SILVER)), ..default() }); commands.spawn(( Camera3dBundle { transform: Transform::from_xyz(0.0, 6., 12.0) .looking_at(Vec3::new(0., 1., 0.), Vec3::Y), ..default() }, PrimaryCamera, )); } pub fn rotate(mut query: Query<&mut Transform, With>, time: Res