use bevy::app::AppExit; use bevy::pbr::DirectionalLightShadowMap; use bevy::prelude::*; use bevy_scene_hook::{HookPlugin, HookedSceneBundle, SceneHook}; use bevy_webcam_facial::*; #[derive(Component)] struct CameraControl; #[derive(Component)] struct CameraEye; fn main() { App::new() .insert_resource(DirectionalLightShadowMap { size: 2048 }) .add_plugins(DefaultPlugins) .add_plugins(WebcamFacialPlugin { config_webcam_device: 0, config_webcam_width: 640, config_webcam_height: 480, config_webcam_framerate: 33, config_webcam_autostart: true, // Using LowPass filter, with value of 'alpha' at 0.01 for last 20 frames to get more smoothing config_filter_length: 20, config_filter_type: SmoothingFilterType::LowPass(0.01), }) // Using HookPlugin to get named object from loaded gltf scene .add_plugins(HookPlugin) .add_systems(Startup, load_scene) .add_systems( Update, ( set_camera_position_from_plugin, user_input_to_plugin_control_system, ), ) .run(); } /// set up 3D scene fn load_scene(mut commands: Commands, asset_server: Res) { commands.spawn(HookedSceneBundle { scene: SceneBundle { scene: asset_server.load("rooster.gltf#Scene0"), ..default() }, hook: SceneHook::new(|entity, cmds| { match entity.get::().map(|t| t.as_str()) { Some("Camera") => { cmds.insert(CameraEye); } _ => {} }; }), }); commands.spawn(PointLightBundle { point_light: PointLight { intensity: 500.0, shadows_enabled: true, ..default() }, transform: Transform::from_xyz(0.0, 4.0, 0.0), ..default() }); commands.spawn( TextBundle::from_section( "A: Start capture\nS: Stop capture\nESC: Exit app", TextStyle { font_size: 20.0, color: Color::BLUE, ..default() }, ) .with_style(Style { position_type: PositionType::Absolute, top: Val::Px(5.0), left: Val::Px(15.0), ..default() }), ); } fn set_camera_position_from_plugin( mut camera: Query<&mut Transform, With>, mut webcam_data: EventReader, _time: Res