From 193f95992cd8b556c0282efe81d752d6d882736c Mon Sep 17 00:00:00 2001 From: yuni Date: Fri, 29 Nov 2024 19:18:51 +0100 Subject: [PATCH] atmosphere: add clouds right/left of the player inside jupiter (WIP) --- src/visual.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/src/visual.rs b/src/visual.rs index 5f02eee..12d420a 100644 --- a/src/visual.rs +++ b/src/visual.rs @@ -56,6 +56,12 @@ pub struct IsEffect; #[derive(Component)] pub struct InnerAtmosphereBox; #[derive(Component)] +pub enum AtmosphereCloud { + Above, + Below, + Fog, +} +#[derive(Component)] pub struct FadeInSprite; #[derive(Component)] pub struct FadeOutSprite; @@ -117,6 +123,7 @@ pub fn setup( let graph = graphs.add(graph); commands.insert_resource(SuitAnimation { index, graph }); + // Add atmosphere box let box_material_handle = materials.add(StandardMaterial { base_color: Color::srgba(0.0, 0.0, 0.0, 1.0), alpha_mode: AlphaMode::Blend, @@ -137,6 +144,36 @@ pub fn setup( }, )); + // Add atmosphere cloud + let texture = asset_server.load("models/textures/cloud.png"); + let cloud_material_handle = materials.add(StandardMaterial { + base_color: Color::srgba(1.0, 1.0, 1.0, 1.0), + base_color_texture: Some(texture), + perceptual_roughness: 1.0, + alpha_mode: AlphaMode::Blend, + cull_mode: None, + unlit: true, + ..default() + }); + let mesh = Rectangle::new(100000.0, 25000.0); + let mesh_handle = meshes.add(mesh); + commands.spawn(( + AtmosphereCloud::Above, + PbrBundle { + mesh: mesh_handle.clone(), + material: cloud_material_handle.clone(), + ..default() + }, + )); + commands.spawn(( + AtmosphereCloud::Below, + PbrBundle { + mesh: mesh_handle, + material: cloud_material_handle, + ..default() + }, + )); + // Blackout disabled for now // commands.spawn(( // BlackOutOverlay, @@ -360,11 +397,22 @@ fn play_animations( fn update_atmosphere( settings: Res, - mut q_atmo: Query< + mut q_atmobox: Query< (&mut Transform, &Handle, &mut Visibility), With, >, - q_player: Query<&Transform, (With, Without)>, + mut q_atmocloud: Query< + (&mut Transform, &mut Visibility, &AtmosphereCloud), + Without, + >, + q_player: Query< + &Transform, + ( + With, + Without, + Without, + ), + >, mut materials: ResMut>, ) { let player_trans = if let Ok(trans) = q_player.get_single() { @@ -372,7 +420,8 @@ fn update_atmosphere( } else { return; }; - for (mut trans, material_handle, mut vis) in &mut q_atmo { + + for (mut trans, material_handle, mut vis) in &mut q_atmobox { if let Some(x) = settings.atmo_altitude { *vis = Visibility::Inherited; trans.translation = player_trans.translation; @@ -396,4 +445,23 @@ fn update_atmosphere( *vis = Visibility::Hidden; } } + + for (mut trans, mut vis, cloud_type) in &mut q_atmocloud { + if let Some(_x) = settings.atmo_altitude { + *vis = Visibility::Inherited; + match cloud_type { + AtmosphereCloud::Above => { + trans.translation = player_trans.translation + Vec3::new(0.0, 10000.0, 0.0); + } + AtmosphereCloud::Below => { + trans.translation = player_trans.translation + Vec3::new(0.0, -10000.0, 0.0); + } + AtmosphereCloud::Fog => { + } + } + trans.look_at(player_trans.translation, Dir3::X); + } else { + *vis = Visibility::Hidden; + } + } }