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 10:52:42 +02:00
|
|
|
PbrBundle {//Plane3d::default().mesh().size(1., 1.)
|
|
|
|
mesh: meshes.add(Cuboid::new(0.25, 0.25, 0.25)),
|
|
|
|
material: materials.add(Color::srgb(1.0, 1.0, 1.0)),
|
|
|
|
transform: Transform::from_xyz(5.0, 0.0, 0.0),
|
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 {
|
2024-10-05 10:52:42 +02:00
|
|
|
transform: Transform::from_xyz(0.0, 0.0, 0.0).with_rotation(Quat::from_rotation_y(-1.5)),
|
2024-10-05 09:46:57 +02:00
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
2024-10-05 09:37:47 +02:00
|
|
|
// camera
|
2024-10-05 09:46:57 +02:00
|
|
|
commands.spawn(Camera3dBundle {
|
2024-10-05 10:52:42 +02:00
|
|
|
transform: Transform::from_xyz(0.0, 0.0, 0.0).with_rotation(Quat::from_rotation_y(-1.5)),
|
2024-10-05 09:46:57 +02:00
|
|
|
..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),
|
|
|
|
// ));
|
|
|
|
// }
|