2022-11-17 00:25:54 +00:00
|
|
|
use std::f32::consts::TAU;
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
prelude::{
|
2023-03-10 18:43:13 +00:00
|
|
|
shape::{Capsule, Plane, Torus, UVSphere},
|
2022-11-17 00:25:54 +00:00
|
|
|
*,
|
|
|
|
},
|
|
|
|
window::close_on_esc,
|
|
|
|
};
|
|
|
|
|
|
|
|
use bevy_mod_outline::*;
|
|
|
|
|
|
|
|
#[bevy_main]
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
2023-03-10 18:43:13 +00:00
|
|
|
.insert_resource(Msaa::Sample4)
|
2022-11-17 00:25:54 +00:00
|
|
|
.insert_resource(ClearColor(Color::BLACK))
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_plugin(OutlinePlugin)
|
|
|
|
.add_startup_system(setup)
|
|
|
|
.add_system(close_on_esc)
|
|
|
|
.add_system(rotates)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Rotates;
|
|
|
|
|
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
2022-11-22 22:42:25 +00:00
|
|
|
let outline = OutlineBundle {
|
|
|
|
outline: OutlineVolume {
|
|
|
|
visible: true,
|
|
|
|
colour: Color::WHITE,
|
|
|
|
width: 10.0,
|
|
|
|
},
|
2023-03-16 22:03:38 +00:00
|
|
|
stencil: OutlineStencil {
|
|
|
|
offset: 5.0,
|
|
|
|
..default()
|
|
|
|
},
|
2022-11-22 22:42:25 +00:00
|
|
|
..default()
|
|
|
|
};
|
|
|
|
|
2022-11-17 00:25:54 +00:00
|
|
|
// Add sphere with child meshes sticking out of it
|
|
|
|
commands
|
2022-11-22 00:05:47 +00:00
|
|
|
.spawn(PbrBundle {
|
2022-11-17 00:25:54 +00:00
|
|
|
mesh: meshes.add(
|
|
|
|
UVSphere {
|
|
|
|
radius: 0.75,
|
|
|
|
sectors: 30,
|
|
|
|
stacks: 30,
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
),
|
|
|
|
material: materials.add(Color::rgb(0.9, 0.1, 0.1).into()),
|
|
|
|
transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)),
|
|
|
|
..default()
|
|
|
|
})
|
2022-11-22 22:42:25 +00:00
|
|
|
.insert(outline.clone())
|
2022-11-17 00:25:54 +00:00
|
|
|
.insert(Rotates)
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent
|
2022-11-22 00:05:47 +00:00
|
|
|
.spawn(PbrBundle {
|
2022-11-17 00:25:54 +00:00
|
|
|
mesh: meshes.add(
|
|
|
|
Capsule {
|
|
|
|
radius: 0.2,
|
|
|
|
rings: 15,
|
|
|
|
depth: 1.0,
|
|
|
|
latitudes: 15,
|
|
|
|
longitudes: 15,
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
),
|
|
|
|
material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()),
|
|
|
|
transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::X, TAU / 4.0))
|
|
|
|
.with_translation(Vec3::new(0.0, 0.0, 0.75)),
|
|
|
|
..default()
|
|
|
|
})
|
2022-11-22 22:42:25 +00:00
|
|
|
.insert(outline.clone())
|
2022-11-17 22:15:13 +00:00
|
|
|
.insert(InheritOutlineDepth);
|
2022-11-17 00:25:54 +00:00
|
|
|
parent
|
2022-11-22 00:05:47 +00:00
|
|
|
.spawn(PbrBundle {
|
2022-11-17 00:25:54 +00:00
|
|
|
mesh: meshes.add(
|
|
|
|
Torus {
|
|
|
|
radius: 0.5,
|
|
|
|
ring_radius: 0.1,
|
|
|
|
subdivisions_segments: 30,
|
|
|
|
subdivisions_sides: 15,
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
),
|
|
|
|
material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()),
|
|
|
|
transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::Z, TAU / 4.0))
|
|
|
|
.with_translation(Vec3::new(0.0, 0.0, -0.75)),
|
|
|
|
..default()
|
|
|
|
})
|
2022-11-22 22:42:25 +00:00
|
|
|
.insert(outline.clone())
|
2022-11-17 22:15:13 +00:00
|
|
|
.insert(InheritOutlineDepth);
|
2022-11-17 00:25:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add plane, light source, and camera
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(PbrBundle {
|
2023-03-10 18:43:13 +00:00
|
|
|
mesh: meshes.add(Mesh::from(Plane {
|
|
|
|
size: 5.0,
|
|
|
|
subdivisions: 0,
|
|
|
|
})),
|
2022-11-17 00:25:54 +00:00
|
|
|
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
|
|
|
..default()
|
|
|
|
});
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(PointLightBundle {
|
2022-11-17 00:25:54 +00:00
|
|
|
point_light: PointLight {
|
|
|
|
intensity: 1500.0,
|
|
|
|
shadows_enabled: true,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
|
|
|
..default()
|
|
|
|
});
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(Camera3dBundle {
|
2022-11-17 00:25:54 +00:00
|
|
|
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rotates(mut query: Query<&mut Transform, With<Rotates>>, timer: Res<Time>) {
|
|
|
|
for mut transform in query.iter_mut() {
|
|
|
|
transform.rotate_axis(Vec3::Y, 0.75 * timer.delta_seconds());
|
|
|
|
}
|
|
|
|
}
|