use bevy::input::common_conditions::input_pressed; use bevy::prelude::*; use bevy::window::PrimaryWindow; use bevy_cef::prelude::*; fn main() { App::new() .add_plugins((DefaultPlugins, CefPlugin)) .add_systems( Startup, ( spawn_camera, spawn_directional_light, spawn_github_webview, spawn_google_search_webview, spawn_ground, enable_ime, ), ) .insert_resource(AmbientLight::default()) .add_systems( Update, ( walk::<1, 0>.run_if(input_pressed(KeyCode::ArrowRight)), walk::<-1, 0>.run_if(input_pressed(KeyCode::ArrowLeft)), walk::<0, 1>.run_if(input_pressed(KeyCode::ArrowUp)), walk::<0, -1>.run_if(input_pressed(KeyCode::ArrowDown)), rotate_camera::<1>.run_if(input_pressed(KeyCode::Digit1)), rotate_camera::<-1>.run_if(input_pressed(KeyCode::Digit2)), ), ) .run(); } fn spawn_camera(mut commands: Commands) { commands.spawn(Camera3d::default()); } fn spawn_directional_light(mut commands: Commands) { commands.spawn(( DirectionalLight { shadows_enabled: true, ..default() }, Transform::from_translation(Vec3::new(1., 1., 1.)).looking_at(Vec3::ZERO, Vec3::Y), )); } fn enable_ime(mut primary_window: Query<&mut Window, With>) { primary_window.single_mut().unwrap().ime_enabled = true; } fn spawn_github_webview( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( CefWebviewUri("https://github.com/not-elm".to_string()), Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::ONE))), WebviewSize(Vec2::splat(800.0)), MeshMaterial3d(materials.add(WebviewExtendStandardMaterial::default())), Transform::from_translation(Vec3::new(1.5, 0., -4.0)), )); } fn spawn_google_search_webview( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( CefWebviewUri("https://www.youtube.com/".to_string()), WebviewSize(Vec2::splat(800.0)), Mesh3d(meshes.add(Plane3d::new(Vec3::Z, Vec2::ONE))), MeshMaterial3d(materials.add(WebviewExtendStandardMaterial::default())), Transform::from_translation(Vec3::new(-1.5, 0., -4.0)), // .with_rotation(Quat::from_rotation_y(-90f32.to_radians())), )); } fn spawn_ground( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { commands.spawn(( Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::new(10., 10.)))), MeshMaterial3d(materials.add(StandardMaterial { base_color: Color::srgba(0.8, 0.8, 0.8, 1.0), ..default() })), Transform::from_translation(Vec3::new(0., -2., 0.)), )); } fn walk( mut q: Query<&mut Transform, With>, time: Res