|
|
|
|
@ -4,6 +4,7 @@ use crate::{
|
|
|
|
|
};
|
|
|
|
|
use bevy::{
|
|
|
|
|
core_pipeline::Skybox,
|
|
|
|
|
input::mouse::{MouseMotion, MouseWheel},
|
|
|
|
|
render::render_resource::{TextureViewDescriptor, TextureViewDimension},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -34,6 +35,20 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
move_camera
|
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
|
.run_if(on_event::<MouseMotion>())
|
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
mouse_zoom
|
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
|
.run_if(on_event::<MouseWheel>())
|
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>()),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(OnEnter(GameState::Display3d), activate::<Display3d>)
|
|
|
|
|
.add_systems(OnExit(GameState::Display3d), deactivate::<Display3d>);
|
|
|
|
|
}
|
|
|
|
|
@ -80,22 +95,12 @@ fn initialize(mut commands: Commands, board: Option<Res<game::Board>>, assets: R
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
Skybox(assets.skybox.clone()),
|
|
|
|
|
// EnvironmentMapLight {
|
|
|
|
|
// diffuse_map: server.load("images/pisa_diffuse_rgb9e5_zstd.ktx2"),
|
|
|
|
|
// specular_map: server.load("images/pisa_specular_rgb9e5_zstd.ktx2"),
|
|
|
|
|
// },
|
|
|
|
|
EnvironmentMapLight {
|
|
|
|
|
diffuse_map: assets.skybox.clone(),
|
|
|
|
|
specular_map: assets.skybox.clone(),
|
|
|
|
|
},
|
|
|
|
|
UiCameraConfig { show_ui: true },
|
|
|
|
|
));
|
|
|
|
|
// light
|
|
|
|
|
commands.spawn(PointLightBundle {
|
|
|
|
|
point_light: PointLight {
|
|
|
|
|
intensity: 1500.0,
|
|
|
|
|
shadows_enabled: true,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
info!("Initializing root");
|
|
|
|
|
commands
|
|
|
|
|
@ -112,11 +117,11 @@ fn initialize(mut commands: Commands, board: Option<Res<game::Board>>, assets: R
|
|
|
|
|
Display3d,
|
|
|
|
|
PointLightBundle {
|
|
|
|
|
point_light: PointLight {
|
|
|
|
|
intensity: 1500.0,
|
|
|
|
|
intensity: 3000.0,
|
|
|
|
|
shadows_enabled: true,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
|
|
|
|
transform: Transform::from_xyz(0.0, 10.0, 5.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
));
|
|
|
|
|
@ -228,3 +233,29 @@ fn gizmo_system(mut gizmos: Gizmos) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// TODO: This has bad feel, needs to be tuned
|
|
|
|
|
fn move_camera(
|
|
|
|
|
mut events: EventReader<MouseMotion>,
|
|
|
|
|
mut camera: Query<&mut Transform, (With<Display3d>, With<Camera>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|MouseMotion { delta }| {
|
|
|
|
|
camera.iter_mut().for_each(|mut t| {
|
|
|
|
|
t.rotate_around(Vec3::ZERO, Quat::from_rotation_y(delta.x / 256.0));
|
|
|
|
|
t.rotate_around(Vec3::ZERO, Quat::from_rotation_x(delta.y / 256.0));
|
|
|
|
|
t.look_at(Vec3::ZERO, Vec3::Y);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn mouse_zoom(
|
|
|
|
|
mut events: EventReader<MouseWheel>,
|
|
|
|
|
mut camera: Query<&mut Transform, (With<Display3d>, With<Camera>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|MouseWheel { y, .. }| {
|
|
|
|
|
camera.iter_mut().for_each(|mut t| {
|
|
|
|
|
t.translation *= 1.0 - (*y / 4.0);
|
|
|
|
|
t.look_at(Vec3::ZERO, Vec3::Y);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|