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:37:47 +02:00
|
|
|
/// set up a simple 3D scene
|
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:37:47 +02:00
|
|
|
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),
|
|
|
|
));
|
2024-10-05 08:41:37 +02:00
|
|
|
}
|