cleaner implementation of atmosphere box

This commit is contained in:
yuni 2024-11-29 18:10:34 +01:00
parent 1ce78a5816
commit 1241dd3231

View file

@ -11,7 +11,7 @@
// This module manages visual effects.
use crate::prelude::*;
use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
use bevy::pbr::NotShadowReceiver;
use bevy::prelude::*;
use bevy_xpbd_3d::prelude::*;
use std::time::Duration;
@ -120,13 +120,12 @@ pub fn setup(
let box_material_handle = materials.add(StandardMaterial {
base_color: Color::srgba(0.0, 0.0, 0.0, 1.0),
alpha_mode: AlphaMode::Blend,
cull_mode: None,
unlit: true,
..default()
});
let mut mesh = Mesh::from(Cuboid::new(100.0, 100.0, 100.0).mesh());
let mut mesh_inside = Mesh::from(Cuboid::new(100.0, 100.0, 100.0).mesh());
mesh_invert_triangles(&mut mesh_inside);
mesh.merge(&mesh_inside);
let r = 1000.0;
let mesh = Mesh::from(Cuboid::new(r, r, r).mesh());
let box_handle = meshes.add(mesh);
commands.spawn((
InnerAtmosphereBox,
@ -386,6 +385,11 @@ fn update_atmosphere(
};
if let Some(material) = materials.get_mut(material_handle) {
material.base_color = Color::srgba(0.0, 0.0, 0.0, opacity);
if opacity >= 1.0 {
material.alpha_mode = AlphaMode::Opaque;
} else {
material.alpha_mode = AlphaMode::Blend;
}
}
} else {
*vis = Visibility::Hidden;