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.insert_resource(settings::Settings::default());
app.add_plugins((
DefaultPlugins.set(ImagePlugin::default_nearest()),
DefaultPlugins,//.set(ImagePlugin::default_nearest()),
FrameTimeDiagnosticsPlugin,
world::WorldPlugin,

View file

@ -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<Image>,
cubemap_ar_handle: Handle<Image>,
}
impl WorldState {
pub fn get_cubemap_handle(&self) -> Handle<Image> {
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<Image>,
// cubemap_ar_handle: Handle<Image>,
//}
//impl WorldState {
// pub fn get_cubemap_handle(&self) -> Handle<Image> {
// 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<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut ambient_light: ResMut<AmbientLight>,
settings: Res<settings::Settings>,
// settings: Res<settings::Settings>,
asset_server: Res<AssetServer>,
) {
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<AssetServer>,
mut images: ResMut<Assets<Image>>,
mut worldstate: ResMut<WorldState>,
mut skyboxes: Query<&mut Skybox>,
settings: Res<settings::Settings>,
) {
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<AssetServer>,
// mut images: ResMut<Assets<Image>>,
// mut worldstate: ResMut<WorldState>,
// mut skyboxes: Query<&mut Skybox>,
// settings: Res<settings::Settings>,
//) {
// 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;
// }
//}