use std::f32::consts::PI;
use std::time::Duration;
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::window::{CursorGrabMode, PresentMode, WindowLevel, WindowTheme};
use bevy::{animation::RepeatAnimation, pbr::CascadeShadowConfigBuilder, prelude::*};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
fn main() {
App::new()
.add_plugins((DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "I am a window!".into(),
resolution: (1024., 576.).into(),
present_mode: PresentMode::AutoVsync,
canvas: Some("#bevy-portal".to_string()),
// Tells wasm to resize the window according to the available canvas
fit_canvas_to_parent: true,
// Tells wasm not to override default event handling, like F5, Ctrl+R etc.
prevent_default_event_handling: false,
window_theme: Some(WindowTheme::Dark),
enabled_buttons: bevy::window::EnabledButtons {
maximize: false,
..Default::default()
},
visible: true,
..default()
}),
..default()
}),))
.add_plugins(WorldInspectorPlugin::new())
.add_systems(Startup, setup)
.add_systems(Update, move_coin)
.run();
}
#[derive(Component)]
struct HandState {}
fn setup(mut commands: Commands, asset_server: Res) {
// Insert a resource with the current scene information
commands.spawn((
SceneBundle {
scene: asset_server.load("test02.gltf#Scene0"),
..default()
},
HandState {},
));
// Camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-34.8, 173.9, 482.1)
.looking_at(Vec3::new(0.0, 173.9, 0.0), Vec3::Y),
..default()
},
EnvironmentMapLight {
diffuse_map: asset_server.load("pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("pisa_specular_rgb9e5_zstd.ktx2"),
},
));
// Light
commands.spawn(DirectionalLightBundle {
transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)),
directional_light: DirectionalLight {
shadows_enabled: true,
..default()
},
cascade_shadow_config: CascadeShadowConfigBuilder {
first_cascade_far_bound: 200.0,
maximum_distance: 400.0,
..default()
}
.into(),
..default()
});
}
fn move_coin(mut coins: Query<(&mut Transform, &mut HandState)>, timer: Res