use bevy::prelude::*;
use bevy_elements::{WeatheredExtension, WeatheredMaterial};
#[derive(Component)]
pub struct GroundPlane;
#[derive(Component)]
pub struct ShowcaseProp;
type Weatherable<'w, 's> = Query<
'w,
's,
(Entity, &'static MeshMaterial3d<StandardMaterial>),
Or<(With<GroundPlane>, With<ShowcaseProp>)>,
>;
pub fn plugin(app: &mut App) {
app.add_systems(Update, adopt_weathered);
}
fn adopt_weathered(
mut commands: Commands,
standard: Res<Assets<StandardMaterial>>,
mut grounds: ResMut<Assets<WeatheredMaterial>>,
props: Weatherable,
) {
for (entity, material) in &props {
let Some(base) = standard.get(&material.0) else {
continue;
};
commands
.entity(entity)
.remove::<(GroundPlane, ShowcaseProp, MeshMaterial3d<StandardMaterial>)>()
.insert(MeshMaterial3d(grounds.add(WeatheredMaterial {
base: base.clone(),
extension: WeatheredExtension::default(),
})));
}
}