astraea/src/main.rs

77 lines
1.9 KiB
Rust
Raw Normal View History

2024-10-05 09:37:47 +02:00
//! A simple 3D scene with light shining over a cube sitting on a plane.
2024-10-05 08:41:37 +02:00
use bevy::prelude::*;
2024-10-05 09:37:47 +02:00
use bevy::render::*;
use bevy::math::*;
2024-10-05 08:41:37 +02:00
fn main() {
App::new()
2024-10-05 09:37:47 +02:00
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
2024-10-05 08:41:37 +02:00
}
2024-10-05 09:46:57 +02:00
#[derive(Component)]
struct Star;
2024-10-05 08:41:37 +02:00
fn setup(
2024-10-05 09:37:47 +02:00
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
2024-10-05 08:41:37 +02:00
) {
2024-10-05 09:46:57 +02:00
// plane
2024-10-05 09:37:47 +02:00
commands.spawn((
2024-10-05 09:46:57 +02:00
PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(20., 20.)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
2024-10-05 09:37:47 +02:00
..default()
},
2024-10-05 09:46:57 +02:00
Star,
2024-10-05 09:37:47 +02:00
));
2024-10-05 09:46:57 +02:00
// light
commands.spawn(DirectionalLightBundle {
transform: Transform::from_translation(Vec3::ONE).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
2024-10-05 09:37:47 +02:00
// camera
2024-10-05 09:46:57 +02:00
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(15.0, 5.0, 15.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
2024-10-05 08:41:37 +02:00
}
2024-10-05 09:46:57 +02:00
// fn setup(
// mut commands: Commands,
// mut meshes: ResMut<Assets<Mesh>>,
// mut materials: ResMut<Assets<StandardMaterial>>,
// ) {
//
// let star_material = materials.add(Color::WHITE);
//
// let star = meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)));
//
// // circular base
// commands.spawn(MaterialMeshBundle {
// mesh: star,
// material: star_material.clone(),
// transform: Transform::from_xyz(0.0, 1.0, 0.0),
// ..default()
// });
// // light
// commands.spawn((
// PointLight {
// shadows_enabled: true,
// ..default()
// },
// Transform::from_xyz(0.0, 0.8, 1.0),
// ));
// // camera
// commands.spawn((
// Camera3d::default(),
// Transform::from_xyz(0.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
// ));
// }