Skip to content

Commit

Permalink
Lock the sphere position in the example when "Baked" is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Dec 11, 2024
1 parent 8bfa3b2 commit 641abe4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion examples/3d/mixed_lighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,22 @@ fn update_radio_buttons(
fn handle_lighting_mode_change(
mut widget_click_events: EventReader<WidgetClickEvent<LightingMode>>,
mut lighting_mode_change_events: EventWriter<LightingModeChanged>,
mut objects: Query<(&Name, &mut Transform)>,
mut app_status: ResMut<AppStatus>,
) {
for event in widget_click_events.read() {
app_status.lighting_mode = **event;
lighting_mode_change_events.send(LightingModeChanged);

// Reset the sphere's position if the lighting mode was set to `Baked`.
if app_status.lighting_mode == LightingMode::Baked {
for (name, mut transform) in &mut objects {
if &**name == "Sphere" {
transform.translation = INITIAL_SPHERE_POSITION;
break;
}
}
}
}
}

Expand All @@ -287,8 +298,11 @@ fn move_sphere(
pointers: Query<&PointerInteraction>,
mut meshes: Query<(&Name, &Parent), With<Mesh3d>>,
mut transforms: Query<&mut Transform>,
app_status: Res<AppStatus>,
) {
if !mouse_button_input.pressed(MouseButton::Left) {
if app_status.lighting_mode == LightingMode::Baked
|| !mouse_button_input.pressed(MouseButton::Left)
{
return;
}

Expand Down

0 comments on commit 641abe4

Please sign in to comment.