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

View File

@ -20,13 +20,18 @@ fn main() {
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems( .add_systems(
Update, Update,
(setup_scene_once_loaded, rotates, rotates_hue, close_on_esc), (
setup_scene_once_loaded,
rotates_and_pulses,
rotates_hue,
close_on_esc,
),
) )
.run(); .run();
} }
#[derive(Component)] #[derive(Component)]
struct Rotates; struct RotatesAndPulses;
#[derive(Component)] #[derive(Component)]
struct RotatesHue; struct RotatesHue;
@ -55,11 +60,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
scene: asset_server.load("hollow.glb#Scene0"), scene: asset_server.load("hollow.glb#Scene0"),
..default() ..default()
}) })
.insert(Rotates) .insert(RotatesAndPulses)
.insert(OutlineBundle { .insert(OutlineBundle {
outline: OutlineVolume { outline: OutlineVolume {
visible: true, visible: true,
width: 7.5, width: 0.0,
colour: Color::BLUE, colour: Color::BLUE,
}, },
stencil: OutlineStencil { 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; *t = (*t + timer.delta_seconds()) % TAU;
let a = t.sin(); 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)); *transform = Transform::from_rotation(Quat::from_rotation_y(a));
volume.width = b;
} }
} }