1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- use bevy::prelude::*;
- #[derive(Component)]
- struct Rotator;
- fn main() {
- App::new()
- .add_plugins(DefaultPlugins)
- .add_systems(Startup, setup)
- .add_systems(Update, rotate)
- .run();
- }
- fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
- commands.spawn(Camera3dBundle {
- transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
- ..default()
- });
- commands.spawn(PointLightBundle {
- point_light: PointLight {
- shadows_enabled: true,
- ..default()
- },
- transform: Transform::from_xyz(4.0, 8.0, 4.0),
- ..default()
- });
- for x in -1..2 {
- for y in -1..2 {
- commands.spawn((
- SceneBundle {
- scene: asset_server.load("test-cube.glb#Scene0"),
- transform: Transform::from_xyz((x * 3) as f32, 0.0, (y * 3) as f32),
- ..default()
- },
- Rotator,
- ));
- }
- }
- }
- fn rotate(mut query: Query<&mut Transform, With<Rotator>>, time: Res<Time>) {
- for mut transform in &mut query {
- transform.rotate_y(time.delta_seconds() / 2.);
- }
- }
|