disable skybox for now

This commit is contained in:
yuni 2024-03-18 20:58:16 +01:00
parent 38a85be608
commit 2786129499
2 changed files with 73 additions and 73 deletions

View file

@ -20,7 +20,7 @@ impl Plugin for OutFlyPlugin {
app.add_systems(Update, handle_input); app.add_systems(Update, handle_input);
app.insert_resource(settings::Settings::default()); app.insert_resource(settings::Settings::default());
app.add_plugins(( app.add_plugins((
DefaultPlugins.set(ImagePlugin::default_nearest()), DefaultPlugins,//.set(ImagePlugin::default_nearest()),
FrameTimeDiagnosticsPlugin, FrameTimeDiagnosticsPlugin,
world::WorldPlugin, world::WorldPlugin,

View file

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