Add comments to shapes example.

This commit is contained in:
Robin KAY 2022-08-08 23:57:14 +01:00
parent 5736faf0c1
commit 02b9b7c49f
1 changed files with 16 additions and 9 deletions

View File

@ -1,8 +1,11 @@
use std::f32::consts::{PI, TAU}; use std::f32::consts::{PI, TAU};
use bevy::prelude::{ use bevy::{
shape::{Cube, Torus}, prelude::{
*, shape::{Cube, Torus},
*,
},
window::close_on_esc,
}; };
use bevy_mod_outline::*; use bevy_mod_outline::*;
@ -15,6 +18,7 @@ fn main() {
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(OutlinePlugin) .add_plugin(OutlinePlugin)
.add_startup_system(setup) .add_startup_system(setup)
.add_system(close_on_esc)
.add_system(wobble) .add_system(wobble)
.add_system(orbit) .add_system(orbit)
.run(); .run();
@ -31,12 +35,7 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
commands.spawn_bundle(PbrBundle { // Add cube with generated outline normals
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
let mut cube_mesh = Mesh::from(Cube { size: 1.0 }); let mut cube_mesh = Mesh::from(Cube { size: 1.0 });
cube_mesh.generate_outline_normals().unwrap(); cube_mesh.generate_outline_normals().unwrap();
commands commands
@ -56,6 +55,7 @@ fn setup(
}) })
.insert(Wobbles); .insert(Wobbles);
// Add torus using the regular surface normals for outlining
commands commands
.spawn_bundle(PbrBundle { .spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(Torus { mesh: meshes.add(Mesh::from(Torus {
@ -78,6 +78,13 @@ fn setup(
..default() ..default()
}) })
.insert(Orbits); .insert(Orbits);
// Add plane, light source, and camera
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
commands.spawn_bundle(PointLightBundle { commands.spawn_bundle(PointLightBundle {
point_light: PointLight { point_light: PointLight {
intensity: 1500.0, intensity: 1500.0,