Add pulsing outline to hollow example.

This commit is contained in:
Robin KAY 2023-11-08 23:17:42 +00:00
parent ddb40d0c2a
commit 4866148a21
1 changed files with 17 additions and 6 deletions

View File

@ -20,13 +20,18 @@ fn main() {
.add_systems(Startup, setup)
.add_systems(
Update,
(setup_scene_once_loaded, rotates, rotates_hue, close_on_esc),
(
setup_scene_once_loaded,
rotates_and_pulses,
rotates_hue,
close_on_esc,
),
)
.run();
}
#[derive(Component)]
struct Rotates;
struct RotatesAndPulses;
#[derive(Component)]
struct RotatesHue;
@ -55,11 +60,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
scene: asset_server.load("hollow.glb#Scene0"),
..default()
})
.insert(Rotates)
.insert(RotatesAndPulses)
.insert(OutlineBundle {
outline: OutlineVolume {
visible: true,
width: 7.5,
width: 0.0,
colour: Color::BLUE,
},
stencil: OutlineStencil {
@ -97,11 +102,17 @@ fn setup_scene_once_loaded(
}
}
fn rotates(mut query: Query<&mut Transform, With<Rotates>>, timer: Res<Time>, mut t: Local<f32>) {
fn rotates_and_pulses(
mut query: Query<(&mut Transform, &mut OutlineVolume), With<RotatesAndPulses>>,
timer: Res<Time>,
mut t: Local<f32>,
) {
*t = (*t + timer.delta_seconds()) % TAU;
let a = t.sin();
for mut transform in query.iter_mut() {
let b = 10.0 * (3.0 * *t).cos().abs();
for (mut transform, mut volume) in query.iter_mut() {
*transform = Transform::from_rotation(Quat::from_rotation_y(a));
volume.width = b;
}
}