use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, init)
        .add_systems(Update, add_shadows)
        .run();
}

fn init(server: Res<AssetServer>, mut commands: Commands) {
    commands.spawn(SceneBundle {
        scene: server.load("models/shadow-example.gltf#Scene0"),
        ..default()
    });
}

fn add_shadows(
    mut lights: Query<(Entity, &mut PointLight), Added<PointLight>>,
    mut commands: Commands,
) {
    lights.iter_mut().for_each(|(e, mut l)| {
        l.shadows_enabled = true;

        let config: bevy::pbr::CascadeShadowConfig =
            bevy::pbr::CascadeShadowConfigBuilder { ..default() }.into();
        commands.entity(e).insert(config);
    });
}
