2022-01-14 06:05:51 +00:00
|
|
|
use bevy::{
|
|
|
|
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
|
|
|
|
prelude::*,
|
|
|
|
render::{options::WgpuOptions, render_resource::WgpuFeatures},
|
|
|
|
};
|
2022-01-19 06:20:58 +00:00
|
|
|
use rand::{thread_rng, Rng};
|
2022-01-14 06:05:51 +00:00
|
|
|
|
2022-01-19 06:20:58 +00:00
|
|
|
use crate::{geometry::CyberSphere, lights::AnimateCyberLightWireframe};
|
2022-01-14 06:05:51 +00:00
|
|
|
|
2022-01-19 06:20:58 +00:00
|
|
|
fn wireframe_planet(
|
2022-01-14 06:05:51 +00:00
|
|
|
mut commands: Commands,
|
|
|
|
mut wireframe_config: ResMut<WireframeConfig>,
|
|
|
|
query: Query<Entity, With<CyberSphere>>,
|
|
|
|
) {
|
|
|
|
let ent = query.single();
|
|
|
|
wireframe_config.global = false;
|
|
|
|
commands.entity(ent).insert(Wireframe);
|
|
|
|
}
|
|
|
|
|
2022-01-19 06:20:58 +00:00
|
|
|
fn wireframify_lights(
|
|
|
|
mut commands: Commands,
|
|
|
|
no_wires: Query<Entity, (With<AnimateCyberLightWireframe>, Without<Wireframe>)>,
|
|
|
|
wires: Query<Entity, (With<AnimateCyberLightWireframe>, With<Wireframe>)>,
|
|
|
|
) {
|
|
|
|
let chance = 0.005;
|
|
|
|
|
|
|
|
let rng = &mut thread_rng();
|
|
|
|
for e in no_wires.iter() {
|
|
|
|
if rng.gen::<f32>() < chance {
|
|
|
|
commands.entity(e).insert(Wireframe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for e in wires.iter() {
|
|
|
|
if rng.gen::<f32>() < chance {
|
|
|
|
commands.entity(e).remove::<Wireframe>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 06:05:51 +00:00
|
|
|
// public plugin
|
|
|
|
pub struct CyberGlamorPlugin;
|
|
|
|
impl Plugin for CyberGlamorPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.insert_resource(WgpuOptions {
|
|
|
|
features: WgpuFeatures::POLYGON_MODE_LINE,
|
|
|
|
..Default::default()
|
|
|
|
})
|
2022-01-19 06:20:58 +00:00
|
|
|
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
|
|
|
.add_system(wireframify_lights)
|
2022-01-14 06:05:51 +00:00
|
|
|
.add_plugin(WireframePlugin);
|
|
|
|
}
|
|
|
|
}
|