main.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use bevy::prelude::*;
  2. #[derive(Component)]
  3. struct Rotator;
  4. fn main() {
  5. App::new()
  6. .add_plugins(DefaultPlugins)
  7. .add_systems(Startup, setup)
  8. .add_systems(Update, rotate)
  9. .run();
  10. }
  11. fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
  12. commands.spawn(Camera3dBundle {
  13. transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
  14. ..default()
  15. });
  16. commands.spawn(PointLightBundle {
  17. point_light: PointLight {
  18. shadows_enabled: true,
  19. ..default()
  20. },
  21. transform: Transform::from_xyz(4.0, 8.0, 4.0),
  22. ..default()
  23. });
  24. for x in -1..2 {
  25. for y in -1..2 {
  26. commands.spawn((
  27. SceneBundle {
  28. scene: asset_server.load("test-cube.glb#Scene0"),
  29. transform: Transform::from_xyz((x * 3) as f32, 0.0, (y * 3) as f32),
  30. ..default()
  31. },
  32. Rotator,
  33. ));
  34. }
  35. }
  36. }
  37. fn rotate(mut query: Query<&mut Transform, With<Rotator>>, time: Res<Time>) {
  38. for mut transform in &mut query {
  39. transform.rotate_y(time.delta_seconds() / 2.);
  40. }
  41. }