diff --git a/src/main.rs b/src/main.rs index e04f43d..a8fa081 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ impl Plugin for OutFlyPlugin { app.add_systems(Update, handle_input); app.insert_resource(settings::Settings::default()); app.add_plugins(( - DefaultPlugins.set(ImagePlugin::default_nearest()), + DefaultPlugins,//.set(ImagePlugin::default_nearest()), FrameTimeDiagnosticsPlugin, world::WorldPlugin, diff --git a/src/world.rs b/src/world.rs index 681a47a..4dd38ad 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,8 +1,8 @@ -use crate::{actor, camera, settings}; +use crate::{actor, camera}; use bevy::prelude::*; -use bevy::core_pipeline::Skybox; -use bevy::asset::LoadState; -use bevy::render::render_resource::{TextureViewDescriptor, TextureViewDimension}; +//use bevy::core_pipeline::Skybox; +//use bevy::asset::LoadState; +//use bevy::render::render_resource::{TextureViewDescriptor, TextureViewDimension}; use bevy::pbr::CascadeShadowConfigBuilder; use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings}; use std::f32::consts::PI; @@ -14,11 +14,11 @@ const SUN_SIZE: f32 = 5000.0; const ASTRONAUT_SIZE: f32 = 5.0; const SUN_BRIGHTNESS: f32 = 1e5; -const SKYBOX_BRIGHTNESS: f32 = 500.0; -const SKYBOX_BRIGHTNESS_AR: f32 = 100.0; +//const SKYBOX_BRIGHTNESS: f32 = 300.0; +//const SKYBOX_BRIGHTNESS_AR: f32 = 100.0; -const ASSET_CUBEMAP: &str = "textures/stars_cubemap.png"; -const ASSET_CUBEMAP_AR: &str = "tmp/cubemap.png"; +//const ASSET_CUBEMAP: &str = "textures/cubemap-fs8.png"; +//const ASSET_CUBEMAP_AR: &str = "textures/out.png"; const ASSET_ASTRONAUT: &str = "tmp/alien.glb#Scene0"; pub struct WorldPlugin; @@ -26,42 +26,43 @@ impl Plugin for WorldPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); //app.add_systems(Update, asset_loaded.after(load_cubemap_asset)); - app.add_systems(Update, swap_world_on_ar_toggle); + //app.add_systems(Update, swap_world_on_ar_toggle); + app.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))); } } -#[derive(Resource)] -pub struct WorldState { - is_loaded: bool, - entities_viewn_through_ar: bool, - cubemap_handle: Handle, - cubemap_ar_handle: Handle, -} -impl WorldState { - pub fn get_cubemap_handle(&self) -> Handle { - if self.entities_viewn_through_ar { - self.cubemap_ar_handle.clone() - } else { - self.cubemap_handle.clone() - } - } -} +//#[derive(Resource)] +//pub struct WorldState { +// is_loaded: bool, +// entities_viewn_through_ar: bool, +// cubemap_handle: Handle, +// cubemap_ar_handle: Handle, +//} +//impl WorldState { +// pub fn get_cubemap_handle(&self) -> Handle { +// if self.entities_viewn_through_ar { +// self.cubemap_ar_handle.clone() +// } else { +// self.cubemap_handle.clone() +// } +// } +//} pub fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, mut ambient_light: ResMut, - settings: Res, +// settings: Res, asset_server: Res, ) { - let cubemap_handle = asset_server.load(ASSET_CUBEMAP); - commands.insert_resource(WorldState { - is_loaded: false, - entities_viewn_through_ar: settings.hud_active, - cubemap_handle: asset_server.load(ASSET_CUBEMAP), - cubemap_ar_handle: asset_server.load(ASSET_CUBEMAP_AR), - }); +// let cubemap_handle = asset_server.load(ASSET_CUBEMAP); +// commands.insert_resource(WorldState { +// is_loaded: false, +// entities_viewn_through_ar: settings.hud_active, +// cubemap_handle: asset_server.load(ASSET_CUBEMAP), +// cubemap_ar_handle: asset_server.load(ASSET_CUBEMAP_AR), +// }); // Add player commands.spawn(( @@ -74,7 +75,6 @@ pub fn setup( } )); - // Add skybox commands.spawn(( Camera3dBundle { camera: Camera { @@ -85,10 +85,10 @@ pub fn setup( ..default() }, camera::CameraController::default(), - Skybox { - image: cubemap_handle, - brightness: SKYBOX_BRIGHTNESS, - }, +// Skybox { +// image: cubemap_handle, +// brightness: SKYBOX_BRIGHTNESS, +// }, BloomSettings { composite_mode: BloomCompositeMode::EnergyConserving, ..default() @@ -221,37 +221,37 @@ pub fn setup( }); } -pub fn swap_world_on_ar_toggle( - asset_server: Res, - mut images: ResMut>, - mut worldstate: ResMut, - mut skyboxes: Query<&mut Skybox>, - settings: Res, -) { - if settings.hud_active != worldstate.entities_viewn_through_ar { - worldstate.is_loaded = false; - worldstate.entities_viewn_through_ar = settings.hud_active; - } - if !worldstate.is_loaded && asset_server.load_state(&worldstate.get_cubemap_handle()) == LoadState::Loaded { - let cubemap_handle = &worldstate.get_cubemap_handle(); - let image = images.get_mut(cubemap_handle).unwrap(); - if image.texture_descriptor.array_layer_count() == 1 { - image.reinterpret_stacked_2d_as_array(image.height() / image.width()); - image.texture_view_descriptor = Some(TextureViewDescriptor { - dimension: Some(TextureViewDimension::Cube), - ..default() - }); - } - - for mut skybox in &mut skyboxes { - skybox.image = cubemap_handle.clone(); - skybox.brightness = if settings.hud_active { - SKYBOX_BRIGHTNESS - } else { - SKYBOX_BRIGHTNESS_AR - } - } - - worldstate.is_loaded = true; - } -} +//pub fn swap_world_on_ar_toggle( +// asset_server: Res, +// mut images: ResMut>, +// mut worldstate: ResMut, +// mut skyboxes: Query<&mut Skybox>, +// settings: Res, +//) { +// if settings.hud_active != worldstate.entities_viewn_through_ar { +// worldstate.is_loaded = false; +// worldstate.entities_viewn_through_ar = settings.hud_active; +// } +// if !worldstate.is_loaded && asset_server.load_state(&worldstate.get_cubemap_handle()) == LoadState::Loaded { +// let cubemap_handle = &worldstate.get_cubemap_handle(); +// let image = images.get_mut(cubemap_handle).unwrap(); +// if image.texture_descriptor.array_layer_count() == 1 { +// image.reinterpret_stacked_2d_as_array(image.height() / image.width()); +// image.texture_view_descriptor = Some(TextureViewDescriptor { +// dimension: Some(TextureViewDimension::Cube), +// ..default() +// }); +// } +// +// for mut skybox in &mut skyboxes { +// skybox.image = cubemap_handle.clone(); +// skybox.brightness = if settings.hud_active { +// SKYBOX_BRIGHTNESS_AR +// } else { +// SKYBOX_BRIGHTNESS +// } +// } +// +// worldstate.is_loaded = true; +// } +//}